From c2d0245aa6047e1deeb025f31eca32869e838c12 Mon Sep 17 00:00:00 2001 From: wicked-tc130 Date: Wed, 28 Aug 2024 16:06:04 +0800 Subject: [PATCH] update version to 5.1.6. --- .gitignore | 2 +- README.md | 9 +++- example-for-spring/pom.xml | 4 +- .../jiguang/app/config/JiguangApiConfig.java | 1 + .../src/main/resources/application.yml | 4 +- .../java/cn/jiguang/app/api/PushApiTest.java | 54 +++++++++++++++++++ jiguang-sdk/pom.xml | 4 +- .../main/java/cn/jiguang/sdk/api/PushApi.java | 10 ++++ .../sdk/bean/push/batch/BatchPushParam.java | 50 +++++++++++++++++ .../sdk/bean/push/batch/BatchPushResult.java | 21 ++++++++ .../bean/push/batch/BatchPushSendParam.java | 14 +++++ .../bean/push/batch/BatchPushSendResult.java | 21 ++++++++ .../cn/jiguang/sdk/client/PushClient.java | 10 ++++ pom.xml | 2 +- 14 files changed, 196 insertions(+), 10 deletions(-) create mode 100644 jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushParam.java create mode 100644 jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushResult.java create mode 100644 jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushSendParam.java create mode 100644 jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushSendResult.java diff --git a/.gitignore b/.gitignore index bb49d4f..a27601b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,4 @@ replay_pid* *.iml .idea -target/ +**/target/ diff --git a/README.md b/README.md index 982dfc1..05205d0 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ ## 1. 集成 引入sdk包 ```xml - + io.github.jpush jiguang-sdk - 5.1.5 + 5.1.6 ``` @@ -87,3 +87,8 @@ * [ReportApi](https://github.com/jpush/jiguang-sdk-java/blob/main/example-for-spring/src/test/java/cn/jiguang/app/api/ReportApiTest.java) * [AdminApi](https://github.com/jpush/jiguang-sdk-java/blob/main/example-for-spring/src/test/java/cn/jiguang/app/api/AdminApiTest.java) * [GroupPushApi](https://github.com/jpush/jiguang-sdk-java/blob/main/example-for-spring/src/test/java/cn/jiguang/app/api/GroupPushApiTest.java) +## 3. 推送失败 +推送失败会抛出异常,可对下面的类异常捕获后进行业务处理 +```java +cn.jiguang.sdk.exception.ApiErrorException +``` \ No newline at end of file diff --git a/example-for-spring/pom.xml b/example-for-spring/pom.xml index 01bf146..fb12879 100644 --- a/example-for-spring/pom.xml +++ b/example-for-spring/pom.xml @@ -13,7 +13,7 @@ io.github.jpush example-for-spring - 5.1.5 + 5.1.6 8 @@ -26,7 +26,7 @@ io.github.jpush jiguang-sdk - 5.1.5 + 5.1.6 diff --git a/example-for-spring/src/main/java/cn/jiguang/app/config/JiguangApiConfig.java b/example-for-spring/src/main/java/cn/jiguang/app/config/JiguangApiConfig.java index b396ef7..e22e222 100644 --- a/example-for-spring/src/main/java/cn/jiguang/app/config/JiguangApiConfig.java +++ b/example-for-spring/src/main/java/cn/jiguang/app/config/JiguangApiConfig.java @@ -52,6 +52,7 @@ public PushApi pushApi(@Qualifier("okHttpClient") OkHttpClient okHttpClient) { .setClient(okHttpClient) // 如果不配置client,则使用默认的okHttpClient .setAppKey(appKey) .setMasterSecret(masterSecret) + .setLoggerLevel(Logger.Level.FULL) .build(); } diff --git a/example-for-spring/src/main/resources/application.yml b/example-for-spring/src/main/resources/application.yml index cf50d7c..345ea03 100644 --- a/example-for-spring/src/main/resources/application.yml +++ b/example-for-spring/src/main/resources/application.yml @@ -12,8 +12,8 @@ logging: jiguang: api: # 此为演示数据,请替换成真实数据 - app-key: a266cd5c8544ba09b23733e1 - master-secret: bcf3b3327000abce4764f862 + app-key: b266cd5c8544ba09b23733e3 + master-secret: 15747d3881d308fe5107b7da dev-key: c2dc75e97486529205528b23 dev-secret: d219e2f001df2fe4f08b6754 group-key: 2ed1465b94aab3f03f6778e0 diff --git a/example-for-spring/src/test/java/cn/jiguang/app/api/PushApiTest.java b/example-for-spring/src/test/java/cn/jiguang/app/api/PushApiTest.java index 98b972a..a53cca9 100644 --- a/example-for-spring/src/test/java/cn/jiguang/app/api/PushApiTest.java +++ b/example-for-spring/src/test/java/cn/jiguang/app/api/PushApiTest.java @@ -9,6 +9,9 @@ import cn.jiguang.sdk.bean.push.PushSendParam; import cn.jiguang.sdk.bean.push.PushSendResult; import cn.jiguang.sdk.bean.push.audience.Audience; +import cn.jiguang.sdk.bean.push.batch.BatchPushParam; +import cn.jiguang.sdk.bean.push.batch.BatchPushSendParam; +import cn.jiguang.sdk.bean.push.batch.BatchPushSendResult; import cn.jiguang.sdk.bean.push.message.notification.NotificationMessage; import cn.jiguang.sdk.bean.push.options.Options; import cn.jiguang.sdk.bean.push.other.CidGetResult; @@ -254,4 +257,55 @@ public void updateImageFile() { log.info("result:{}", result); } + @Test + public void batchSendByRegistrationId() { + NotificationMessage.Android android = new NotificationMessage.Android(); + android.setAlert("this is android alert"); + android.setTitle("this is android title"); + NotificationMessage notificationMessage = new NotificationMessage(); + notificationMessage.setAndroid(android); + + BatchPushParam pushParam = new BatchPushParam(); + pushParam.setTarget("170976fa8b808c38fe7"); + pushParam.setNotification(notificationMessage); + pushParam.setPlatform(Arrays.asList(Platform.android, Platform.ios)); + + Map pushSendParam = new HashMap<>(); + pushSendParam.put("b266cd5c8544ba09b23733e3-c7f656ad-12a3-4807-a614-9924dc11d79e", pushParam); + pushSendParam.put("b266cd5c8544ba09b23733e3-0cbee7fc-e7ba-4b87-952e-14c5be18e671", pushParam); + pushSendParam.put("b266cd5c8544ba09b23733e3-870bec54-f0e7-4ae0-a1f9-f13b4ddd1629", pushParam); + + BatchPushSendParam param = new BatchPushSendParam(); + param.setSendParam(pushSendParam); + + BatchPushSendResult result = pushApi.batchSendByRegistrationId(param); + log.info("result:{}", result); + } + + @Test + public void batchSendByAlias() { + NotificationMessage.Android android = new NotificationMessage.Android(); + android.setAlert("this is android alert"); + android.setTitle("this is android title"); + NotificationMessage notificationMessage = new NotificationMessage(); + notificationMessage.setAndroid(android); + + BatchPushParam pushParam = new BatchPushParam(); + pushParam.setTarget("alias1"); + pushParam.setNotification(notificationMessage); + pushParam.setPlatform(Arrays.asList(Platform.android, Platform.ios)); + + Map pushSendParam = new HashMap<>(); + pushSendParam.put("b266cd5c8544ba09b23733e3-6386dd3c-87dd-42c8-b721-a184ea323371", pushParam); + pushSendParam.put("b266cd5c8544ba09b23733e3-999c861b-426c-475d-97c8-0cb884e67dfd", pushParam); + pushSendParam.put("b266cd5c8544ba09b23733e3-d6296fc1-8e7b-4fdd-81ee-019de077bd97", pushParam); + + BatchPushSendParam param = new BatchPushSendParam(); + param.setSendParam(pushSendParam); + + BatchPushSendResult result = pushApi.batchSendByAlias(param); + log.info("result:{}", result); + } + + } diff --git a/jiguang-sdk/pom.xml b/jiguang-sdk/pom.xml index 22f0eac..66b3b16 100644 --- a/jiguang-sdk/pom.xml +++ b/jiguang-sdk/pom.xml @@ -7,13 +7,13 @@ io.github.jpush jiguang-sdk-java - 5.1.5 + 5.1.6 ../pom.xml io.github.jpush jiguang-sdk - 5.1.5 + 5.1.6 jar diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/api/PushApi.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/api/PushApi.java index 3d4bfd8..3c0a62f 100644 --- a/jiguang-sdk/src/main/java/cn/jiguang/sdk/api/PushApi.java +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/api/PushApi.java @@ -9,6 +9,8 @@ import cn.jiguang.sdk.bean.push.PushSendResult; import cn.jiguang.sdk.bean.push.SchedulePushSendParam; import cn.jiguang.sdk.bean.push.SchedulePushSendResult; +import cn.jiguang.sdk.bean.push.batch.BatchPushSendParam; +import cn.jiguang.sdk.bean.push.batch.BatchPushSendResult; import cn.jiguang.sdk.bean.push.other.CidGetResult; import cn.jiguang.sdk.bean.push.other.QuotaGetResult; import cn.jiguang.sdk.client.PushClient; @@ -99,6 +101,14 @@ public ImageFileUpdateResult updateImageFile(@NonNull String mediaId, @NonNull I return pushClient.updateImageFile(mediaId, param); } + public BatchPushSendResult batchSendByRegistrationId(BatchPushSendParam param) { + return pushClient.batchSendByRegistrationId(param); + } + + public BatchPushSendResult batchSendByAlias(BatchPushSendParam param) { + return pushClient.batchSendByAlias(param); + } + // ********************* 如果遇到此api没有及时补充字段的情况,可以自行构建json,调用下面的接口 ********************* public PushSendResult send(Object param) { diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushParam.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushParam.java new file mode 100644 index 0000000..6b684d4 --- /dev/null +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushParam.java @@ -0,0 +1,50 @@ +package cn.jiguang.sdk.bean.push.batch; + +import cn.jiguang.sdk.bean.push.callback.Callback; +import cn.jiguang.sdk.bean.push.message.custom.CustomMessage; +import cn.jiguang.sdk.bean.push.message.notification.NotificationMessage; +import cn.jiguang.sdk.bean.push.message.sms.SmsMessage; +import cn.jiguang.sdk.bean.push.options.Options; +import cn.jiguang.sdk.enums.platform.Platform; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class BatchPushParam { + + /** + * 此处填写的是 regId 值或者 alias 值 + */ + @JsonProperty("target") + private String target; + + /** + * 两种格式 + * 字符串:"all" + * {@link Platform}数组:["android","ios","hmos","quickapp"] + */ + @JsonProperty("platform") + private Object platform; + + @JsonProperty("options") + @JsonInclude(JsonInclude.Include.NON_NULL) + private Options options; + + @JsonProperty("notification") + @JsonInclude(JsonInclude.Include.NON_NULL) + private NotificationMessage notification; + + @JsonProperty("message") + @JsonInclude(JsonInclude.Include.NON_NULL) + private CustomMessage custom; + + @JsonProperty("sms_message") + @JsonInclude(JsonInclude.Include.NON_NULL) + private SmsMessage smsMessage; + + @JsonProperty("callback") + @JsonInclude(JsonInclude.Include.NON_NULL) + private Callback callback; + +} diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushResult.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushResult.java new file mode 100644 index 0000000..723dfb1 --- /dev/null +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushResult.java @@ -0,0 +1,21 @@ +package cn.jiguang.sdk.bean.push.batch; + +import cn.jiguang.sdk.exception.ApiErrorException; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class BatchPushResult { + + @JsonProperty("msg_id") + @JsonInclude(JsonInclude.Include.NON_NULL) + private String messageId; + + @JsonProperty("error") + @JsonInclude(JsonInclude.Include.NON_NULL) + private ApiErrorException.ApiError.Error error; + +} diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushSendParam.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushSendParam.java new file mode 100644 index 0000000..d0d874b --- /dev/null +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushSendParam.java @@ -0,0 +1,14 @@ +package cn.jiguang.sdk.bean.push.batch; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.Map; + +@Data +public class BatchPushSendParam { + + @JsonProperty("pushlist") + private Map sendParam; + +} diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushSendResult.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushSendResult.java new file mode 100644 index 0000000..9c41348 --- /dev/null +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/batch/BatchPushSendResult.java @@ -0,0 +1,21 @@ +package cn.jiguang.sdk.bean.push.batch; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class BatchPushSendResult { + + private Map sendResult = new HashMap<>(); + + @JsonAnySetter + public void addResult(String key, BatchPushResult value) { + sendResult.put(key, value); + } + +} diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/client/PushClient.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/client/PushClient.java index 85f6cac..47e61c8 100644 --- a/jiguang-sdk/src/main/java/cn/jiguang/sdk/client/PushClient.java +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/client/PushClient.java @@ -9,6 +9,8 @@ import cn.jiguang.sdk.bean.push.PushSendResult; import cn.jiguang.sdk.bean.push.SchedulePushSendParam; import cn.jiguang.sdk.bean.push.SchedulePushSendResult; +import cn.jiguang.sdk.bean.push.batch.BatchPushSendParam; +import cn.jiguang.sdk.bean.push.batch.BatchPushSendResult; import cn.jiguang.sdk.bean.push.other.CidGetResult; import cn.jiguang.sdk.bean.push.other.QuotaGetResult; import feign.Headers; @@ -88,6 +90,14 @@ public interface PushClient { @Headers("Content-Type: multipart/form-data") ImageFileUpdateResult updateImageFile(@Param("media_id") String mediaId, ImageFileUpdateParam param); + @RequestLine("POST /v3/push/batch/regid/single") + @Headers("Content-Type: application/json; charset=utf-8") + BatchPushSendResult batchSendByRegistrationId(BatchPushSendParam param); + + @RequestLine("POST /v3/push/batch/alias/single") + @Headers("Content-Type: application/json; charset=utf-8") + BatchPushSendResult batchSendByAlias(BatchPushSendParam param); + // ********************* 如果遇到此api没有及时补充字段的情况,可以自行构建json,调用下面的接口 ********************* @RequestLine("POST /v3/push") diff --git a/pom.xml b/pom.xml index 17d469d..a15e79a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.jpush jiguang-sdk-java - 5.1.5 + 5.1.6 pom Jiguang SDK For Rest Api