Skip to content

Commit 11fde7e

Browse files
authored
Merge pull request #122 from jpush/dev
Dev
2 parents 2e81f21 + ff4c3cd commit 11fde7e

File tree

11 files changed

+169
-25
lines changed

11 files changed

+169
-25
lines changed

.classpath

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
1111
<attributes>
1212
<attribute name="maven.pomderived" value="true"/>
13+
<attribute name="test" value="true"/>
1314
</attributes>
1415
</classpathentry>
1516
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
@@ -21,6 +22,7 @@
2122
<attributes>
2223
<attribute name="optional" value="true"/>
2324
<attribute name="maven.pomderived" value="true"/>
25+
<attribute name="test" value="true"/>
2426
</attributes>
2527
</classpathentry>
2628
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
@@ -29,7 +31,7 @@
2931
<attribute name="maven.pomderived" value="true"/>
3032
</attributes>
3133
</classpathentry>
32-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
34+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
3335
<attributes>
3436
<attribute name="maven.pomderived" value="true"/>
3537
</attributes>
@@ -38,5 +40,22 @@
3840
<classpathentry kind="lib" path="libs/slf4j-log4j12-1.7.7.jar"/>
3941
<classpathentry kind="lib" path="libs/slf4j-api-1.7.7.jar"/>
4042
<classpathentry kind="lib" path="libs/gson-2.2.4.jar"/>
43+
<classpathentry kind="src" path="target/generated-sources/annotations">
44+
<attributes>
45+
<attribute name="optional" value="true"/>
46+
<attribute name="maven.pomderived" value="true"/>
47+
<attribute name="ignore_optional_problems" value="true"/>
48+
<attribute name="m2e-apt" value="true"/>
49+
</attributes>
50+
</classpathentry>
51+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
52+
<attributes>
53+
<attribute name="optional" value="true"/>
54+
<attribute name="maven.pomderived" value="true"/>
55+
<attribute name="ignore_optional_problems" value="true"/>
56+
<attribute name="m2e-apt" value="true"/>
57+
<attribute name="test" value="true"/>
58+
</attributes>
59+
</classpathentry>
4160
<classpathentry kind="output" path="target/classes"/>
4261
</classpath>

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<dependency>
2525
<groupId>cn.jpush.api</groupId>
2626
<artifactId>jpush-client</artifactId>
27-
<version>3.3.7</version>
27+
<version>3.3.8</version>
2828
</dependency>
2929
```
3030
### jar 包方式
@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>cn.jpush.api</groupId>
4646
<artifactId>jiguang-common</artifactId>
47-
<version>1.1.1</version>
47+
<version>1.1.3</version>
4848
</dependency>
4949
<dependency>
5050
<groupId>io.netty</groupId>
@@ -230,7 +230,11 @@ try {
230230
public static void testSendWithSMS() {
231231
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
232232
try {
233-
SMS sms = SMS.content("Test SMS", 10);
233+
SMS sms = SMS.newBuilder()
234+
.setDelayTime(1000)
235+
.setTempID(2000)
236+
.addPara("Test", 1)
237+
.build();
234238
PushResult result = jpushClient.sendAndroidMessageWithAlias("Test SMS", "test sms", sms, "alias1");
235239
LOG.info("Got result - " + result);
236240
} catch (APIConnectionException e) {

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cn.jpush.api.examples;
22

3+
import java.util.HashSet;
34
import java.util.Map;
45

56
import org.slf4j.Logger;
@@ -15,19 +16,37 @@
1516
public class DeviceExample {
1617
protected static final Logger LOG = LoggerFactory.getLogger(DeviceExample.class);
1718

18-
private static final String appKey = "dd1066407b044738b6479275";
19-
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";
19+
private static final String appKey = "7b4b94cca0d185d611e53cca";
20+
private static final String masterSecret = "860803cf613ed54aa3b941a8";
2021
private static final String TAG1 = "tag1";
2122
private static final String ALIAS1 = "alias1";
2223
private static final String ALIAS2 = "alias2";
23-
private static final String REGISTRATION_ID1 = "0900e8d85ef";
24+
private static final String REGISTRATION_ID1 = "160a3797c856951a397";
2425
private static final String REGISTRATION_ID2 = "0a04ad7d8b4";
2526

2627
private static JPushClient jpushClient = new JPushClient(masterSecret, appKey);
2728

2829
public static void main(String[] args) {
29-
testGetDeviceTagAlias();
30+
// testGetDeviceTagAlias();
3031
// testGetUserOnlineStatus();
32+
testUpdateDeviceTagAlias();
33+
}
34+
35+
public static void testUpdateDeviceTagAlias() {
36+
HashSet<String> tagSet = new HashSet<String>();
37+
tagSet.add("hhh");
38+
try {
39+
DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID1, null, tagSet, null);
40+
LOG.info("Got result " + result);
41+
} catch (APIConnectionException e) {
42+
LOG.error("Connection error. Should retry later. ", e);
43+
44+
} catch (APIRequestException e) {
45+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
46+
LOG.info("HTTP Status: " + e.getStatus());
47+
LOG.info("Error Code: " + e.getErrorCode());
48+
LOG.info("Error Message: " + e.getErrorMessage());
49+
}
3150
}
3251

3352
public static void testGetDeviceTagAlias() {

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

Lines changed: 25 additions & 2 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;
@@ -55,6 +57,7 @@ public static void main(String[] args) {
5557
// testSendPushes();
5658
// testSendPush_fromJSON();
5759
// testSendPushWithCallback();
60+
// testSendPushWithCid();
5861
}
5962

6063
// 使用 NettyHttpClient 异步接口发送请求
@@ -80,10 +83,13 @@ public void onSucceed(ResponseWrapper responseWrapper) {
8083
public static void testSendPush() {
8184
ClientConfig clientConfig = ClientConfig.getInstance();
8285
final JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig);
86+
// String authCode = ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET);
8387
// Here you can use NativeHttpClient or NettyHttpClient or ApacheHttpClient.
8488
// Call setHttpClient to set httpClient,
8589
// If you don't invoke this method, default httpClient will use NativeHttpClient.
90+
8691
// ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, clientConfig);
92+
// NettyHttpClient httpClient =new NettyHttpClient(authCode, null, clientConfig);
8793
// jpushClient.getPushClient().setHttpClient(httpClient);
8894
final PushPayload payload = buildPushObject_android_and_ios();
8995
// // For push, all you need do is to build PushPayload object.
@@ -287,6 +293,7 @@ public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage()
287293
.addPlatformNotification(IosNotification.newBuilder()
288294
.setAlert(ALERT)
289295
.setBadge(5)
296+
.setMutableContent(false)
290297
.setSound("happy")
291298
.addExtra("from", "JPush")
292299
.build())
@@ -351,9 +358,20 @@ public static PushPayload buildPushObject_all_tag_not() {
351358
}
352359

353360
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+
354371
return PushPayload.newBuilder()
355372
.setPlatform(Platform.android())
356-
.setAudience(Audience.registrationId("18071adc030dcba91c0"))
373+
// .setAudience(Audience.registrationId("1507bfd3f79558957de"))
374+
.setAudience(Audience.registrationId(list))
357375
.setNotification(Notification.alert(ALERT))
358376
.setCid("cid")
359377
.build();
@@ -408,7 +426,12 @@ public static void testSendIosAlert() {
408426
public static void testSendWithSMS() {
409427
JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY);
410428
try {
411-
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();
412435
PushResult result = jpushClient.sendAndroidMessageWithAlias("Test SMS", "test sms", sms, "alias1");
413436
LOG.info("Got result - " + result);
414437
} 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
}

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>cn.jpush.api</groupId>
55
<artifactId>jpush-client</artifactId>
6-
<version>3.3.8-SNAPSHOT</version>
6+
<version>3.3.9-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<url>https://github.com/jpush/jpush-api-java-client</url>
99
<name>JPush API Java Client</name>
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>cn.jpush.api</groupId>
4444
<artifactId>jiguang-common</artifactId>
45-
<version>1.1.1</version>
45+
<version>1.1.3</version>
4646
</dependency>
4747
<dependency>
4848
<groupId>org.apache.httpcomponents</groupId>

src/main/java/cn/jpush/api/JPushClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import cn.jpush.api.push.model.notification.Notification;
3434
import cn.jpush.api.schedule.ScheduleClient;
3535
import cn.jpush.api.schedule.ScheduleListResult;
36+
import cn.jpush.api.schedule.ScheduleMsgIdsResult;
3637
import cn.jpush.api.schedule.ScheduleResult;
3738
import cn.jpush.api.schedule.model.SchedulePayload;
3839
import cn.jpush.api.schedule.model.TriggerPayload;
@@ -1053,6 +1054,18 @@ public ScheduleResult getSchedule(String scheduleId)
10531054
throws APIConnectionException, APIRequestException {
10541055
return _scheduleClient.getSchedule(scheduleId);
10551056
}
1057+
1058+
/**
1059+
* Get the message id by the schedule id.
1060+
* @param scheduleId The schedule id.
1061+
* @return The message id list.
1062+
* @throws APIConnectionException if a remote or network exception occurs.
1063+
* @throws APIRequestException if a request exception occurs.
1064+
*/
1065+
public ScheduleMsgIdsResult getScheduleMsgIds(String scheduleId)
1066+
throws APIConnectionException, APIRequestException {
1067+
return _scheduleClient.getScheduleMsgIds(scheduleId);
1068+
}
10561069

10571070
/**
10581071
* Get the schedule list size and the first page.

src/main/java/cn/jpush/api/device/DeviceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public DefaultResult bindMobile(String registrationId, String mobile)
154154
// delete bind while mobile is empty.
155155
mobile = "";
156156
} else {
157-
Preconditions.checkArgument(StringUtils.isMobileNumber(mobile), "The mobile format is incorrect. " + mobile);
157+
// Preconditions.checkArgument(StringUtils.isMobileNumber(mobile), "The mobile format is incorrect. " + mobile);
158158
}
159159

160160
String url = hostName + devicesPath + "/" + registrationId;

src/main/java/cn/jpush/api/schedule/ScheduleClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ public ScheduleResult getSchedule(String scheduleId) throws APIConnectionExcepti
118118
ResponseWrapper response = _httpClient.sendGet(hostName + schedulePath + "/" + scheduleId);
119119
return ScheduleResult.fromResponse(response, ScheduleResult.class);
120120
}
121+
122+
public ScheduleMsgIdsResult getScheduleMsgIds(String scheduleId) throws APIConnectionException, APIRequestException{
123+
124+
Preconditions.checkArgument(StringUtils.isNotEmpty(scheduleId), "scheduleId should not be empty");
125+
126+
ResponseWrapper response = _httpClient.sendGet(hostName + schedulePath + "/" + scheduleId + "/msg_ids");
127+
return ScheduleResult.fromResponse(response, ScheduleMsgIdsResult.class);
128+
}
121129

122130
public ScheduleResult updateSchedule(String scheduleId, SchedulePayload payload) throws APIConnectionException, APIRequestException{
123131

0 commit comments

Comments
 (0)