zoukankan      html  css  js  c++  java
  • 极光开发服务 向终端设备推送消息

     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/

    境随心转而悦,心随境转而烦
  • 相关阅读:
    2019春第九周作业
    2019春第八周作业
    2019春第七周作业
    2019春第六周作业
    2019春第五周作业
    2019年春季学期第四周作业
    2019年春季学期第三周作业
    2019年春季学期第二周作业
    学习进度条
    第六周作业
  • 原文地址:https://www.cnblogs.com/tomingto/p/11283732.html
Copyright © 2011-2022 走看看