推送,极光推送
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 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(); }
相关文章推荐
- ionic 之cordova 极光推送jpush和百度定位插件结合使用之定位失效问题解决办法
- 极光推送(服务器端)案例
- Apicloud极光推送SDK—JS代码
- react-native 中配置极光推送 Android关键详细的说明与截图代码 找不到类Bundle/JPushInterface
- 关于极光推送收不到通知的问题
- [置顶] Android开发之第三方推送JPush极光推送知识点详解 学会集成第三方SDK推送
- java sdk 极光推送 安卓,ios
- 极光推送集成步骤详解
- 极光自定义推送
- JPush极光推送Java服务器端API
- Android基于极光推送实现单点登录
- java+maven集成极光推送服务
- 极光推送准确配置
- .net平台借助第三方推送服务在推送Android消息(极光推送) 转
- Android第三方推送——极光推送,百度云推送,个推
- JPush极光推送自己集成服务端jar包
- Android极光推送手工整合到项目中的方法
- 用JPUSH极光推送实现服务端向安装了APP应用的手机推送消息(C#服务端接口)
- ionic集成jPush极光推送
- JPush极光推送快速创建Android Demo