Skip to content

Commit 790b8ad

Browse files
committed
Update sample
1 parent 224d63a commit 790b8ad

File tree

3 files changed

+59
-16
lines changed

3 files changed

+59
-16
lines changed

example/main/java/cn/jpush/api/examples/PushExample.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.net.URI;
44
import java.net.URISyntaxException;
5+
import java.util.Collection;
56
import java.util.HashMap;
7+
import java.util.LinkedList;
68
import java.util.Map;
79

810
import cn.jiguang.common.ServiceHelper;
@@ -50,12 +52,12 @@ public class PushExample {
5052
public static void main(String[] args) {
5153
// testSendPushWithCustomConfig();
5254
// testSendIosAlert();
53-
// testSendPush();
55+
testSendPush();
5456
// testGetCidList();
5557
// testSendPushes();
5658
// testSendPush_fromJSON();
5759
// testSendPushWithCallback();
58-
testSendPushWithCid();
60+
// testSendPushWithCid();
5961
}
6062

6163
// 使用 NettyHttpClient 异步接口发送请求
@@ -81,10 +83,13 @@ public void onSucceed(ResponseWrapper responseWrapper) {
8183
public static void testSendPush() {
8284
ClientConfig clientConfig = ClientConfig.getInstance();
8385
final JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig);
86+
// String authCode = ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET);
8487
// Here you can use NativeHttpClient or NettyHttpClient or ApacheHttpClient.
8588
// Call setHttpClient to set httpClient,
8689
// If you don't invoke this method, default httpClient will use NativeHttpClient.
90+
8791
// ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, clientConfig);
92+
// NettyHttpClient httpClient =new NettyHttpClient(authCode, null, clientConfig);
8893
// jpushClient.getPushClient().setHttpClient(httpClient);
8994
final PushPayload payload = buildPushObject_android_and_ios();
9095
// // For push, all you need do is to build PushPayload object.
@@ -288,6 +293,7 @@ public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage()
288293
.addPlatformNotification(IosNotification.newBuilder()
289294
.setAlert(ALERT)
290295
.setBadge(5)
296+
.setMutableContent(false)
291297
.setSound("happy")
292298
.addExtra("from", "JPush")
293299
.build())
@@ -352,9 +358,20 @@ public static PushPayload buildPushObject_all_tag_not() {
352358
}
353359

354360
public static PushPayload buildPushObject_android_cid() {
361+
Collection<String> list =new LinkedList<String>();
362+
list.add("1507bfd3f79558957de");
363+
list.add("1507bfd3f79554957de");
364+
list.add("1507bfd3f79555957de");
365+
list.add("1507bfd3f79556957de");
366+
list.add("1507ffd3f79545957de");
367+
list.add("1507ffd3f79457957de");
368+
list.add("1507ffd3f79456757de");
369+
370+
355371
return PushPayload.newBuilder()
356372
.setPlatform(Platform.android())
357-
.setAudience(Audience.registrationId("1507bfd3f79558957de"))
373+
// .setAudience(Audience.registrationId("1507bfd3f79558957de"))
374+
.setAudience(Audience.registrationId(list))
358375
.setNotification(Notification.alert(ALERT))
359376
.setCid("cid")
360377
.build();
@@ -409,7 +426,12 @@ public static void testSendIosAlert() {
409426
public static void testSendWithSMS() {
410427
JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY);
411428
try {
412-
SMS sms = SMS.content(1, 10);
429+
// SMS sms = SMS.content(1, 10);
430+
SMS sms = SMS.newBuilder()
431+
.setDelayTime(1000)
432+
.setTempID(2000)
433+
.addPara("Test", 1)
434+
.build();
413435
PushResult result = jpushClient.sendAndroidMessageWithAlias("Test SMS", "test sms", sms, "alias1");
414436
LOG.info("Got result - " + result);
415437
} catch (APIConnectionException e) {

example/main/java/cn/jpush/api/examples/ReportsExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class ReportsExample {
2626
public static final String REGISTRATION_ID3 = "18071adc030dcba91c0";
2727

2828
public static void main(String[] args) {
29-
testGetReport();
30-
testGetMessages();
31-
testGetUsers();
29+
// testGetReport();
30+
// testGetMessages();
31+
// testGetUsers();
3232
testGetMessageStatus();
3333
}
3434

example/main/java/cn/jpush/api/examples/ScheduleExample.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import cn.jpush.api.JPushClient;
1111
import cn.jpush.api.push.model.PushPayload;
1212
import cn.jpush.api.schedule.ScheduleListResult;
13+
import cn.jpush.api.schedule.ScheduleMsgIdsResult;
1314
import cn.jpush.api.schedule.ScheduleResult;
1415
import cn.jpush.api.schedule.model.SchedulePayload;
1516
import cn.jpush.api.schedule.model.TriggerPayload;
@@ -18,21 +19,24 @@ public class ScheduleExample {
1819

1920
protected static final Logger LOG = LoggerFactory.getLogger(ScheduleExample.class);
2021

21-
private static final String appKey ="dd1066407b044738b6479275";
22-
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";
22+
private static final String appKey ="7b4b94cca0d185d611e53cca";
23+
private static final String masterSecret = "860803cf613ed54aa3b941a8";
2324

24-
public static void main(String[] args) {
2525

26+
public static void main(String[] args) {
27+
// testCreateSingleSchedule();
28+
// testCreateDailySchedule();
2629
// testDeleteSchedule();
27-
testGetScheduleList();
30+
// testGetScheduleList();
2831
// testUpdateSchedule();
29-
testGetSchedule();
32+
// testGetSchedule();
33+
testGetScheduleMsgIds();
3034
}
3135

3236
public static void testCreateSingleSchedule() {
3337
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
3438
String name = "test_schedule_example";
35-
String time = "2016-07-30 12:30:25";
39+
String time = "2018-10-14 10:48:25";
3640
PushPayload push = PushPayload.alertAll("test schedule example.");
3741
try {
3842
ScheduleResult result = jpushClient.createSingleSchedule(name, time, push);
@@ -50,8 +54,8 @@ public static void testCreateSingleSchedule() {
5054
public static void testCreateDailySchedule() {
5155
JPushClient jPushClient = new JPushClient(masterSecret, appKey);
5256
String name = "test_daily_schedule";
53-
String start = "2015-08-06 12:16:13";
54-
String end = "2115-08-06 12:16:13";
57+
String start = "2019-08-06 12:16:13";
58+
String end = "2020-08-06 12:16:13";
5559
String time = "14:00:00";
5660
PushPayload push = PushPayload.alertAll("test daily example.");
5761
try {
@@ -171,7 +175,7 @@ public static void testUpdateSchedule() {
171175
}
172176

173177
public static void testGetSchedule() {
174-
String scheduleId = "95bbd066-3a88-11e5-8e62-0021f652c102";
178+
String scheduleId = "13573bfa-cf5a-11e8-bd7f-0021f6b55802";
175179
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
176180

177181
try {
@@ -186,6 +190,23 @@ public static void testGetSchedule() {
186190
LOG.info("Error Message: " + e.getErrorMessage());
187191
}
188192
}
193+
194+
public static void testGetScheduleMsgIds() {
195+
String scheduleId = "63db10a0-cf5b-11e8-ac2f-0021f6b55802";
196+
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
197+
198+
try {
199+
ScheduleMsgIdsResult result = jpushClient.getScheduleMsgIds(scheduleId);
200+
LOG.info("scheduleMsgIds :" + result);
201+
} catch (APIConnectionException e) {
202+
LOG.error("Connection error. Should retry later. ", e);
203+
} catch (APIRequestException e) {
204+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
205+
LOG.info("HTTP Status: " + e.getStatus());
206+
LOG.info("Error Code: " + e.getErrorCode());
207+
LOG.info("Error Message: " + e.getErrorMessage());
208+
}
209+
}
189210

190211

191212
}

0 commit comments

Comments
 (0)