11package cn .jpush .api .examples ;
22
3- import cn .jpush .api .common .ClientConfig ;
4- import cn .jpush .api .push .model .*;
5- import cn .jpush .api .push .model .notification .IosAlert ;
6- import org .slf4j .Logger ;
7- import org .slf4j .LoggerFactory ;
8-
93import cn .jpush .api .JPushClient ;
4+ import cn .jpush .api .common .ClientConfig ;
105import cn .jpush .api .common .resp .APIConnectionException ;
116import cn .jpush .api .common .resp .APIRequestException ;
127import cn .jpush .api .push .PushResult ;
8+ import cn .jpush .api .push .model .*;
139import cn .jpush .api .push .model .audience .Audience ;
1410import cn .jpush .api .push .model .audience .AudienceTarget ;
1511import cn .jpush .api .push .model .notification .AndroidNotification ;
12+ import cn .jpush .api .push .model .notification .IosAlert ;
1613import cn .jpush .api .push .model .notification .IosNotification ;
1714import cn .jpush .api .push .model .notification .Notification ;
15+ import com .google .gson .JsonObject ;
16+ import org .slf4j .Logger ;
17+ import org .slf4j .LoggerFactory ;
1818
1919import java .util .HashMap ;
20+ import java .util .Map ;
2021
2122public class PushExample {
2223 protected static final Logger LOG = LoggerFactory .getLogger (PushExample .class );
@@ -33,7 +34,7 @@ public class PushExample {
3334
3435 public static void main (String [] args ) {
3536// testSendPushWithCustomConfig();
36- testSendIosAlert ();
37+ buildPushObject_with_extra ();
3738 }
3839
3940
@@ -95,6 +96,37 @@ public static PushPayload buildPushObject_android_and_ios() {
9596 .build ())
9697 .build ();
9798 }
99+
100+ public static void buildPushObject_with_extra () {
101+
102+ JsonObject jsonExtra = new JsonObject ();
103+ jsonExtra .addProperty ("extra1" , 1 );
104+ jsonExtra .addProperty ("extra2" , false );
105+
106+ Map <String , String > extras = new HashMap <String , String >();
107+ extras .put ("extra_1" , "val1" );
108+ extras .put ("extra_2" , "val2" );
109+
110+ PushPayload payload = PushPayload .newBuilder ()
111+ .setPlatform (Platform .android_ios ())
112+ .setAudience (Audience .tag ("tag1" ))
113+ .setNotification (Notification .newBuilder ()
114+ .setAlert ("alert content" )
115+ .addPlatformNotification (AndroidNotification .newBuilder ()
116+ .setTitle ("Android Title" )
117+ .addExtras (extras )
118+ .addExtra ("booleanExtra" , false )
119+ .addExtra ("numberExtra" , 1 )
120+ .addExtra ("jsonExtra" , jsonExtra )
121+ .build ())
122+ .addPlatformNotification (IosNotification .newBuilder ()
123+ .incrBadge (1 )
124+ .addExtra ("extra_key" , "extra_value" ).build ())
125+ .build ())
126+ .build ();
127+
128+ System .out .println (payload .toJSON ());
129+ }
98130
99131 public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage () {
100132 return PushPayload .newBuilder ()
0 commit comments