1
1
package cn .jpush .api .push .model ;
2
2
3
3
4
- import com .google .gson .JsonElement ;
5
- import com .google .gson .JsonObject ;
6
- import com .google .gson .JsonPrimitive ;
4
+ import com .google .gson .*;
7
5
8
6
import cn .jiguang .common .ServiceHelper ;
9
7
import cn .jiguang .common .utils .Preconditions ;
10
8
9
+ import java .util .Map ;
10
+
11
11
public class Options implements PushModel {
12
+
12
13
private static final String SENDNO = "sendno" ;
13
14
private static final String OVERRIDE_MSG_ID = "override_msg_id" ;
14
15
private static final String TIME_TO_LIVE = "time_to_live" ;
15
16
private static final String APNS_PRODUCTION = "apns_production" ;
16
17
private static final String BIG_PUSH_DURATION = "big_push_duration" ;
17
18
private static final String APNS_COLLAPSE_ID = "apns_collapse_id" ;
18
-
19
+ private static final String THIRD_PARTH_CHANNEl = "third_party_channel" ;
20
+
19
21
private static final long NONE_TIME_TO_LIVE = -1 ;
20
-
22
+
21
23
private final int sendno ;
22
24
private final long overrideMsgId ;
23
25
private long timeToLive ;
24
26
private boolean apnsProduction ;
25
- private int bigPushDuration ; // minutes
27
+ // minutes
28
+ private int bigPushDuration ;
26
29
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 ) {
30
63
this .sendno = sendno ;
31
64
this .overrideMsgId = overrideMsgId ;
32
65
this .timeToLive = timeToLive ;
33
66
this .apnsProduction = apnsProduction ;
34
67
this .bigPushDuration = bigPushDuration ;
35
68
this .apnsCollapseId = apnsCollapseId ;
69
+ this .thirdPartyChannel = thirdPartyChannel ;
36
70
}
37
-
71
+
38
72
public static Builder newBuilder () {
39
73
return new Builder ();
40
74
}
41
-
75
+
42
76
public static Options sendno () {
43
77
return newBuilder ().setSendno (ServiceHelper .generateSendno ()).build ();
44
78
}
45
-
79
+
46
80
public static Options sendno (int sendno ) {
47
81
return newBuilder ().setSendno (sendno ).build ();
48
82
}
49
-
83
+
50
84
public void setApnsProduction (boolean apnsProduction ) {
51
85
this .apnsProduction = apnsProduction ;
52
86
}
53
-
87
+
54
88
public void setTimeToLive (long timeToLive ) {
55
89
this .timeToLive = timeToLive ;
56
90
}
57
-
91
+
58
92
public void setBigPushDuration (int bigPushDuration ) {
59
- this .bigPushDuration = bigPushDuration ;
93
+ this .bigPushDuration = bigPushDuration ;
60
94
}
61
-
95
+
62
96
public int getSendno () {
63
97
return this .sendno ;
64
98
}
65
-
99
+
66
100
@ Override
67
101
public JsonElement toJSON () {
68
102
JsonObject json = new JsonObject ();
@@ -75,43 +109,57 @@ public JsonElement toJSON() {
75
109
if (timeToLive >= 0 ) {
76
110
json .add (TIME_TO_LIVE , new JsonPrimitive (timeToLive ));
77
111
}
78
-
112
+
79
113
json .add (APNS_PRODUCTION , new JsonPrimitive (apnsProduction ));
80
-
114
+
81
115
if (bigPushDuration > 0 ) {
82
- json .add (BIG_PUSH_DURATION , new JsonPrimitive (bigPushDuration ));
116
+ json .add (BIG_PUSH_DURATION , new JsonPrimitive (bigPushDuration ));
83
117
}
84
118
85
119
if (apnsCollapseId != null ) {
86
120
json .add (APNS_COLLAPSE_ID , new JsonPrimitive (apnsCollapseId ));
87
121
}
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
+
89
135
return json ;
90
136
}
91
-
137
+
92
138
public static class Builder {
139
+
93
140
private int sendno = 0 ;
94
141
private long overrideMsgId = 0 ;
95
142
private long timeToLive = NONE_TIME_TO_LIVE ;
96
143
private boolean apnsProduction = false ;
97
144
private int bigPushDuration = 0 ;
98
145
private String apnsCollapseId ;
99
-
146
+ private Map <String , Map <String , String >> thirdPartyChannel ;
147
+
100
148
public Builder setSendno (int sendno ) {
101
149
this .sendno = sendno ;
102
150
return this ;
103
151
}
104
-
152
+
105
153
public Builder setOverrideMsgId (long overrideMsgId ) {
106
154
this .overrideMsgId = overrideMsgId ;
107
155
return this ;
108
156
}
109
-
157
+
110
158
public Builder setTimeToLive (long timeToLive ) {
111
159
this .timeToLive = timeToLive ;
112
160
return this ;
113
161
}
114
-
162
+
115
163
public Builder setApnsProduction (boolean apnsProduction ) {
116
164
this .apnsProduction = apnsProduction ;
117
165
return this ;
@@ -121,22 +169,32 @@ public Builder setApnsCollapseId(String id) {
121
169
this .apnsCollapseId = id ;
122
170
return this ;
123
171
}
124
-
172
+
125
173
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 ;
128
185
}
129
186
130
187
public Options build () {
131
188
Preconditions .checkArgument (sendno >= 0 , "sendno should be greater than 0." );
132
189
Preconditions .checkArgument (overrideMsgId >= 0 , "override_msg_id should be greater than 0." );
133
190
Preconditions .checkArgument (timeToLive >= NONE_TIME_TO_LIVE , "time_to_live should be greater than 0." );
134
191
Preconditions .checkArgument (bigPushDuration >= 0 , "bigPushDuration should be greater than 0." );
192
+
135
193
if (sendno <= 0 ) {
136
194
sendno = ServiceHelper .generateSendno ();
137
195
}
138
-
139
- return new Options (sendno , overrideMsgId , timeToLive , apnsProduction , bigPushDuration , apnsCollapseId );
196
+
197
+ return new Options (sendno , overrideMsgId , timeToLive , apnsProduction , bigPushDuration , apnsCollapseId , thirdPartyChannel );
140
198
}
141
199
}
142
200
0 commit comments