极光推送短信-工具类

极光短信通知工具类
需要你注册极光账号的MASTER_SECRETAPP_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应用推送、短信通知,特地在此记录一下,方便后续使用。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章