6
6
import cn .jiguang .common .ServiceHelper ;
7
7
import cn .jiguang .common .utils .Preconditions ;
8
8
9
+ import java .util .HashMap ;
9
10
import java .util .LinkedHashMap ;
10
11
import java .util .Map ;
12
+ import java .util .Set ;
11
13
12
14
public class Options implements PushModel {
13
15
@@ -32,37 +34,42 @@ public class Options implements PushModel {
32
34
33
35
34
36
/**
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
+ * }
54
61
* }
55
62
* }
56
63
*/
57
- private Map <String , Map < String , String > > thirdPartyChannel ;
64
+ private Map <String , JsonObject > thirdPartyChannel ;
58
65
59
66
private Options (int sendno ,
60
67
long overrideMsgId ,
61
68
long timeToLive ,
62
69
boolean apnsProduction ,
63
70
int bigPushDuration ,
64
71
String apnsCollapseId ,
65
- Map <String , Map < String , String > > thirdPartyChannel ,
72
+ Map <String , JsonObject > thirdPartyChannel ,
66
73
Map <String , JsonPrimitive > customData ) {
67
74
this .sendno = sendno ;
68
75
this .overrideMsgId = overrideMsgId ;
@@ -127,11 +134,8 @@ public JsonElement toJSON() {
127
134
128
135
if (null != thirdPartyChannel && thirdPartyChannel .size () > 0 ) {
129
136
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 ();
135
139
partyChannel .add (entry .getKey (), channel );
136
140
}
137
141
json .add (THIRD_PARTH_CHANNEl , partyChannel );
@@ -154,7 +158,7 @@ public static class Builder {
154
158
private boolean apnsProduction = false ;
155
159
private int bigPushDuration = 0 ;
156
160
private String apnsCollapseId ;
157
- private Map <String , Map < String , String > > thirdPartyChannel ;
161
+ private Map <String , JsonObject > thirdPartyChannel ;
158
162
private Map <String , JsonPrimitive > customData ;
159
163
160
164
public Builder setSendno (int sendno ) {
@@ -187,11 +191,48 @@ public Builder setBigPushDuration(int bigPushDuration) {
187
191
return this ;
188
192
}
189
193
194
+ @ Deprecated
190
195
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 ;
192
211
}
193
212
213
+ @ Deprecated
194
214
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 ) {
195
236
this .thirdPartyChannel = thirdPartyChannel ;
196
237
return this ;
197
238
}
0 commit comments