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";