极光短信通知工具类
需要你注册极光账号的MASTER_SECRET 和 APP_KEY 两个参数(必须)。
进入极光开发者平台,即可查看:
/**
* 极光推送
*/
@SuppressWarnings({"deprecation", "restriction"})
public class JiguangPushUtil {
protected static final Logger log = LoggerFactory.getLogger(JiguangPushUtil.class);
private static String MASTER_SECRET = "xxxxxxxxx";
private static String APP_KEY = "xxxxxxxxx";
private static final String ALERT = "推送信息";
/***
* 发送短信
* mobileNumber 手机号
* temp_para 短信模板变量
* tempId 短信模板id
*/
public static void sendSMS(String mobileNumber, Map<String, String> temp_para, Integer tempId) {
JSMSClient jsmsClient = new JSMSClient(MASTER_SECRET, APP_KEY);
SMSPayload smsPayload = SMSPayload.newBuilder()
.setMobileNumber(mobileNumber)
.setTempId(tempId)
.setTempPara(temp_para)
// .setCode(code)
.build();//new SMSPayload(mobileNumber,tempId,ttl,code,voiceLang,temp_para);
try {
SendSMSResult res = jsmsClient.sendTemplateSMS(smsPayload);
log.info("发送成功:" + res.toString());
} catch (APIConnectionException | APIRequestException e) {
e.printStackTrace();
log.error("jiguang send sms error", e);
}
}
// test
public static void main(String[] args) {
Map<String, String> temp_para = new HashMap<>();
temp_para.put("time", "1");
temp_para.put("time", "2");
temp_para.put("time", "3");
sendSMS("17616529886", temp_para, 162844);
}
}
最近这段时间在项目中用到了极光推送,包括了安卓、IOS应用推送、短信通知,特地在此记录一下,方便后续使用。