極光短信通知工具類
需要你註冊極光賬號的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應用推送、短信通知,特地在此記錄一下,方便後續使用。