Java 极光推送分组推送
来源:互联网 发布:郑州景安网络怎么样 编辑:程序博客网 时间:2024/06/05 16:42
前提:
项目采用alias别名推送,极光推送按照别名推送,一次只能推1000条,因此,在数量>1000的情况下采用分组推送
1.分组
/** * @throws APIRequestException * @throws APIConnectionException * @throws Exception */ private void pushMsgToUser(String type) throws APIConnectionException, APIRequestException, Exception { // 检索符合条件的别名 List<String> Devices = subjectService.selDevices(); int size = Devices.size(); List<List<String>> pgrp = new ArrayList<List<String>>(); //超过999条分组推送,小与999条一次推送 if (size > 998) { int n = 5;//假设分成5组 int number=size/n;//每组的个数 int remainder=size%n;//余数 int offset=0;//偏移量 for (int i=0 ; i < n ; i++ ){ List<String> pp = null; if (remainder > 0){ pp=Devices.subList(i*number+offset,(i+1)*number+offset+1); remainder--; offset++; }else { pp=Devices.subList(i*number+offset, (i+1)*number+offset); } pgrp.add(pp); } for (List<String> li : pgrp) { boolean result = KeCommon.pushMsgToTea(li, "有新信息,请注意查看。", "有新信息"); if (!result) { printErrorLog("批给推送消息失败", logger); } } }else { boolean result = KeCommon.pushMsgToTea(Devices, "有新信息,请注意查看。", "有新信息"); if (!result) { printErrorLog("分批给老师推送消息失败", logger); } } }
2.调用推送方法
public class KeCommon { /** * 推送消息给用户 * @param alias 别名 * @param alert 标题 * @param msgContent 内容 * @param setApnsProduction:true发布环境、false测试环境 * @return * @throws APIConnectionException * @throws APIRequestException */ public static boolean pushMsgToTea(List<String> alias, String alert, String msgContent, String sound) throws APIConnectionException, APIRequestException { // 极光推送自定义参数变量 Map<String, String> extras = new HashMap<String, String>(); JPushClient jpushClient = new JPushClient(MASTERSECRETTEA, APPKEYTEA); PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.android_ios()) .setAudience(Audience.alias(alias)) .setNotification(Notification.newBuilder() .addPlatformNotification(IosNotification.newBuilder() .setAlert(alert) .incrBadge(1) .setSound("happy.caf") .addExtra("from", "JPush") .build()) .addPlatformNotification(AndroidNotification.newBuilder() .setAlert(alert) .setTitle(msgContent) .build()) .build()) .setMessage(Message.content(msgContent)) .setOptions(Options.newBuilder() .setApnsProduction(APNS_PRODUCTION) .build()) .build(); logger.debug("ios===:" + Platform.ios()); logger.debug("alias===:" + alias); logger.debug("alert===:" + alert); logger.debug("extras===:" + extras); logger.debug("Notification===:" + Notification.ios(alert, extras)); logger.debug("Message===:" + msgContent); PushResult pushResult = jpushClient.sendPush(payload); return pushResult.isResultOK(); } }
阅读全文
0 0
- Java 极光推送分组推送
- java 极光推送
- JAVA极光推送
- 极光推送java服务端
- 极光推送java服务端
- java极光推送实例
- 极光推送-JAVA服务器端推送代码
- Java调用极光推送推送消息
- android 利用极光推送sdk实现分组推送
- 服务端极光推送2-分组推送及服务端集成
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 4.24 leetcode -24 linked-list-cycle
- 突然发现Bootstrsp的响应式工具挺好用的
- Qmake recursion
- CSS的预编译——less语言基本语法教程(入门)
- 控制反转(IoC)技术在C++中的使用
- Java 极光推送分组推送
- IAR Error[Pe020]: identifier 'FILE' is undefined 解决方法
- ubuntu14.04.1安装chrome 浏览器
- Windows Server2008 R2 设置允许多个人远程连接桌面
- Web性能压力测试工具之WebBench
- 【Spark系列5】cache和persist的区别
- python中的多线程爬虫
- <数据结构与算法>最优二叉树——霍夫曼树
- MySql Oracle 日期比较对比