极光开发服务 向终端设备推送消息
1 private static PushPayload buildPushObject_all_alias_alert(Integer mid, String message, Integer flag) { 2 JSONObject result = new JSONObject(); 3 result.put("mid", mid); 4 result.put("message", message); 5 result.put("flag", flag); 6 return PushPayload.newBuilder() 7 .setPlatform(Platform.all()) 8 .setAudience(Audience.all()) 9 .setNotification(Notification.alert("")) 10 .setMessage(Message.content(result.toString())) 11 .build(); 12 }
//给机器发送信息 public static void sendJPush(Integer mid, String message, Integer flag) { JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, ClientConfig.getInstance()); // For push, all you need do is to build PushPayload object. PushPayload payload = buildPushObject_all_alias_alert(mid, message, flag); try { PushResult result = jpushClient.sendPush(payload); log.info("Got result - " + result); } catch (APIConnectionException e) { // Connection error, should retry later log.error("Connection error, should retry later", e); } catch (APIRequestException e) { // Should review the error, and fix the request log.error("Should review the error, and fix the request", e); log.info("HTTP Status: " + e.getStatus()); log.info("Error Code: " + e.getErrorCode()); log.info("Error Message: " + e.getErrorMessage()); } }
/** *测试消息机制 */ @RequestMapping(value = "/testJpush.json", method = RequestMethod.GET) @ResponseBody public void testJpush(Integer mid) { JSONObject json = new JSONObject(); json.put("Untiekes", "0A-01,0B-01"); json.put("Ono", "2019080114156688"); //发送信息给android try { Utils.sendJPush(mid, "\"" + json + "\"", 4); } catch (Exception e) { log.info("推送消息异常=========================" + e.getMessage()); } }
详情见极光开发官网-------https://docs.jiguang.cn//jpush/server/sdk/java_sdk/
境随心转而悦,心随境转而烦
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
· 不到万不得已,千万不要去外包
· C# WebAPI 插件热插拔(持续更新中)
· 会议真的有必要吗?我们产品开发9年了,但从来没开过会
· 如何打造一个高并发系统?
· 《SpringBoot》EasyExcel实现百万数据的导入导出