From 2f6c8c32b8da73e5e4694c817390c9eceea7d4a0 Mon Sep 17 00:00:00 2001 From: bigbencat Date: Wed, 4 Mar 2020 14:09:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=8E=E4=B8=BApush=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=88=B0=E9=80=9A=E7=9F=A5=E6=A0=8F=E9=87=8C?= =?UTF-8?q?=E9=9D=A2=EF=BC=8C=E8=80=8C=E4=B8=8D=E5=BA=94=E8=AF=A5=E9=80=8F?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../push/android/hms/HMSPush.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/cn/wildfirechat/push/android/hms/HMSPush.java b/src/main/java/cn/wildfirechat/push/android/hms/HMSPush.java index 1e7393e..088f8eb 100644 --- a/src/main/java/cn/wildfirechat/push/android/hms/HMSPush.java +++ b/src/main/java/cn/wildfirechat/push/android/hms/HMSPush.java @@ -58,12 +58,26 @@ public void push(PushMessage pushMessage) { JSONArray deviceTokens = new JSONArray();//目标设备Token deviceTokens.add(pushMessage.getDeviceToken()); + JSONObject param = new JSONObject(); + param.put("appPkgName", pushMessage.packageName);//定义需要打开的appPkgName + JSONObject action = new JSONObject(); + action.put("type", 3);//类型3为打开APP,其他行为请参考接口文档设置 + action.put("param", param);//消息点击动作参数 + JSONObject msg = new JSONObject(); - msg.put("type", 1);//3: 通知栏消息,异步透传消息请根据接口文档设置 + msg.put("type", 3);//3: 通知栏消息,异步透传消息请根据接口文档设置 + msg.put("action", action);//消息点击动作 add by liguangyu String token = pushMessage.getDeviceToken(); pushMessage.deviceToken = null; - msg.put("body", new Gson().toJson(pushMessage));//通知栏消息body内容 + + JSONObject body = new JSONObject();//仅通知栏消息需要设置标题和内容,透传消息key和value为用户自定义 + body.put("title", pushMessage.senderName);//消息标题 + body.put("content", pushMessage.pushContent);//消息内容体 + //body.put("info", new Gson().toJson(pushMessage));//消息内容体 + msg.put("body", body);//通知栏消息body内容示例代码 + LOG.info("liguangyu test body: {} pushMessage{}",body,new Gson().toJson(pushMessage) ); + //msg.put("body", new Gson().toJson(pushMessage));//通知栏消息body内容 JSONObject hps = new JSONObject();//华为PUSH消息总结构体 hps.put("msg", msg); @@ -135,4 +149,5 @@ public String httpPost(String httpUrl, String data, int connectTimeout, int read } } } + }