55
66import cn .jpush .api .JPushClient ;
77import cn .jpush .api .push .PushResult ;
8+ import cn .jpush .api .push .model .Platform ;
89import cn .jpush .api .push .model .PushPayload ;
10+ import cn .jpush .api .push .model .audience .Audience ;
11+ import cn .jpush .api .push .model .notification .AndroidNotification ;
12+ import cn .jpush .api .push .model .notification .Notification ;
913import cn .jpush .api .report .ReceivedsResult ;
1014
1115public class JPushClientExample {
@@ -21,14 +25,13 @@ public class JPushClientExample {
2125 public static final String TAG = "tag_api" ;
2226
2327 public static void main (String [] args ) {
24- testSendNotification ();
25- // testSendMesasge();
28+ testSendPush ();
2629 testGetReport ();
2730 }
2831
29- private static void testSendNotification () {
32+ private static void testSendPush () {
3033 JPushClient jpushClient = new JPushClient (masterSecret , appKey );
31- PushPayload payload = PushPayload . alertAll ( CONTENT );
34+ PushPayload payload = buildPushObject_all_all_alert ( );
3235 LOG .info ("Paylaod JSON - " + payload .toString ());
3336
3437 PushResult result = jpushClient .sendPush (payload );
@@ -43,12 +46,32 @@ private static void testSendNotification() {
4346 }
4447 }
4548
46- private static void testSendMesasge () {
47- JPushClient jpushClient = new JPushClient (masterSecret , appKey );
48- PushPayload payload = PushPayload .messageAll (CONTENT );
49- jpushClient .sendPush (payload );
49+ public static PushPayload buildPushObject_all_all_alert () {
50+ return PushPayload .alertAll (CONTENT );
51+ }
52+
53+ public static PushPayload buildPushObject_all_alias_alert () {
54+ return PushPayload .newBuilder ()
55+ .setPlatform (Platform .all ())
56+ .setAudience (Audience .alias ("alias1" ))
57+ .setNotification (Notification .alert (CONTENT ))
58+ .build ();
5059 }
5160
61+ public static PushPayload buildPushObject_android_tag_alertWithTitle () {
62+ return PushPayload .newBuilder ()
63+ .setPlatform (Platform .android ())
64+ .setAudience (Audience .tag ("tag1" ))
65+ .setNotification (Notification .newBuilder ()
66+ .addPlatformNotification (AndroidNotification .newBuilder ()
67+ .setAlert (CONTENT )
68+ .setTitle (TITLE )
69+ .build ())
70+ .build ())
71+ .build ();
72+ }
73+
74+
5275 public static void testGetReport () {
5376 JPushClient jpushClient = new JPushClient (masterSecret , appKey );
5477 ReceivedsResult receivedsResult = jpushClient .getReportReceiveds ("1708010723,1774452771" );
0 commit comments