Skip to content

Commit f06be3f

Browse files
committed
v3.5.2
1 parent 0c8d1d8 commit f06be3f

File tree

18 files changed

+656
-102
lines changed

18 files changed

+656
-102
lines changed

README.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,8 @@
1515

1616
## 安装
1717

18-
### maven 方式
19-
将下边的依赖条件放到你项目的 maven pom.xml 文件里。v3.4.8 为例,最新版本请看[Release页面](https://github.com/jpush/jpush-api-java-client/releases)
20-
21-
```Java
22-
<dependency>
23-
<groupId>cn.jpush.api</groupId>
24-
<artifactId>jpush-client</artifactId>
25-
<version>3.4.8</version>
26-
</dependency>
27-
```
28-
### jar 包方式
29-
30-
请到 [Release页面](https://github.com/jpush/jpush-api-java-client/releases)下载相应版本的发布包。
31-
32-
3318
### 依赖包
34-
* [jiguang-java-client-common](https://github.com/jpush/jiguang-java-client-common) / 极光 Java client 的公共封装开发包,必须依赖,v1.1.10 为例,查看[最新版本](https://github.com/jpush/jiguang-java-client-common/releases)
19+
* [jiguang-java-client-common](https://github.com/jpush/jiguang-java-client-common) / 极光 Java client 的公共封装开发包,必须依赖,v1.1.11 为例,查看[最新版本](https://github.com/jpush/jiguang-java-client-common/releases)
3520
* [slf4j](http://www.slf4j.org/) / log4j (Logger)
3621
* [gson](https://code.google.com/p/google-gson/) (Google JSON Utils)
3722

@@ -43,7 +28,7 @@
4328
<dependency>
4429
<groupId>cn.jpush.api</groupId>
4530
<artifactId>jiguang-common</artifactId>
46-
<version>1.1.10</version>
31+
<version>1.1.11</version>
4732
</dependency>
4833
<dependency>
4934
<groupId>io.netty</groupId>

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

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import cn.jpush.api.push.model.audience.Audience;
1717
import cn.jpush.api.push.model.audience.AudienceTarget;
1818
import cn.jpush.api.push.model.notification.*;
19+
import cn.jpush.api.report.GroupMessageDetailResult;
1920
import com.google.gson.Gson;
2021
import com.google.gson.GsonBuilder;
2122
import com.google.gson.JsonObject;
@@ -31,7 +32,10 @@
3132
public class PushExample {
3233
protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class);
3334

34-
// demo App defined in resources/jpush-api.conf
35+
/**
36+
* Change the app key and master secret to your own account
37+
* If you want to use push by group, please enter your own group push key and group master secret.
38+
*/
3539
protected static final String APP_KEY = "8f02a4fa717a6235734d92de";
3640
protected static final String MASTER_SECRET = "cf6de29f9e66432ba4ac1c32";
3741
protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c";
@@ -56,6 +60,9 @@ public static void main(String[] args) {
5660

5761
// 目前推荐这个方法进行测试
5862
testSendPush();
63+
// testSendGroupPush();
64+
65+
5966
// testGetCidList();
6067
// testSendPushes();
6168
// testSendPush_fromJSON();
@@ -229,7 +236,7 @@ public void run() {
229236
}
230237
}
231238

232-
public void testSendGroupPush() {
239+
public static void testSendGroupPush() {
233240
GroupPushClient groupPushClient = new GroupPushClient(GROUP_MASTER_SECRET, GROUP_PUSH_KEY);
234241
final PushPayload payload = buildPushObject_android_and_ios();
235242
try {
@@ -239,9 +246,9 @@ public void testSendGroupPush() {
239246
PushResult pushResult = entry.getValue();
240247
PushResult.Error error = pushResult.error;
241248
if (error != null) {
242-
LOG.info("AppKey: " + entry.getKey() + " error code : " + error.getCode() + " error message: " + error.getMessage());
249+
LOG.info("Group_msgid: " + groupPushResult.getGroupMsgId() + " AppKey: " + entry.getKey() + " error code : " + error.getCode() + " error message: " + error.getMessage());
243250
} else {
244-
LOG.info("AppKey: " + entry.getKey() + " sendno: " + pushResult.sendno + " msg_id:" + pushResult.msg_id);
251+
LOG.info("Group_msgid: " + groupPushResult.getGroupMsgId() + " AppKey: " + entry.getKey() + " sendno: " + pushResult.sendno + " msg_id:" + pushResult.msg_id);
245252
}
246253

247254
}
@@ -279,6 +286,11 @@ public static PushPayload buildPushObject_android_tag_alertWithTitle() {
279286
.build();
280287
}
281288

289+
/**
290+
* Could modify the contents for pushing
291+
* The comments are showing how to use it
292+
* @return
293+
*/
282294
public static PushPayload buildPushObject_android_and_ios() {
283295
Map<String, String> extras = new HashMap<String, String>();
284296
extras.put("test", "https://community.jiguang.cn/push");
@@ -297,9 +309,6 @@ public static PushPayload buildPushObject_android_and_ios() {
297309
.addPlatformNotification(IosNotification.newBuilder()
298310
.incrBadge(1)
299311
.addExtra("extra_key", "extra_value").build())
300-
.addVoip("key", "value")
301-
.addVoip("key2", 2)
302-
.addVoip("key3", true)
303312
.build())
304313
// .setSMS(SMS.newBuilder()
305314
// .setDelayTime(1000)
@@ -450,6 +459,7 @@ public static PushPayload buildPushObject_android_cid() {
450459
list.add("1507ffd3f79545957de");
451460
list.add("1507ffd3f79457957de");
452461
list.add("1507ffd3f79456757de");
462+
list.add("zzzzzzzz");
453463

454464

455465
return PushPayload.newBuilder()
@@ -592,29 +602,29 @@ public static void testBatchSend() {
592602
LOG.info("batchSendPushByAlias param: {}, result: {}", pushPayloadList, new Gson().toJson(result.getBatchPushResult()));
593603
}
594604

595-
{
596-
List<PushPayload> pushPayloadList = new ArrayList<>();
597-
PushPayload.Builder builder1 = PushPayload.newBuilder();
598-
builder1.setMessage(Message.content("content1 by regId"))
599-
.setNotification(Notification.alert(ALERT))
600-
.setPlatform(Platform.android())
601-
.setAudience(Audience.all())
602-
.setOptions(Options.sendno())
603-
.setTarget("1507ffd3f79456757de");
604-
pushPayloadList.add(builder1.build());
605-
606-
PushPayload.Builder builder2 = PushPayload.newBuilder();
607-
builder2.setMessage(Message.content("content2 by regId"))
608-
.setNotification(Notification.alert(ALERT))
609-
.setAudience(Audience.all())
610-
.setPlatform(Platform.ios())
611-
.setOptions(Options.sendno())
612-
.setTarget("1507ffd3f79456757de");
613-
pushPayloadList.add(builder2.build());
614-
615-
BatchPushResult result = jPushClient.batchSendPushByRegId(pushPayloadList);
616-
LOG.info("batchSendPushByRegId param: {}, result: {}", pushPayloadList, new Gson().toJson(result.getBatchPushResult()));
617-
}
605+
// {
606+
// List<PushPayload> pushPayloadList = new ArrayList<>();
607+
// PushPayload.Builder builder1 = PushPayload.newBuilder();
608+
// builder1.setMessage(Message.content("content1 by regId"))
609+
// .setNotification(Notification.alert(ALERT))
610+
// .setPlatform(Platform.android())
611+
// .setAudience(Audience.all())
612+
// .setOptions(Options.sendno())
613+
// .setTarget("1507ffd3f79456757de");
614+
// pushPayloadList.add(builder1.build());
615+
//
616+
// PushPayload.Builder builder2 = PushPayload.newBuilder();
617+
// builder2.setMessage(Message.content("content2 by regId"))
618+
// .setNotification(Notification.alert(ALERT))
619+
// .setAudience(Audience.all())
620+
// .setPlatform(Platform.ios())
621+
// .setOptions(Options.sendno())
622+
// .setTarget("1507ffd3f79456757de");
623+
// pushPayloadList.add(builder2.build());
624+
//
625+
// BatchPushResult result = jPushClient.batchSendPushByRegId(pushPayloadList);
626+
// LOG.info("batchSendPushByRegId param: {}, result: {}", pushPayloadList, new Gson().toJson(result.getBatchPushResult()));
627+
// }
618628

619629
} catch (APIConnectionException e) {
620630
LOG.error("Connection error. Should retry later. ", e);

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

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,39 @@
1414
public class ReportsExample {
1515
protected static final Logger LOG = LoggerFactory.getLogger(ReportsExample.class);
1616

17-
// demo App defined in resources/jpush-api.conf
18-
private static final String appKey = "7b4b94cca0d185d611e53cca";
19-
private static final String masterSecret = "860803cf613ed54aa3b941a8";
17+
18+
/**
19+
* Change the app key and master secret to your own account
20+
* If you want to use push by group, please enter your own group push key and group master secret.
21+
*/
22+
protected static final String appKey = "8f02a4fa717a6235734d92de";
23+
protected static final String masterSecret = "cf6de29f9e66432ba4ac1c32";
24+
protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c";
25+
protected static final String GROUP_MASTER_SECRET = "b11314807507e2bcfdeebe2e";
26+
27+
2028
public static final String REGISTRATION_ID1 = "0900e8d85ef";
2129
public static final String REGISTRATION_ID2 = "0a04ad7d8b4";
2230
public static final String REGISTRATION_ID3 = "18071adc030dcba91c0";
2331

2432
public static void main(String[] args) {
2533

26-
// testGetReceivedsDetail();
27-
testGetMessagesDetail();
34+
// testGetReceivedDetail();
35+
// testGetMessagesDetail();
2836
// testGetReport();
2937
// testGetMessages();
3038
// testGetUsers();
31-
testGetMessageStatus();
39+
// testGetMessageStatus();
40+
testGetGroupMessagesDetail();
41+
// testGetGroupUsers();
3242
}
3343

3444

3545
public static void testGetReport() {
3646
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
3747
try {
38-
ReceivedsResult result = jpushClient.getReportReceiveds("1942377665");
39-
LOG.debug("Got result - " + result);
48+
ReceivedsResult result = jpushClient.getReportReceiveds("2252035206045707");
49+
LOG.info("Got result - " + result);
4050

4151
} catch (APIConnectionException e) {
4252
LOG.error("Connection error. Should retry later. ", e);
@@ -49,11 +59,15 @@ public static void testGetReport() {
4959
}
5060
}
5161

62+
/**
63+
* 用户统计
64+
* https://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#vip_2
65+
*/
5266
public static void testGetUsers() {
5367
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
5468
try {
5569
UsersResult result = jpushClient.getReportUsers(TimeUnit.DAY, "2014-06-10", 3);
56-
LOG.debug("Got result - " + result);
70+
LOG.info("Got result - " + result);
5771

5872
} catch (APIConnectionException e) {
5973
LOG.error("Connection error. Should retry later. ", e);
@@ -112,7 +126,8 @@ public static void testGetMessageStatus() {
112126
public static void testGetMessagesDetail() {
113127

114128
JPushClient jPushClient = new JPushClient(masterSecret, appKey);
115-
String msgIds = "3993287034,3993287035,3993287036";
129+
// String msgIds = "3993287034,3993287035,3993287036";
130+
String msgIds = "38280839685161019";
116131
try {
117132
MessageDetailResult result = jPushClient.getMessagesDetail(msgIds);
118133
LOG.info("msgIds: {}, MessageDetail: {}", msgIds, result.received_list);
@@ -131,7 +146,7 @@ public static void testGetMessagesDetail() {
131146
* 送达详情
132147
* https://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#_7
133148
*/
134-
public static void testGetReceivedsDetail() {
149+
public static void testGetReceivedDetail() {
135150

136151
JPushClient jPushClient = new JPushClient(masterSecret, appKey);
137152
String msgIds = "3993287034,3993287035,3993287036";
@@ -148,5 +163,48 @@ public static void testGetReceivedsDetail() {
148163
}
149164
}
150165

166+
/**
167+
* 分组统计-消息统计
168+
* https://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#-vip
169+
*/
170+
public static void testGetGroupMessagesDetail() {
171+
172+
JPushClient jPushClient = new JPushClient(GROUP_MASTER_SECRET, GROUP_PUSH_KEY);
173+
String groupMsgIds = "c4hmbne09s6bbaca91vg";
174+
try {
175+
GroupMessageDetailResult result = jPushClient.getGroupMessagesDetail(groupMsgIds);
176+
LOG.info("group_msgIds: {}, MessageDetail: {}", groupMsgIds, result.received_list);
177+
} catch (APIConnectionException e) {
178+
LOG.error("Connection error. Should retry later. ", e);
179+
} catch (APIRequestException e) {
180+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
181+
LOG.info("HTTP Status: " + e.getStatus());
182+
LOG.info("Error Code: " + e.getErrorCode());
183+
LOG.info("Error Message: " + e.getErrorMessage());
184+
}
185+
186+
}
187+
188+
/**
189+
* 分组统计-用户统计
190+
* https://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/#-vip_1
191+
*/
192+
public static void testGetGroupUsers() {
193+
JPushClient jpushClient = new JPushClient(GROUP_MASTER_SECRET, GROUP_PUSH_KEY);
194+
try {
195+
GroupUsersResult result = jpushClient.getGroupReportUsers(TimeUnit.DAY, "2021-08-21", 3);
196+
LOG.debug("Got result - " + result);
197+
198+
} catch (APIConnectionException e) {
199+
LOG.error("Connection error. Should retry later. ", e);
200+
201+
} catch (APIRequestException e) {
202+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
203+
LOG.info("HTTP Status: " + e.getStatus());
204+
LOG.info("Error Code: " + e.getErrorCode());
205+
LOG.info("Error Message: " + e.getErrorMessage());
206+
}
207+
}
208+
151209
}
152210

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,31 @@ public class ScheduleExample {
1919

2020
protected static final Logger LOG = LoggerFactory.getLogger(ScheduleExample.class);
2121

22+
23+
/**
24+
* Change it to your own appKey and masterSecret if you want to try the demo
25+
*/
2226
private static final String appKey ="7b4b94cca0d185d611e53cca";
2327
private static final String masterSecret = "860803cf613ed54aa3b941a8";
2428

2529

2630
public static void main(String[] args) {
27-
// testCreateSingleSchedule();
28-
// testCreateDailySchedule();
31+
testCreateSingleSchedule();
32+
// testCreateDailySchedule();
2933
// testDeleteSchedule();
3034
// testGetScheduleList();
3135
// testUpdateSchedule();
3236
// testGetSchedule();
33-
testGetScheduleMsgIds();
37+
// testGetScheduleMsgIds();
3438
}
3539

3640
public static void testCreateSingleSchedule() {
3741
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
3842
String name = "test_schedule_example";
39-
String time = "2018-10-14 10:48:25";
40-
PushPayload push = PushPayload.alertAll("test schedule example.");
43+
String time = "2021-08-11 15:36:10";
44+
PushPayload push = PushPayload.alertAll("test schedule example");
4145
try {
42-
ScheduleResult result = jpushClient.createSingleSchedule(name, time, push);
46+
ScheduleResult result = jpushClient.createSingleSchedule(name, time, push, masterSecret, appKey);
4347
LOG.info("schedule result is " + result);
4448
} catch (APIConnectionException e) {
4549
LOG.error("Connection error. Should retry later. ", e);
@@ -59,7 +63,7 @@ public static void testCreateDailySchedule() {
5963
String time = "14:00:00";
6064
PushPayload push = PushPayload.alertAll("test daily example.");
6165
try {
62-
ScheduleResult result = jPushClient.createDailySchedule(name, start, end, time, push);
66+
ScheduleResult result = jPushClient.createDailySchedule(name, start, end, time, push, masterSecret, appKey);
6367
LOG.info("schedule result is " + result);
6468
} catch (APIConnectionException e) {
6569
LOG.error("Connection error. Should retry later. ", e);
@@ -80,7 +84,7 @@ public static void testCreateWeeklySchedule() {
8084
Week[] days = {Week.MON, Week.FRI};
8185
PushPayload push = PushPayload.alertAll("test weekly example.");
8286
try {
83-
ScheduleResult result = jPushClient.createWeeklySchedule(name, start, end, time, days, push);
87+
ScheduleResult result = jPushClient.createWeeklySchedule(name, start, end, time, days, push, masterSecret, appKey);
8488
LOG.info("schedule result is " + result);
8589
} catch (APIConnectionException e) {
8690
LOG.error("Connection error. Should retry later. ", e);
@@ -101,7 +105,7 @@ public static void testCreateMonthlySchedule() {
101105
String[] points = {"01", "02"};
102106
PushPayload push = PushPayload.alertAll("test monthly example.");
103107
try {
104-
ScheduleResult result = jPushClient.createMonthlySchedule(name, start, end, time, points, push);
108+
ScheduleResult result = jPushClient.createMonthlySchedule(name, start, end, time, points, push, masterSecret, appKey);
105109
LOG.info("schedule result is " + result);
106110
} catch (APIConnectionException e) {
107111
LOG.error("Connection error. Should retry later.", e);

0 commit comments

Comments
 (0)