From 540b9011252b341f477b1192905bb2dea59d6ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E4=B8=B9=E4=BE=A0?= Date: Fri, 6 Dec 2019 00:01:47 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9C=80=E5=A4=96?= =?UTF-8?q?=E5=B1=82=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/jpush/api/examples/PushExample.java | 48 +++++++++++++++++++ pom.xml | 2 +- .../cn/jpush/api/push/model/PushPayload.java | 24 +++++++++- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/example/main/java/cn/jpush/api/examples/PushExample.java b/example/main/java/cn/jpush/api/examples/PushExample.java index f452ccd9..a18dbb09 100644 --- a/example/main/java/cn/jpush/api/examples/PushExample.java +++ b/example/main/java/cn/jpush/api/examples/PushExample.java @@ -46,6 +46,8 @@ public class PushExample { public static void main(String[] args) { + // 回调参数可参考下面方法 + testSendPushWithCustom(); testSendPushWithCustomField(); // testBatchSend(); testSendPushWithCustomConfig(); @@ -630,5 +632,51 @@ public static void testSendPushWithCustomField() { } } + /** + * 回调参数示例 + */ + public static void testSendPushWithCustom() { + + ClientConfig config = ClientConfig.getInstance(); + // Setup the custom hostname + config.setPushHostName("https://api.jpush.cn"); + + JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, config); + + Notification notification = Notification.newBuilder() + .addPlatformNotification(AndroidNotification.newBuilder() + .setAlert(ALERT) + .setTitle("Alert test") + .build()) + .build(); + + JsonObject callback = new JsonObject(); + callback.addProperty("url", "https://www.jiguagn.cn/callback"); + JsonObject params = new JsonObject(); + params.addProperty("name", "joe"); + params.addProperty("age", 26); + callback.add("params", params); + callback.addProperty("type", 3); + + PushPayload.Builder payloadBuilder = new PushPayload.Builder() + .setPlatform(Platform.all()) + .setAudience(Audience.all()) + .setNotification(notification) + .addCustom("callback", callback); + + try { + PushResult result = jpushClient.sendPush(payloadBuilder.build()); + 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()); + } + } + } diff --git a/pom.xml b/pom.xml index ff26a476..463c9c25 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ cn.jpush.api jpush-client - 3.4.3-SNAPSHOT + 3.4.3 jar https://github.com/jpush/jpush-api-java-client JPush API Java Client diff --git a/src/main/java/cn/jpush/api/push/model/PushPayload.java b/src/main/java/cn/jpush/api/push/model/PushPayload.java index 4b48818b..575a38b0 100644 --- a/src/main/java/cn/jpush/api/push/model/PushPayload.java +++ b/src/main/java/cn/jpush/api/push/model/PushPayload.java @@ -14,6 +14,9 @@ import cn.jpush.api.push.model.notification.Notification; import cn.jpush.api.push.model.notification.PlatformNotification; +import java.util.LinkedHashMap; +import java.util.Map; + /** * The object you should build for sending a push. * @@ -54,9 +57,10 @@ public class PushPayload implements PushModel { private SMS sms; private String cid; private String target; + protected Map custom; private PushPayload(Platform platform, Audience audience, - Notification notification, Message message, Options options, SMS sms, String cid, String target) { + Notification notification, Message message, Options options, SMS sms, String cid, String target, Map custom) { this.platform = platform; this.audience = audience; this.notification = notification; @@ -65,6 +69,7 @@ private PushPayload(Platform platform, Audience audience, this.sms = sms; this.cid = cid; this.target = target; + this.custom = custom; } public PushPayload setCid(String cid) { @@ -192,6 +197,11 @@ public JsonElement toJSON() { if (null != target) { json.addProperty(TARGET, target); } + if (null != custom) { + for (Map.Entry entry : custom.entrySet()) { + json.add(entry.getKey(), entry.getValue()); + } + } return json; } @@ -252,6 +262,11 @@ public static class Builder { private SMS sms = null; private String cid; private String target; + private Map custom; + + public Builder() { + this.custom = new LinkedHashMap<>(); + } public Builder setTarget(String target) { this.target = target; @@ -293,6 +308,11 @@ public Builder setCid(String cid) { return this; } + public Builder addCustom(String field, JsonObject jsonObject) { + this.custom.put(field, jsonObject); + return this; + } + public PushPayload build() { if (StringUtils.isTrimedEmpty(target)) { @@ -312,7 +332,7 @@ public PushPayload build() { options = Options.sendno(); } - return new PushPayload(platform, audience, notification, message, options, sms, cid, target); + return new PushPayload(platform, audience, notification, message, options, sms, cid, target, custom); } } } From 1ce1104ba795d75d4e609d7a9df537073eb8a5df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E4=B8=B9=E4=BE=A0?= Date: Fri, 6 Dec 2019 00:02:41 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9C=80=E5=A4=96?= =?UTF-8?q?=E5=B1=82=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 463c9c25..be715eb7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ cn.jpush.api jpush-client - 3.4.3 + 3.4.3-SNAPSHOP jar https://github.com/jpush/jpush-api-java-client JPush API Java Client From 50178c9549bdbb4f498eb1198dd68567a97231ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E4=B8=B9=E4=BE=A0?= Date: Fri, 6 Dec 2019 00:03:25 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9C=80=E5=A4=96?= =?UTF-8?q?=E5=B1=82=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index be715eb7..463c9c25 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ cn.jpush.api jpush-client - 3.4.3-SNAPSHOP + 3.4.3 jar https://github.com/jpush/jpush-api-java-client JPush API Java Client From dc6e397b2b7d5f32578b8b22a8f9f7a7dc53bea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E4=B8=B9=E4=BE=A0?= Date: Fri, 6 Dec 2019 00:06:44 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9C=80=E5=A4=96?= =?UTF-8?q?=E5=B1=82=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 463c9c25..ff26a476 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ cn.jpush.api jpush-client - 3.4.3 + 3.4.3-SNAPSHOT jar https://github.com/jpush/jpush-api-java-client JPush API Java Client From 7af75f057792ae5db61ba549fe3c8b054e2fd789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E4=B8=B9=E4=BE=A0?= Date: Fri, 6 Dec 2019 00:20:45 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/cn/jpush/api/push/model/BatchPushResult.java | 5 ----- src/main/java/cn/jpush/api/report/MessageDetailResult.java | 5 ----- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index ff26a476..3535cfcc 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ cn.jpush.api jpush-client - 3.4.3-SNAPSHOT + 3.4.3-SHAPSHOT jar https://github.com/jpush/jpush-api-java-client JPush API Java Client diff --git a/src/main/java/cn/jpush/api/push/model/BatchPushResult.java b/src/main/java/cn/jpush/api/push/model/BatchPushResult.java index da762cad..8a4777cd 100644 --- a/src/main/java/cn/jpush/api/push/model/BatchPushResult.java +++ b/src/main/java/cn/jpush/api/push/model/BatchPushResult.java @@ -12,11 +12,6 @@ import java.util.List; import java.util.Map; -/** - * @author xudanxia - * @Desc - * @date 2019-08-22. - */ public class BatchPushResult extends BaseResult { private static final Type RESULT_TYPE = new TypeToken>() {}.getType(); diff --git a/src/main/java/cn/jpush/api/report/MessageDetailResult.java b/src/main/java/cn/jpush/api/report/MessageDetailResult.java index f8065c18..df06f65e 100644 --- a/src/main/java/cn/jpush/api/report/MessageDetailResult.java +++ b/src/main/java/cn/jpush/api/report/MessageDetailResult.java @@ -11,11 +11,6 @@ import java.util.ArrayList; import java.util.List; -/** - * @author xdx - * @Desc - * @date 2019-07-29. - */ public class MessageDetailResult extends BaseResult { private static final Type RECEIVED_TYPE = new TypeToken>() {}.getType(); From 1bbb34dfeb45c08d68e75f3627f9d315148f61d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E4=B8=B9=E4=BE=A0?= Date: Fri, 6 Dec 2019 00:22:10 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3535cfcc..463c9c25 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ cn.jpush.api jpush-client - 3.4.3-SHAPSHOT + 3.4.3 jar https://github.com/jpush/jpush-api-java-client JPush API Java Client