Skip to content

Commit

Permalink
add:同步官网更新
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanq committed May 29, 2023
1 parent 4492798 commit a415497
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 108 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>3.6.8</version>
<version>3.6.9</version>
<packaging>jar</packaging>
<url>https://github.com/jpush/jpush-api-java-client</url>
<name>JPush API Java Client</name>
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/cn/jpush/api/push/model/Notification3rd.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Notification3rd implements PushModel{
private static final String URI_ACTIVITY = "uri_activity";
private static final String URI_ACTION = "uri_action";
private static final String BADGE_ADD_NUM = "badge_add_num";
private static final String BADGE_SET_NUM = "badge_set_num";
private static final String BADGE_CLASS = "badge_class";
private static final String SOUND = "sound";
private static final String EXTRAS = "extras";
Expand All @@ -35,6 +36,7 @@ public class Notification3rd implements PushModel{
private final String uri_activity;
private final String uri_action;
private final int badge_add_num;
private final int badge_set_num;
private final String badge_class;
private final String sound;
private final Map<String, String> extras;
Expand All @@ -43,7 +45,7 @@ public class Notification3rd implements PushModel{
private final Map<String, JsonObject> jsonExtras;

private Notification3rd(String title, String content, String channel_id,
String uri_activity, String uri_action, int badge_add_num,
String uri_activity, String uri_action, int badge_add_num,int badge_set_num,
String badge_class, String sound,
Map<String, String> extras,
Map<String, Number> numberExtras,
Expand All @@ -55,6 +57,7 @@ private Notification3rd(String title, String content, String channel_id,
this.uri_activity = uri_activity;
this.uri_action = uri_action;
this.badge_add_num = badge_add_num;
this.badge_set_num = badge_set_num;
this.badge_class = badge_class;
this.sound = sound;
this.extras = extras;
Expand Down Expand Up @@ -97,6 +100,10 @@ public JsonElement toJSON() {
json.addProperty(BADGE_ADD_NUM, badge_add_num);
}

if (0 != badge_set_num) {
json.addProperty(BADGE_SET_NUM, badge_set_num);
}

if (null != badge_class) {
json.addProperty(BADGE_CLASS, badge_class);
}
Expand Down Expand Up @@ -164,6 +171,7 @@ public static class Builder{
private String uri_activity;
private String uri_action;
private int badge_add_num;
private int badge_set_num;
private String badge_class;
private String sound;
protected Map<String, String> extrasBuilder;
Expand Down Expand Up @@ -201,6 +209,11 @@ public Builder setBadgeAddNum(int badge_add_num) {
return this;
}

public Builder setBadgeSetNum(int badge_set_num) {
this.badge_set_num = badge_set_num;
return this;
}

public Builder setBadgeClass(String badge_class) {
this.badge_class = badge_class;
return this;
Expand Down Expand Up @@ -263,7 +276,7 @@ public Builder addExtra(String key, JsonObject value) {
public Notification3rd build() {
Preconditions.checkArgument(content != null && content != "", "content should not be null or empty");

return new Notification3rd(title, content, channel_id, uri_activity, uri_action, badge_add_num,
return new Notification3rd(title, content, channel_id, uri_activity, uri_action, badge_add_num, badge_set_num,
badge_class, sound, extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder);
}
}
Expand Down
67 changes: 34 additions & 33 deletions src/main/java/cn/jpush/api/push/model/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
import java.util.Map;
import java.util.Set;

/**
* 参考文档:https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push#options
*
* <p><b>Options</b></p>
* <br>
* <ul>
* <li>sendno: 推送序号 </li>
* <li>time_to_live: 离线消息保留时长 (秒) </li>
* <li>override_msg_id: 要覆盖的消息 ID </li>
* <li>apns_production: APNs 是否生产环境 </li>
* <li>apns_collapse_id: 更新 iOS 通知的标识符 </li>
* <li>big_push_duration: 定速推送时长 (分钟) </li>
* <li>third_party_channel: 推送请求下发通道 </li>
* <li>classification: 消息类型分类,极光不对指定的消息类型进行判断或校准,会以开发者自行指定的消息类型适配 Android 厂商通道。不填默认为 0 </li>
* </ul>
*/
public class Options implements PushModel {

private static final String SENDNO = "sendno";
Expand All @@ -20,6 +36,7 @@ public class Options implements PushModel {
private static final String BIG_PUSH_DURATION = "big_push_duration";
private static final String APNS_COLLAPSE_ID = "apns_collapse_id";
private static final String THIRD_PARTH_CHANNEl = "third_party_channel";
private static final String CLASSIFICATION = "classification";

private static final long NONE_TIME_TO_LIVE = -1;

Expand All @@ -30,45 +47,20 @@ public class Options implements PushModel {
// minutes
private int bigPushDuration;
private String apnsCollapseId;
private final Map<String, JsonPrimitive> customData;


private int classification;
/**
* {
* "third_party_channel":{
* "xiaomi":{
* "distribution":"ospush",
* "channel_id":"*******"
* },
* "huawei":{
* "distribution":"jpush"
* },
* "meizu":{
* "distribution":"jpush"
* },
* "fcm":{
* "distribution":"ospush"
* },
* "oppo":{
* "distribution":"ospush",
* "channel_id":"*******"
* },
* "vivo":{
* "distribution":"ospush",
* "classification":0 // 2020/06 新增,和vivo官方字段含义一致 0 代表运营消息,1 代表系统消息,不填vivo官方默认为0
* // 使用此字段时,需使用setThirdPartyChannelV2方法,因为此值只能为整数形式
* }
* }
* }
* 参考:https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push#third_party_channel-%E8%AF%B4%E6%98%8E
*/
private Map<String, JsonObject> thirdPartyChannel;
private final Map<String, JsonPrimitive> customData;

private Options(int sendno,
long overrideMsgId,
long timeToLive,
boolean apnsProduction,
int bigPushDuration,
String apnsCollapseId,
int classification,
Map<String, JsonObject> thirdPartyChannel,
Map<String, JsonPrimitive> customData) {
this.sendno = sendno;
Expand All @@ -77,6 +69,7 @@ private Options(int sendno,
this.apnsProduction = apnsProduction;
this.bigPushDuration = bigPushDuration;
this.apnsCollapseId = apnsCollapseId;
this.classification = classification;
this.thirdPartyChannel = thirdPartyChannel;
this.customData = customData;
}
Expand Down Expand Up @@ -132,6 +125,8 @@ public JsonElement toJSON() {
json.add(APNS_COLLAPSE_ID, new JsonPrimitive(apnsCollapseId));
}

json.add(CLASSIFICATION, new JsonPrimitive(classification));

if (null != thirdPartyChannel && thirdPartyChannel.size() > 0) {
JsonObject partyChannel = new JsonObject();
for (Map.Entry<String, JsonObject> entry : thirdPartyChannel.entrySet()) {
Expand All @@ -158,6 +153,7 @@ public static class Builder {
private boolean apnsProduction = false;
private int bigPushDuration = 0;
private String apnsCollapseId;
private int classification;
private Map<String, JsonObject> thirdPartyChannel;
private Map<String, JsonPrimitive> customData;

Expand Down Expand Up @@ -191,6 +187,11 @@ public Builder setBigPushDuration(int bigPushDuration) {
return this;
}

public Builder setClassification(int classification) {
this.classification = classification;
return this;
}

@Deprecated
public Map<String, Map<String, String>> getThirdPartyChannel() {
if (null != thirdPartyChannel) {
Expand Down Expand Up @@ -248,7 +249,7 @@ public Builder addCustom(Map<String, String> extras) {
}

public Builder addCustom(String key, Number value) {
Preconditions.checkArgument(! (null == key), "Key should not be null.");
Preconditions.checkArgument(!(null == key), "Key should not be null.");
if (customData == null) {
customData = new LinkedHashMap<String, JsonPrimitive>();
}
Expand All @@ -257,7 +258,7 @@ public Builder addCustom(String key, Number value) {
}

public Builder addCustom(String key, String value) {
Preconditions.checkArgument(! (null == key), "Key should not be null.");
Preconditions.checkArgument(!(null == key), "Key should not be null.");
if (customData == null) {
customData = new LinkedHashMap<String, JsonPrimitive>();
}
Expand All @@ -266,7 +267,7 @@ public Builder addCustom(String key, String value) {
}

public Builder addCustom(String key, Boolean value) {
Preconditions.checkArgument(! (null == key), "Key should not be null.");
Preconditions.checkArgument(!(null == key), "Key should not be null.");
if (customData == null) {
customData = new LinkedHashMap<String, JsonPrimitive>();
}
Expand All @@ -284,7 +285,7 @@ public Options build() {
sendno = ServiceHelper.generateSendno();
}

return new Options(sendno, overrideMsgId, timeToLive, apnsProduction, bigPushDuration, apnsCollapseId, thirdPartyChannel, customData);
return new Options(sendno, overrideMsgId, timeToLive, apnsProduction, bigPushDuration, apnsCollapseId, classification, thirdPartyChannel, customData);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,13 @@ public class LiveActivity implements PushModel {

private final String iOSEvent;
private final JsonObject iOSContentState;
private final String iOSAlertTitle;
private final String iOSAlertAlternateTitle;
private final String iOSAlertBody;
private final String iOSAlertAlternateBody;
private final String iOSAlertSound;
private final Integer iOSDismissalDate;

public LiveActivity(Boolean apnsProduction, String liveActivityId, String iOSEvent, JsonObject iOSContentState, String iOSAlertTitle, String iOSAlertAlternateTitle, String iOSAlertBody, String iOSAlertAlternateBody, String iOSAlertSound, Integer iOSDismissalDate) {
private final Long iOSDismissalDate;

public LiveActivity(Boolean apnsProduction, String liveActivityId, String iOSEvent, JsonObject iOSContentState, Long iOSDismissalDate) {
this.apnsProduction = apnsProduction;
this.liveActivityId = liveActivityId;
this.iOSEvent = iOSEvent;
this.iOSContentState = iOSContentState;
this.iOSAlertTitle = iOSAlertTitle;
this.iOSAlertAlternateTitle = iOSAlertAlternateTitle;
this.iOSAlertBody = iOSAlertBody;
this.iOSAlertAlternateBody = iOSAlertAlternateBody;
this.iOSAlertSound = iOSAlertSound;
this.iOSDismissalDate = iOSDismissalDate;
}

Expand All @@ -43,12 +33,7 @@ public static class Builder {
private String liveActivityId;
private String iOSEvent;
private JsonObject iOSContentState;
private String iOSAlertTitle;
private String iOSAlertAlternateTitle;
private String iOSAlertBody;
private String iOSAlertAlternateBody;
private String iOSAlertSound;
private Integer iOSDismissalDate;
private Long iOSDismissalDate;

public Builder apnsProduction(Boolean apnsProduction) {
this.apnsProduction = apnsProduction;
Expand Down Expand Up @@ -91,38 +76,13 @@ public Builder iOSContentState(String key, Boolean value) {
return this;
}

public Builder iOSAlertTitle(String iOSAlertTitle) {
this.iOSAlertTitle = iOSAlertTitle;
return this;
}

public Builder iOSAlertAlternateTitle(String iOSAlertAlternateTitle) {
this.iOSAlertAlternateTitle = iOSAlertAlternateTitle;
return this;
}

public Builder iOSAlertBody(String iOSAlertBody) {
this.iOSAlertBody = iOSAlertBody;
return this;
}

public Builder iOSAlertAlternateBody(String iOSAlertAlternateBody) {
this.iOSAlertAlternateBody = iOSAlertAlternateBody;
return this;
}

public Builder iOSAlertSound(String iOSAlertSound) {
this.iOSAlertSound = iOSAlertSound;
return this;
}

public Builder iOSDismissalDate(Integer iOSDismissalDate) {
public Builder iOSDismissalDate(Long iOSDismissalDate) {
this.iOSDismissalDate = iOSDismissalDate;
return this;
}

public LiveActivity build() {
return new LiveActivity(apnsProduction, liveActivityId, iOSEvent, iOSContentState, iOSAlertTitle, iOSAlertAlternateTitle, iOSAlertBody, iOSAlertAlternateBody, iOSAlertSound, iOSDismissalDate);
return new LiveActivity(apnsProduction, liveActivityId, iOSEvent, iOSContentState, iOSDismissalDate);
}

}
Expand All @@ -143,30 +103,11 @@ public JsonElement toJSON() {
if (apnsProduction != null) {
optionsJsonObject.addProperty("apns_production", apnsProduction);
}
if (iOSAlertTitle != null || iOSAlertAlternateTitle != null || iOSAlertBody != null || iOSAlertAlternateBody != null || iOSAlertSound != null) {
optionsJsonObject.addProperty("alternate_set", true);
}

JsonObject liveActivityJsonObject = new JsonObject();
JsonObject iOSJsonObject = new JsonObject();
JsonObject alertJsonObject = new JsonObject();

if (iOSAlertTitle != null) {
alertJsonObject.addProperty("title", iOSAlertTitle);
}
if (iOSAlertAlternateTitle != null) {
alertJsonObject.addProperty("alternate_title", iOSAlertAlternateTitle);
}
if (iOSAlertBody != null) {
alertJsonObject.addProperty("body", iOSAlertBody);
}
if (iOSAlertAlternateBody != null) {
alertJsonObject.addProperty("alternate_body", iOSAlertAlternateBody);
}
if (iOSAlertSound != null) {
alertJsonObject.addProperty("sound", iOSAlertSound);
}

if (iOSEvent != null) {
iOSJsonObject.addProperty("event", iOSEvent);
}
Expand All @@ -176,7 +117,7 @@ public JsonElement toJSON() {
if (!alertJsonObject.entrySet().isEmpty()) {
iOSJsonObject.add("alert", alertJsonObject);
}
if (iOSDismissalDate != null) {
if (!alertJsonObject.entrySet().isEmpty()) {
iOSJsonObject.addProperty("dismissal-date", iOSDismissalDate);
}

Expand Down
Loading

0 comments on commit a415497

Please sign in to comment.