From 8003193b175191f93b8381de288c756e0adadba7 Mon Sep 17 00:00:00 2001 From: wicked-tc130 Date: Tue, 10 Sep 2024 19:42:52 +0800 Subject: [PATCH] update version to 5.1.8. --- README.md | 4 +- example-for-spring/pom.xml | 4 +- .../java/cn/jiguang/app/api/PushApiTest.java | 55 +++++++++++++++++-- jiguang-sdk/pom.xml | 4 +- .../main/java/cn/jiguang/sdk/api/PushApi.java | 13 +++-- .../push/ScheduleTemplatePushSendParam.java | 15 +++++ .../push/ScheduleTemplatePushSendResult.java | 29 ++++++++++ .../sdk/bean/push/TemplatePushSendParam.java | 18 ++++++ .../sdk/bean/push/TemplatePushSendResult.java | 29 ++++++++++ .../sdk/bean/push/other/TemplateParam.java | 28 ++++++++++ .../sdk/bean/push/other/TemplateResult.java | 25 +++++++++ .../cn/jiguang/sdk/client/PushClient.java | 13 +++-- .../cn/jiguang/sdk/codec/ApiErrorDecoder.java | 27 ++++++++- pom.xml | 2 +- 14 files changed, 244 insertions(+), 22 deletions(-) create mode 100644 jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/ScheduleTemplatePushSendParam.java create mode 100644 jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/ScheduleTemplatePushSendResult.java create mode 100644 jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/TemplatePushSendParam.java create mode 100644 jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/TemplatePushSendResult.java create mode 100644 jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/TemplateParam.java create mode 100644 jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/TemplateResult.java diff --git a/README.md b/README.md index b8190e5..e54be92 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ ## 1. 集成 引入sdk包 ```xml - + io.github.jpush jiguang-sdk - 5.1.7 + 5.1.8 ``` diff --git a/example-for-spring/pom.xml b/example-for-spring/pom.xml index 1797d3c..400f78d 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.7 + 5.1.8 8 @@ -26,7 +26,7 @@ io.github.jpush jiguang-sdk - 5.1.7 + 5.1.8 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 10aed2f..fc713c8 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 @@ -6,8 +6,7 @@ import cn.jiguang.sdk.bean.file.FileUploadResult; import cn.jiguang.sdk.bean.file.FilesGetResult; import cn.jiguang.sdk.bean.image.*; -import cn.jiguang.sdk.bean.push.PushSendParam; -import cn.jiguang.sdk.bean.push.PushSendResult; +import cn.jiguang.sdk.bean.push.*; import cn.jiguang.sdk.bean.push.audience.Audience; import cn.jiguang.sdk.bean.push.batch.BatchPushParam; import cn.jiguang.sdk.bean.push.batch.BatchPushSendParam; @@ -17,6 +16,7 @@ import cn.jiguang.sdk.bean.push.options.Options; import cn.jiguang.sdk.bean.push.other.CidGetResult; import cn.jiguang.sdk.bean.push.other.QuotaGetResult; +import cn.jiguang.sdk.bean.push.other.TemplateParam; import cn.jiguang.sdk.constants.ApiConstants; import cn.jiguang.sdk.enums.platform.Platform; import com.fasterxml.jackson.databind.ObjectMapper; @@ -28,9 +28,8 @@ import org.springframework.test.context.junit4.SpringRunner; import java.io.File; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; +import java.time.LocalDateTime; +import java.util.*; @Slf4j @SpringBootTest() @@ -314,5 +313,51 @@ public void batchSendByAlias() { log.info("result:{}", result); } + @Test + public void templateSend() { + Map keys = new HashMap<>(); + keys.put("title", "template-title"); + keys.put("content", "template-content"); + keys.put("deeplink", "intent:#Intent;component=com.jiguang.push/com.example.jpushdemo.SettingActivity;end"); + + List templateParams = new ArrayList<>(); + TemplateParam templateParam = new TemplateParam(); + templateParam.setKeys(keys); + templateParam.setAudience(ApiConstants.Audience.ALL); + templateParams.add(templateParam); + + TemplatePushSendParam param = new ScheduleTemplatePushSendParam(); + param.setId("1770D8D90FA49AAA"); + param.setParams(templateParams); + TemplatePushSendResult result = pushApi.templateSend(param); + log.info("result:{}", result); + } + + @Test + public void scheduleTemplateSend() { + Map keys = new HashMap<>(); + keys.put("xxx", "王"); + keys.put("number", "6666"); + keys.put("amount", "9999"); + + List templateParams = new ArrayList<>(); + TemplateParam templateParam = new TemplateParam(); + templateParam.setKeys(keys); + templateParam.setAudience(ApiConstants.Audience.ALL); + templateParams.add(templateParam); + + SchedulePushSendParam.Trigger.Single single = new SchedulePushSendParam.Trigger.Single(); + single.setTime(LocalDateTime.now().plusDays(1)); + SchedulePushSendParam.Trigger trigger = new SchedulePushSendParam.Trigger(); + trigger.setSingle(single); + + ScheduleTemplatePushSendParam param = new ScheduleTemplatePushSendParam(); + param.setId("1770D8D90FA4994D"); + param.setParams(templateParams); + param.setScheduleName("定时模板推送示例"); + param.setTrigger(trigger); + ScheduleTemplatePushSendResult result = pushApi.scheduleTemplateSend(param); + log.info("result:{}", result); + } } diff --git a/jiguang-sdk/pom.xml b/jiguang-sdk/pom.xml index 1fddf89..054650a 100644 --- a/jiguang-sdk/pom.xml +++ b/jiguang-sdk/pom.xml @@ -7,13 +7,13 @@ io.github.jpush jiguang-sdk-java - 5.1.7 + 5.1.8 ../pom.xml io.github.jpush jiguang-sdk - 5.1.7 + 5.1.8 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 3c0a62f..03720a5 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 @@ -5,10 +5,7 @@ import cn.jiguang.sdk.bean.file.FileUploadResult; import cn.jiguang.sdk.bean.file.FilesGetResult; import cn.jiguang.sdk.bean.image.*; -import cn.jiguang.sdk.bean.push.PushSendParam; -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.*; import cn.jiguang.sdk.bean.push.batch.BatchPushSendParam; import cn.jiguang.sdk.bean.push.batch.BatchPushSendResult; import cn.jiguang.sdk.bean.push.other.CidGetResult; @@ -109,6 +106,14 @@ public BatchPushSendResult batchSendByAlias(BatchPushSendParam param) { return pushClient.batchSendByAlias(param); } + public TemplatePushSendResult templateSend(TemplatePushSendParam param) { + return pushClient.templateSend(param); + } + + public ScheduleTemplatePushSendResult scheduleTemplateSend(ScheduleTemplatePushSendParam param) { + return pushClient.scheduleTemplateSend(param); + } + // ********************* 如果遇到此api没有及时补充字段的情况,可以自行构建json,调用下面的接口 ********************* public PushSendResult send(Object param) { diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/ScheduleTemplatePushSendParam.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/ScheduleTemplatePushSendParam.java new file mode 100644 index 0000000..29a1e07 --- /dev/null +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/ScheduleTemplatePushSendParam.java @@ -0,0 +1,15 @@ +package cn.jiguang.sdk.bean.push; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class ScheduleTemplatePushSendParam extends TemplatePushSendParam { + + @JsonProperty("schedule_name") + private String scheduleName; + + @JsonProperty("trigger") + private SchedulePushSendParam.Trigger trigger; + +} diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/ScheduleTemplatePushSendResult.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/ScheduleTemplatePushSendResult.java new file mode 100644 index 0000000..8a27ada --- /dev/null +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/ScheduleTemplatePushSendResult.java @@ -0,0 +1,29 @@ +package cn.jiguang.sdk.bean.push; + +import cn.jiguang.sdk.bean.push.other.TemplateResult; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class ScheduleTemplatePushSendResult { + + @JsonProperty("code") + private Integer code; + + @JsonProperty("message") + private String message; + + @JsonProperty("data") + private Data data; + + @lombok.Data + public static class Data { + + @JsonProperty("schedule_list") + private List results; + + } + +} diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/TemplatePushSendParam.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/TemplatePushSendParam.java new file mode 100644 index 0000000..9a1ddf2 --- /dev/null +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/TemplatePushSendParam.java @@ -0,0 +1,18 @@ +package cn.jiguang.sdk.bean.push; + +import cn.jiguang.sdk.bean.push.other.TemplateParam; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class TemplatePushSendParam { + + @JsonProperty("id") + private String id; + + @JsonProperty("params") + private List params; + +} diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/TemplatePushSendResult.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/TemplatePushSendResult.java new file mode 100644 index 0000000..c5d1ef0 --- /dev/null +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/TemplatePushSendResult.java @@ -0,0 +1,29 @@ +package cn.jiguang.sdk.bean.push; + +import cn.jiguang.sdk.bean.push.other.TemplateResult; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class TemplatePushSendResult { + + @JsonProperty("code") + private Integer code; + + @JsonProperty("message") + private String message; + + @JsonProperty("data") + private Data data; + + @lombok.Data + public static class Data { + + @JsonProperty("push_list") + private List results; + + } + +} diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/TemplateParam.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/TemplateParam.java new file mode 100644 index 0000000..ff787a6 --- /dev/null +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/TemplateParam.java @@ -0,0 +1,28 @@ +package cn.jiguang.sdk.bean.push.other; + +import cn.jiguang.sdk.bean.push.audience.Audience; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.Map; + +@Data +public class TemplateParam { + + /** + * 两种格式 + * 字符串:"all" + * {@link Audience}对象: {"tag":[],"tag_and":[],"tag_not":[],"alias":[],"registration_id":[],"segment":[],"abtest":[],"live_activity_id":"","file":{"file_id":""}} + */ + @JsonProperty("audience") + private Object audience; + + @JsonProperty("keys") + private Map keys; + + @JsonProperty("trace_id") + @JsonInclude(JsonInclude.Include.NON_NULL) + private String traceId; + +} diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/TemplateResult.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/TemplateResult.java new file mode 100644 index 0000000..ae1be70 --- /dev/null +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/other/TemplateResult.java @@ -0,0 +1,25 @@ +package cn.jiguang.sdk.bean.push.other; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class TemplateResult { + + @JsonProperty("code") + private Integer code; + + @JsonProperty("message") + @JsonInclude(JsonInclude.Include.NON_NULL) + private String message; + + @JsonProperty("message_id") + @JsonInclude(JsonInclude.Include.NON_NULL) + private String messageId; + + @JsonProperty("schedule_id") + @JsonInclude(JsonInclude.Include.NON_NULL) + private String scheduleId; + +} 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 47e61c8..97071a3 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 @@ -5,10 +5,7 @@ import cn.jiguang.sdk.bean.file.FileUploadResult; import cn.jiguang.sdk.bean.file.FilesGetResult; import cn.jiguang.sdk.bean.image.*; -import cn.jiguang.sdk.bean.push.PushSendParam; -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.*; import cn.jiguang.sdk.bean.push.batch.BatchPushSendParam; import cn.jiguang.sdk.bean.push.batch.BatchPushSendResult; import cn.jiguang.sdk.bean.push.other.CidGetResult; @@ -98,6 +95,14 @@ public interface PushClient { @Headers("Content-Type: application/json; charset=utf-8") BatchPushSendResult batchSendByAlias(BatchPushSendParam param); + @RequestLine("POST /v3/push/template") + @Headers("Content-Type: application/json; charset=utf-8") + TemplatePushSendResult templateSend(TemplatePushSendParam param); + + @RequestLine("POST /v3/push/template/schedule") + @Headers("Content-Type: application/json; charset=utf-8") + ScheduleTemplatePushSendResult scheduleTemplateSend(ScheduleTemplatePushSendParam param); + // ********************* 如果遇到此api没有及时补充字段的情况,可以自行构建json,调用下面的接口 ********************* @RequestLine("POST /v3/push") diff --git a/jiguang-sdk/src/main/java/cn/jiguang/sdk/codec/ApiErrorDecoder.java b/jiguang-sdk/src/main/java/cn/jiguang/sdk/codec/ApiErrorDecoder.java index 07a0736..a1bbd30 100644 --- a/jiguang-sdk/src/main/java/cn/jiguang/sdk/codec/ApiErrorDecoder.java +++ b/jiguang-sdk/src/main/java/cn/jiguang/sdk/codec/ApiErrorDecoder.java @@ -1,26 +1,49 @@ package cn.jiguang.sdk.codec; +import cn.jiguang.sdk.bean.push.other.TemplateResult; import cn.jiguang.sdk.exception.ApiErrorException; import com.fasterxml.jackson.databind.ObjectMapper; import feign.Response; import feign.Util; import feign.codec.ErrorDecoder; +import lombok.extern.slf4j.Slf4j; import java.nio.charset.StandardCharsets; +@Slf4j public class ApiErrorDecoder implements ErrorDecoder { @Override public Exception decode(String methodKey, Response response) { int status = response.status(); + Response.Body body = response.body(); + if (methodKey.contains("templateSend") || methodKey.contains("scheduleTemplateSend")) { + try { + String bodyContent = Util.toString(body.asReader(StandardCharsets.UTF_8)); + TemplateResult templateResult = new ObjectMapper().readValue(bodyContent, TemplateResult.class); + return buildApiErrorException(status, templateResult.getCode(), templateResult.getMessage()); + } catch (Exception exception) { + log.error("unknown error", exception); + return buildApiErrorException(status, 500, "unknown error"); + } + } try { - Response.Body body = response.body(); String bodyContent = Util.toString(body.asReader(StandardCharsets.UTF_8)); ApiErrorException.ApiError apiError = new ObjectMapper().readValue(bodyContent, ApiErrorException.ApiError.class); return new ApiErrorException(status, apiError); } catch (Exception exception) { - return new ApiErrorException(status, null); + log.error("unknown error", exception); + return buildApiErrorException(status, 500, "unknown error"); } } + private ApiErrorException buildApiErrorException(int status, int code, String message) { + ApiErrorException.ApiError.Error error = new ApiErrorException.ApiError.Error(); + error.setCode(code); + error.setMessage(message); + ApiErrorException.ApiError apiError = new ApiErrorException.ApiError(); + apiError.setError(error); + return new ApiErrorException(status, apiError); + } + } diff --git a/pom.xml b/pom.xml index 19e92d7..b86e095 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.jpush jiguang-sdk-java - 5.1.7 + 5.1.8 pom Jiguang SDK For Rest Api