您的位置:首页 > 其它

推送,极光推送

2016-11-07 11:12 92 查看
推送的原理其实也很简单,拿极光推送来说,首先,APP登录的时候,调用极光的API,设置当前登录的信息到极光;服务器发送推送时,只要将需要推送的信息和相应的唯一标识传给极光,就可以了。

附上服务器端简单代码:

public static void testSendPush(String appKey ,String masterSecret,
String jsonString,String alias) {
try {
MSG_CONTENT = jsonString;

jpushClient = new JPushClient(masterSecret, appKey, 3);
PushPayload payload = buildPushObject_android_and_ios(jsonString, alias);
PushResult result = jpushClient.sendPush(payload);

LOG.info("Got result - " + result);

} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);

} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Code: " + e.getErrorCode());
LOG.info("Error Message: " + e.getErrorMessage());
LOG.info("Msg ID: " + e.getMsgId());
}
}

public static PushPayload buildPushObject_android_and_ios(String jsonString,String alias) {
return PushPayload.newBuilder()
.setPlatform(Platform.android_ios())
.setAudience(Audience.newBuilder()
.addAudienceTarget(AudienceTarget.alias(alias))
.build())
.setMessage(Message.newBuilder()
.setMsgContent(jsonString)
.addExtra("from", "JPush")
.build())
.build();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  推送