11package cn .jpush .api .push .model ;
22
33
4- import com .google .gson .JsonElement ;
5- import com .google .gson .JsonObject ;
6- import com .google .gson .JsonPrimitive ;
4+ import com .google .gson .*;
75
86import cn .jiguang .common .ServiceHelper ;
97import cn .jiguang .common .utils .Preconditions ;
108
9+ import java .util .Map ;
10+
1111public class Options implements PushModel {
12+
1213 private static final String SENDNO = "sendno" ;
1314 private static final String OVERRIDE_MSG_ID = "override_msg_id" ;
1415 private static final String TIME_TO_LIVE = "time_to_live" ;
1516 private static final String APNS_PRODUCTION = "apns_production" ;
1617 private static final String BIG_PUSH_DURATION = "big_push_duration" ;
1718 private static final String APNS_COLLAPSE_ID = "apns_collapse_id" ;
18-
19+ private static final String THIRD_PARTH_CHANNEl = "third_party_channel" ;
20+
1921 private static final long NONE_TIME_TO_LIVE = -1 ;
20-
22+
2123 private final int sendno ;
2224 private final long overrideMsgId ;
2325 private long timeToLive ;
2426 private boolean apnsProduction ;
25- private int bigPushDuration ; // minutes
27+ // minutes
28+ private int bigPushDuration ;
2629 private String apnsCollapseId ;
27-
28- private Options (int sendno , long overrideMsgId , long timeToLive , boolean apnsProduction ,
29- int bigPushDuration , String apnsCollapseId ) {
30+
31+ /**
32+ * example
33+ * "third_party_channel": {
34+ * "xiaomi": {
35+ * "distribution": "ospush"
36+ * },
37+ * "huawei": {
38+ * "distribution": "jpush"
39+ * },
40+ * "meizu": {
41+ * "distribution": "jpush"
42+ * },
43+ * "fcm": {
44+ * "distribution": "ospush"
45+ * },
46+ * "oppo": {
47+ * "distribution": "ospush"
48+ * },
49+ * "vivo": {
50+ * "distribution": "ospush"
51+ * }
52+ * }
53+ */
54+ private Map <String , Map <String , String >> thirdPartyChannel ;
55+
56+ private Options (int sendno ,
57+ long overrideMsgId ,
58+ long timeToLive ,
59+ boolean apnsProduction ,
60+ int bigPushDuration ,
61+ String apnsCollapseId ,
62+ Map <String , Map <String , String >> thirdPartyChannel ) {
3063 this .sendno = sendno ;
3164 this .overrideMsgId = overrideMsgId ;
3265 this .timeToLive = timeToLive ;
3366 this .apnsProduction = apnsProduction ;
3467 this .bigPushDuration = bigPushDuration ;
3568 this .apnsCollapseId = apnsCollapseId ;
69+ this .thirdPartyChannel = thirdPartyChannel ;
3670 }
37-
71+
3872 public static Builder newBuilder () {
3973 return new Builder ();
4074 }
41-
75+
4276 public static Options sendno () {
4377 return newBuilder ().setSendno (ServiceHelper .generateSendno ()).build ();
4478 }
45-
79+
4680 public static Options sendno (int sendno ) {
4781 return newBuilder ().setSendno (sendno ).build ();
4882 }
49-
83+
5084 public void setApnsProduction (boolean apnsProduction ) {
5185 this .apnsProduction = apnsProduction ;
5286 }
53-
87+
5488 public void setTimeToLive (long timeToLive ) {
5589 this .timeToLive = timeToLive ;
5690 }
57-
91+
5892 public void setBigPushDuration (int bigPushDuration ) {
59- this .bigPushDuration = bigPushDuration ;
93+ this .bigPushDuration = bigPushDuration ;
6094 }
61-
95+
6296 public int getSendno () {
6397 return this .sendno ;
6498 }
65-
99+
66100 @ Override
67101 public JsonElement toJSON () {
68102 JsonObject json = new JsonObject ();
@@ -75,43 +109,57 @@ public JsonElement toJSON() {
75109 if (timeToLive >= 0 ) {
76110 json .add (TIME_TO_LIVE , new JsonPrimitive (timeToLive ));
77111 }
78-
112+
79113 json .add (APNS_PRODUCTION , new JsonPrimitive (apnsProduction ));
80-
114+
81115 if (bigPushDuration > 0 ) {
82- json .add (BIG_PUSH_DURATION , new JsonPrimitive (bigPushDuration ));
116+ json .add (BIG_PUSH_DURATION , new JsonPrimitive (bigPushDuration ));
83117 }
84118
85119 if (apnsCollapseId != null ) {
86120 json .add (APNS_COLLAPSE_ID , new JsonPrimitive (apnsCollapseId ));
87121 }
88-
122+
123+ if (null != thirdPartyChannel && thirdPartyChannel .size () > 0 ) {
124+ JsonObject partyChannel = new JsonObject ();
125+ for (Map .Entry <String , Map <String , String >> entry : thirdPartyChannel .entrySet ()) {
126+ JsonObject channel = new JsonObject ();
127+ for (Map .Entry <String , String > stringEntry : entry .getValue ().entrySet ()) {
128+ channel .addProperty (stringEntry .getKey (), stringEntry .getValue ());
129+ }
130+ partyChannel .add (entry .getKey (), channel );
131+ }
132+ json .add (THIRD_PARTH_CHANNEl , partyChannel );
133+ }
134+
89135 return json ;
90136 }
91-
137+
92138 public static class Builder {
139+
93140 private int sendno = 0 ;
94141 private long overrideMsgId = 0 ;
95142 private long timeToLive = NONE_TIME_TO_LIVE ;
96143 private boolean apnsProduction = false ;
97144 private int bigPushDuration = 0 ;
98145 private String apnsCollapseId ;
99-
146+ private Map <String , Map <String , String >> thirdPartyChannel ;
147+
100148 public Builder setSendno (int sendno ) {
101149 this .sendno = sendno ;
102150 return this ;
103151 }
104-
152+
105153 public Builder setOverrideMsgId (long overrideMsgId ) {
106154 this .overrideMsgId = overrideMsgId ;
107155 return this ;
108156 }
109-
157+
110158 public Builder setTimeToLive (long timeToLive ) {
111159 this .timeToLive = timeToLive ;
112160 return this ;
113161 }
114-
162+
115163 public Builder setApnsProduction (boolean apnsProduction ) {
116164 this .apnsProduction = apnsProduction ;
117165 return this ;
@@ -121,22 +169,32 @@ public Builder setApnsCollapseId(String id) {
121169 this .apnsCollapseId = id ;
122170 return this ;
123171 }
124-
172+
125173 public Builder setBigPushDuration (int bigPushDuration ) {
126- this .bigPushDuration = bigPushDuration ;
127- return this ;
174+ this .bigPushDuration = bigPushDuration ;
175+ return this ;
176+ }
177+
178+ public Map <String , Map <String , String >> getThirdPartyChannel () {
179+ return thirdPartyChannel ;
180+ }
181+
182+ public Builder setThirdPartyChannel (Map <String , Map <String , String >> thirdPartyChannel ) {
183+ this .thirdPartyChannel = thirdPartyChannel ;
184+ return this ;
128185 }
129186
130187 public Options build () {
131188 Preconditions .checkArgument (sendno >= 0 , "sendno should be greater than 0." );
132189 Preconditions .checkArgument (overrideMsgId >= 0 , "override_msg_id should be greater than 0." );
133190 Preconditions .checkArgument (timeToLive >= NONE_TIME_TO_LIVE , "time_to_live should be greater than 0." );
134191 Preconditions .checkArgument (bigPushDuration >= 0 , "bigPushDuration should be greater than 0." );
192+
135193 if (sendno <= 0 ) {
136194 sendno = ServiceHelper .generateSendno ();
137195 }
138-
139- return new Options (sendno , overrideMsgId , timeToLive , apnsProduction , bigPushDuration , apnsCollapseId );
196+
197+ return new Options (sendno , overrideMsgId , timeToLive , apnsProduction , bigPushDuration , apnsCollapseId , thirdPartyChannel );
140198 }
141199 }
142200
0 commit comments