66import cn .jiguang .common .ServiceHelper ;
77import cn .jiguang .common .utils .Preconditions ;
88
9+ import java .util .HashMap ;
910import java .util .LinkedHashMap ;
1011import java .util .Map ;
12+ import java .util .Set ;
1113
1214public class Options implements PushModel {
1315
@@ -32,37 +34,42 @@ public class Options implements PushModel {
3234
3335
3436 /**
35- * example
36- * "third_party_channel": {
37- * "xiaomi": {
38- * "distribution": "ospush"
39- * },
40- * "huawei": {
41- * "distribution": "jpush"
42- * },
43- * "meizu": {
44- * "distribution": "jpush"
45- * },
46- * "fcm": {
47- * "distribution": "ospush"
48- * },
49- * "oppo": {
50- * "distribution": "ospush"
51- * },
52- * "vivo": {
53- * "distribution": "ospush"
37+ * {
38+ * "third_party_channel":{
39+ * "xiaomi":{
40+ * "distribution":"ospush",
41+ * "channel_id":"*******"
42+ * },
43+ * "huawei":{
44+ * "distribution":"jpush"
45+ * },
46+ * "meizu":{
47+ * "distribution":"jpush"
48+ * },
49+ * "fcm":{
50+ * "distribution":"ospush"
51+ * },
52+ * "oppo":{
53+ * "distribution":"ospush",
54+ * "channel_id":"*******"
55+ * },
56+ * "vivo":{
57+ * "distribution":"ospush",
58+ * "classification":0 // 2020/06 新增,和vivo官方字段含义一致 0 代表运营消息,1 代表系统消息,不填vivo官方默认为0
59+ * // 使用此字段时,需使用setThirdPartyChannelV2方法,因为此值只能为整数形式
60+ * }
5461 * }
5562 * }
5663 */
57- private Map <String , Map < String , String > > thirdPartyChannel ;
64+ private Map <String , JsonObject > thirdPartyChannel ;
5865
5966 private Options (int sendno ,
6067 long overrideMsgId ,
6168 long timeToLive ,
6269 boolean apnsProduction ,
6370 int bigPushDuration ,
6471 String apnsCollapseId ,
65- Map <String , Map < String , String > > thirdPartyChannel ,
72+ Map <String , JsonObject > thirdPartyChannel ,
6673 Map <String , JsonPrimitive > customData ) {
6774 this .sendno = sendno ;
6875 this .overrideMsgId = overrideMsgId ;
@@ -127,11 +134,8 @@ public JsonElement toJSON() {
127134
128135 if (null != thirdPartyChannel && thirdPartyChannel .size () > 0 ) {
129136 JsonObject partyChannel = new JsonObject ();
130- for (Map .Entry <String , Map <String , String >> entry : thirdPartyChannel .entrySet ()) {
131- JsonObject channel = new JsonObject ();
132- for (Map .Entry <String , String > stringEntry : entry .getValue ().entrySet ()) {
133- channel .addProperty (stringEntry .getKey (), stringEntry .getValue ());
134- }
137+ for (Map .Entry <String , JsonObject > entry : thirdPartyChannel .entrySet ()) {
138+ JsonObject channel = entry .getValue ();
135139 partyChannel .add (entry .getKey (), channel );
136140 }
137141 json .add (THIRD_PARTH_CHANNEl , partyChannel );
@@ -154,7 +158,7 @@ public static class Builder {
154158 private boolean apnsProduction = false ;
155159 private int bigPushDuration = 0 ;
156160 private String apnsCollapseId ;
157- private Map <String , Map < String , String > > thirdPartyChannel ;
161+ private Map <String , JsonObject > thirdPartyChannel ;
158162 private Map <String , JsonPrimitive > customData ;
159163
160164 public Builder setSendno (int sendno ) {
@@ -187,11 +191,48 @@ public Builder setBigPushDuration(int bigPushDuration) {
187191 return this ;
188192 }
189193
194+ @ Deprecated
190195 public Map <String , Map <String , String >> getThirdPartyChannel () {
191- return thirdPartyChannel ;
196+ if (null != thirdPartyChannel ) {
197+ Map <String , Map <String , String >> thirdPartyChannelRsp = new HashMap <>();
198+ Set <Map .Entry <String , JsonObject >> entrySet = thirdPartyChannel .entrySet ();
199+ for (Map .Entry <String , JsonObject > entry : entrySet ) {
200+ JsonObject entryValue = entry .getValue ();
201+ Set <Map .Entry <String , JsonElement >> valueEntrySet = entryValue .entrySet ();
202+ Map <String , String > valueMap = new HashMap <>();
203+ for (Map .Entry <String , JsonElement > valueEntry : valueEntrySet ) {
204+ valueMap .put (valueEntry .getKey (), null == valueEntry .getValue () ? null : valueEntry .getValue ().getAsString ());
205+ }
206+ thirdPartyChannelRsp .put (entry .getKey (), valueMap );
207+ }
208+ return thirdPartyChannelRsp ;
209+ }
210+ return null ;
192211 }
193212
213+ @ Deprecated
194214 public Builder setThirdPartyChannel (Map <String , Map <String , String >> thirdPartyChannel ) {
215+ this .thirdPartyChannel = new HashMap <>();
216+ if (null != thirdPartyChannel ) {
217+ Set <Map .Entry <String , Map <String , String >>> entrySet = thirdPartyChannel .entrySet ();
218+ for (Map .Entry <String , Map <String , String >> entry : entrySet ) {
219+ String key = entry .getKey ();
220+ Map <String , String > valueMap = entry .getValue ();
221+ JsonObject valueObj = new JsonObject ();
222+ if (null != valueMap ) {
223+ Set <Map .Entry <String , String >> valueEntrySet = valueMap .entrySet ();
224+ for (Map .Entry <String , String > valueEntry : valueEntrySet ) {
225+ valueObj .addProperty (valueEntry .getKey (), valueEntry .getValue ());
226+ }
227+ this .thirdPartyChannel .put (key , valueObj );
228+ }
229+ }
230+
231+ }
232+ return this ;
233+ }
234+
235+ public Builder setThirdPartyChannelV2 (Map <String , JsonObject > thirdPartyChannel ) {
195236 this .thirdPartyChannel = thirdPartyChannel ;
196237 return this ;
197238 }
0 commit comments