极光的研究

1. 调用极光推送

List recList3 = new ArrayList();
recList3.add(sc3);
JPush.SendPushForAndroidAndIos(title, msgContent, null, recList3, JPush.Platforms.iTask);

 这里的 sc3  ----  就是 登录人登录在 app 的 账号 SA8@lsh.com 

2.         

                               1. 弹出的头2. 具体的信息 4.接收人   5. 平台(安卓 或者ios)        

public static void SendPushForAndroidAndIos(String alert, String msg_content, JsonObject json, List reclist, Platforms platform) {
    ClientConfig clientConfig = ClientConfig.getInstance();
    // 定义推送到哪个APP
    JPushClient jpushClient = new JPushClient(platform.getValue(), platform.getKey(), null, clientConfig);
    // 推送对象
    PushPayload payload = buildPushMsg(alert, msg_content, json, reclist);
    try {
        // 推送动作
        PushResult result = jpushClient.sendPush(payload);
        logger.info("Got result - " + result);
    } catch (APIConnectionException e) {
        logger.error("Connection error. Should retry later. ", e);
    } catch (APIRequestException e) {
        logger.error("Error response from JPush server. Should review and fix it. ", e);
        logger.info("HTTP Status: " + e.getStatus());
        logger.info("Error Code: " + e.getErrorCode());
        logger.info("Error Message: " + e.getErrorMessage());
        logger.info("Msg ID: " + e.getMsgId());
    }
}

3.推送对象

 /**
     * @param alert       消息推送的消息头?
     * @param msg_content 消息内容
     * @param json        对方解析extra时候约定的参数和值
     * @param reclist     推送对象
     * @return
     */
    public static PushPayload buildPushMsg(String alert, String msg_content, JsonObject json, List reclist) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.alias(reclist)) //接受人
                .setNotification(Notification.newBuilder()
                        .addPlatformNotification(IosNotification.newBuilder()
                                .setAlert(alert)
                                .setBadge(5)
                                .setSound("happy")
                                .addExtra("data", json)
                                .build())
                        .addPlatformNotification(AndroidNotification.newBuilder()
                                .setAlert(alert)
                                .build())
                        .build())
                .setMessage(Message.content(msg_content))
                .setOptions(Options.newBuilder()
                        // 项目后期可能会更改为true
//                        .setApnsProduction(true)
                        .setApnsProduction(false)
                        .build())
                .build();
    }

4. 平台 参数   包括在 极光上注册获得 的参数,一个 枚举的 内部类

public enum Platforms {
    iTask(iTaskAppKey, iTaskMasterSecret), iMgt(iMgtAppKey, iMgtMasterSecret);
    private String key;
    private String value;

    private Platforms(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}

5.这是 极光获 的 参数 

// iTask相关属性
private static final String iTaskAppKey = "eb61318960e222d928a3f8dc";
private static final String iTaskMasterSecret = "844e42ec8c7bf0fc86978508";
// iManagement相关属性
private static final String iMgtAppKey = "0bd0b1607288b9644c508789";
private static final String iMgtMasterSecret = "673b586c3fe66227512c86f1";


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值