-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support group push, update version to 5.1.3.
- Loading branch information
1 parent
2e7ff3b
commit c3edecb
Showing
14 changed files
with
279 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
example-for-spring/src/test/java/cn/jiguang/app/api/GroupPushApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package cn.jiguang.app.api; | ||
|
||
import cn.jiguang.sdk.api.GroupPushApi; | ||
import cn.jiguang.sdk.bean.push.GroupPushSendParam; | ||
import cn.jiguang.sdk.bean.push.GroupPushSendResult; | ||
import cn.jiguang.sdk.bean.push.audience.Audience; | ||
import cn.jiguang.sdk.bean.push.message.notification.NotificationMessage; | ||
import cn.jiguang.sdk.bean.push.options.Options; | ||
import cn.jiguang.sdk.constants.ApiConstants; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
@SpringBootTest() | ||
@RunWith(SpringRunner.class) | ||
public class GroupPushApiTest { | ||
|
||
@Autowired | ||
private GroupPushApi groupPushApi; | ||
|
||
@Test | ||
public void send() { | ||
GroupPushSendParam param = new GroupPushSendParam(); | ||
// 通知内容 | ||
NotificationMessage.Android android = new NotificationMessage.Android(); | ||
android.setAlert("this is android alert"); | ||
android.setTitle("this is android title"); | ||
|
||
NotificationMessage.IOS iOS = new NotificationMessage.IOS(); | ||
Map<String, String> iOSAlert = new HashMap<>(); | ||
iOSAlert.put("title", "this is iOS title"); | ||
iOSAlert.put("subtitle", "this is iOS subtitle"); | ||
iOS.setAlert(iOSAlert); | ||
|
||
Map<String, Object> extrasMap = new HashMap<>(); | ||
Map<String, Object> extrasParamMap = new HashMap<>(); | ||
extrasParamMap.put("key1", "value1"); | ||
extrasParamMap.put("key2", "value2"); | ||
extrasMap.put("params", extrasParamMap); | ||
android.setExtras(extrasMap); | ||
iOS.setExtras(extrasMap); | ||
|
||
NotificationMessage notificationMessage = new NotificationMessage(); | ||
notificationMessage.setAlert("this is alert"); | ||
notificationMessage.setAndroid(android); | ||
notificationMessage.setIos(iOS); | ||
param.setNotification(notificationMessage); | ||
|
||
// 目标人群 | ||
Audience audience = new Audience(); | ||
audience.setRegistrationIdList(Arrays.asList("1104a89793af2cfc030", "1104a89793af2cfc030")); | ||
// 指定目标 | ||
param.setAudience(audience); | ||
|
||
// 或者发送所有人 | ||
// param.setAudience(ApiConstants.Audience.ALL); | ||
|
||
// 指定平台 | ||
// param.setPlatform(Arrays.asList(Platform.android, Platform.ios)); | ||
// 或者发送所有平台 | ||
param.setPlatform(ApiConstants.Platform.ALL); | ||
|
||
// Android厂商 | ||
// param.setThirdNotificationMessage(); | ||
|
||
// 短信补充 | ||
// param.setSmsMessage(); | ||
|
||
// 回调 | ||
// param.setCallback(); | ||
|
||
// options | ||
Options options = new Options(); | ||
Map<String, Object> thirdPartyMap = new HashMap<>(); | ||
Map<String, Object> huaweiMap = new HashMap<>(); | ||
huaweiMap.put("distribution", "first_ospush"); | ||
huaweiMap.put("importance", "NORMAL"); | ||
huaweiMap.put("category", "MARKETING"); | ||
thirdPartyMap.put("huawei", huaweiMap); | ||
options.setThirdPartyChannel(thirdPartyMap); | ||
// param.setOptions(options); | ||
|
||
// 发送 | ||
GroupPushSendResult result = groupPushApi.send(param); | ||
log.info("result:{}", result); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
jiguang-sdk/src/main/java/cn/jiguang/sdk/api/GroupPushApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package cn.jiguang.sdk.api; | ||
|
||
import cn.jiguang.sdk.bean.push.GroupPushSendParam; | ||
import cn.jiguang.sdk.bean.push.GroupPushSendResult; | ||
import cn.jiguang.sdk.client.GroupPushClient; | ||
import cn.jiguang.sdk.codec.ApiDecoder; | ||
import cn.jiguang.sdk.codec.ApiEncoder; | ||
import cn.jiguang.sdk.codec.ApiErrorDecoder; | ||
import feign.Feign; | ||
import feign.Logger; | ||
import feign.auth.BasicAuthRequestInterceptor; | ||
import feign.okhttp.OkHttpClient; | ||
import feign.slf4j.Slf4jLogger; | ||
import lombok.NonNull; | ||
|
||
import java.net.Proxy; | ||
|
||
public class GroupPushApi { | ||
|
||
private final GroupPushClient groupPushClient; | ||
|
||
protected GroupPushApi(@NonNull GroupPushClient groupPushClient) { | ||
this.groupPushClient = groupPushClient; | ||
} | ||
|
||
public GroupPushSendResult send(@NonNull GroupPushSendParam param) { | ||
return groupPushClient.send(param); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private String host = "https://api.jpush.cn"; | ||
private Proxy proxy; | ||
private String groupKey; | ||
private String groupMasterSecret; | ||
private Logger.Level loggerLevel = Logger.Level.BASIC; | ||
|
||
public Builder setHost(@NonNull String host) { | ||
this.host = host; | ||
return this; | ||
} | ||
|
||
public Builder setProxy(@NonNull Proxy proxy) { | ||
this.proxy = proxy; | ||
return this; | ||
} | ||
|
||
public Builder setGroupKey(@NonNull String groupKey) { | ||
this.groupKey = groupKey; | ||
return this; | ||
} | ||
|
||
public Builder setGroupMasterSecret(@NonNull String groupMasterSecret) { | ||
this.groupMasterSecret = groupMasterSecret; | ||
return this; | ||
} | ||
|
||
public Builder setLoggerLevel(@NonNull Logger.Level loggerLevel) { | ||
this.loggerLevel = loggerLevel; | ||
return this; | ||
} | ||
|
||
public GroupPushApi build() { | ||
okhttp3.OkHttpClient.Builder delegateBuilder = new okhttp3.OkHttpClient().newBuilder(); | ||
if (proxy != null) { | ||
delegateBuilder.proxy(proxy); | ||
} | ||
GroupPushClient groupPushClient = Feign.builder() | ||
.client(new OkHttpClient(delegateBuilder.build())) | ||
.requestInterceptor(new BasicAuthRequestInterceptor("group-" + groupKey, groupMasterSecret)) | ||
.encoder(new ApiEncoder()) | ||
.decoder(new ApiDecoder()) | ||
.errorDecoder(new ApiErrorDecoder()) | ||
.logger(new Slf4jLogger()) | ||
.logLevel(loggerLevel) | ||
.target(GroupPushClient.class, host); | ||
return new GroupPushApi(groupPushClient); | ||
} | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/GroupPushSendParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cn.jiguang.sdk.bean.push; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class GroupPushSendParam extends PushSendParam{ | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
jiguang-sdk/src/main/java/cn/jiguang/sdk/bean/push/GroupPushSendResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cn.jiguang.sdk.bean.push; | ||
|
||
import cn.jiguang.sdk.exception.ApiErrorException; | ||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import lombok.Data; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Data | ||
public class GroupPushSendResult { | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private Map<String, ApiErrorException.ApiError.Error> errors = new HashMap<>(); | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private Map<String, PushSendResult> successes = new HashMap<>(); | ||
|
||
@JsonProperty("group_msgid") | ||
private String groupMessageId; | ||
|
||
@JsonAnySetter | ||
public void handleUnknown(String key, JsonNode value) { | ||
if (key.equals("group_msgid")) { | ||
setGroupMessageId(value.asText()); | ||
} else if (value.has("error")) { | ||
ApiErrorException.ApiError.Error errorDetail = new ApiErrorException.ApiError.Error(); | ||
errorDetail.setCode(value.get("error").get("code").asInt()); | ||
errorDetail.setMessage(value.get("error").get("message").asText()); | ||
errors.put(key, errorDetail); | ||
} else if (value.has("msg_id")) { | ||
PushSendResult successDetail = new PushSendResult(); | ||
successDetail.setMessageId(value.get("msg_id").asText()); | ||
successDetail.setSendNo(value.get("sendno").asText()); | ||
successes.put(key, successDetail); | ||
} | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
jiguang-sdk/src/main/java/cn/jiguang/sdk/client/GroupPushClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cn.jiguang.sdk.client; | ||
|
||
import cn.jiguang.sdk.bean.push.GroupPushSendParam; | ||
import cn.jiguang.sdk.bean.push.GroupPushSendResult; | ||
import feign.Headers; | ||
import feign.RequestLine; | ||
|
||
/** | ||
* (<a href="https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push_grouppush">REST API - GroupPush</a>) | ||
*/ | ||
public interface GroupPushClient { | ||
|
||
@RequestLine("POST /v3/grouppush") | ||
@Headers("Content-Type: application/json; charset=utf-8") | ||
GroupPushSendResult send(GroupPushSendParam param); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters