Skip to content

Commit

Permalink
update version to 5.1.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
wicked-tc130 committed Sep 10, 2024
1 parent 84b6b29 commit 8003193
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
## 1. 集成
引入sdk包
```xml
<!--以5.1.7版本为例-->
<!--以5.1.8版本为例-->
<dependencies>
<!-- jiguang-sdk -->
<dependency>
<groupId>io.github.jpush</groupId>
<artifactId>jiguang-sdk</artifactId>
<version>5.1.7</version>
<version>5.1.8</version>
</dependency>
</dependencies>
```
Expand Down
4 changes: 2 additions & 2 deletions example-for-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>io.github.jpush</groupId>
<artifactId>example-for-spring</artifactId>
<version>5.1.7</version>
<version>5.1.8</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand All @@ -26,7 +26,7 @@
<dependency>
<groupId>io.github.jpush</groupId>
<artifactId>jiguang-sdk</artifactId>
<version>5.1.7</version>
<version>5.1.8</version>
</dependency>
<!-- lombok -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -314,5 +313,51 @@ public void batchSendByAlias() {
log.info("result:{}", result);
}

@Test
public void templateSend() {
Map<String, String> 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<TemplateParam> 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<String, String> keys = new HashMap<>();
keys.put("xxx", "王");
keys.put("number", "6666");
keys.put("amount", "9999");

List<TemplateParam> 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);
}

}
4 changes: 2 additions & 2 deletions jiguang-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<parent>
<groupId>io.github.jpush</groupId>
<artifactId>jiguang-sdk-java</artifactId>
<version>5.1.7</version>
<version>5.1.8</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>io.github.jpush</groupId>
<artifactId>jiguang-sdk</artifactId>
<version>5.1.7</version>
<version>5.1.8</version>
<packaging>jar</packaging>

<properties>
Expand Down
13 changes: 9 additions & 4 deletions jiguang-sdk/src/main/java/cn/jiguang/sdk/api/PushApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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<TemplateResult> results;

}

}
Original file line number Diff line number Diff line change
@@ -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<TemplateParam> params;

}
Original file line number Diff line number Diff line change
@@ -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<TemplateResult> results;

}

}
Original file line number Diff line number Diff line change
@@ -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<String, String> keys;

@JsonProperty("trace_id")
@JsonInclude(JsonInclude.Include.NON_NULL)
private String traceId;

}
Original file line number Diff line number Diff line change
@@ -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;

}
13 changes: 9 additions & 4 deletions jiguang-sdk/src/main/java/cn/jiguang/sdk/client/PushClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.jpush</groupId>
<artifactId>jiguang-sdk-java</artifactId>
<version>5.1.7</version>
<version>5.1.8</version>
<packaging>pom</packaging>

<name>Jiguang SDK For Rest Api</name>
Expand Down

0 comments on commit 8003193

Please sign in to comment.