1414import cn .jpush .api .push .model .notification .Notification ;
1515import cn .jpush .api .push .model .notification .PlatformNotification ;
1616
17+ import java .util .LinkedHashMap ;
18+ import java .util .Map ;
19+
1720/**
1821 * The object you should build for sending a push.
1922 *
@@ -54,9 +57,10 @@ public class PushPayload implements PushModel {
5457 private SMS sms ;
5558 private String cid ;
5659 private String target ;
60+ protected Map <String , JsonObject > custom ;
5761
5862 private PushPayload (Platform platform , Audience audience ,
59- Notification notification , Message message , Options options , SMS sms , String cid , String target ) {
63+ Notification notification , Message message , Options options , SMS sms , String cid , String target , Map < String , JsonObject > custom ) {
6064 this .platform = platform ;
6165 this .audience = audience ;
6266 this .notification = notification ;
@@ -65,6 +69,7 @@ private PushPayload(Platform platform, Audience audience,
6569 this .sms = sms ;
6670 this .cid = cid ;
6771 this .target = target ;
72+ this .custom = custom ;
6873 }
6974
7075 public PushPayload setCid (String cid ) {
@@ -192,6 +197,11 @@ public JsonElement toJSON() {
192197 if (null != target ) {
193198 json .addProperty (TARGET , target );
194199 }
200+ if (null != custom ) {
201+ for (Map .Entry <String , JsonObject > entry : custom .entrySet ()) {
202+ json .add (entry .getKey (), entry .getValue ());
203+ }
204+ }
195205
196206 return json ;
197207 }
@@ -252,6 +262,11 @@ public static class Builder {
252262 private SMS sms = null ;
253263 private String cid ;
254264 private String target ;
265+ private Map <String , JsonObject > custom ;
266+
267+ public Builder () {
268+ this .custom = new LinkedHashMap <>();
269+ }
255270
256271 public Builder setTarget (String target ) {
257272 this .target = target ;
@@ -293,6 +308,11 @@ public Builder setCid(String cid) {
293308 return this ;
294309 }
295310
311+ public Builder addCustom (String field , JsonObject jsonObject ) {
312+ this .custom .put (field , jsonObject );
313+ return this ;
314+ }
315+
296316 public PushPayload build () {
297317
298318 if (StringUtils .isTrimedEmpty (target )) {
@@ -312,7 +332,7 @@ public PushPayload build() {
312332 options = Options .sendno ();
313333 }
314334
315- return new PushPayload (platform , audience , notification , message , options , sms , cid , target );
335+ return new PushPayload (platform , audience , notification , message , options , sms , cid , target , custom );
316336 }
317337 }
318338}
0 commit comments