Skip to content

Commit 9821eec

Browse files
committed
Merge pull request #22 from jpush/dev
merge version 3.2.6
2 parents 7aedcb5 + bcb31bf commit 9821eec

28 files changed

+1668
-129
lines changed

README.md

Lines changed: 71 additions & 52 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.2.5</version>
27+
<version>3.2.6</version>
2828
</dependency>
2929
```
3030
### jar 包方式
@@ -87,27 +87,26 @@
8787
> 以下片断来自项目代码里的文件:example / cn.jpush.api.examples.PushExample
8888
8989
```Java
90-
JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
91-
92-
// For push, all you need do is to build PushPayload object.
93-
PushPayload payload = buildPushObject_all_all_alert();
94-
95-
try {
96-
PushResult result = jpushClient.sendPush(payload);
97-
LOG.info("Got result - " + result);
98-
99-
} catch (APIConnectionException e) {
100-
// Connection error, should retry later
101-
LOG.error("Connection error, should retry later", e);
102-
103-
} catch (APIRequestException e) {
104-
// Should review the error, and fix the request
105-
LOG.error("Should review the error, and fix the request", e);
106-
LOG.info("HTTP Status: " + e.getStatus());
107-
LOG.info("Error Code: " + e.getErrorCode());
108-
LOG.info("Error Message: " + e.getErrorMessage());
109-
}
90+
JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
11091

92+
// For push, all you need do is to build PushPayload object.
93+
PushPayload payload = buildPushObject_all_all_alert();
94+
95+
try {
96+
PushResult result = jpushClient.sendPush(payload);
97+
LOG.info("Got result - " + result);
98+
99+
} catch (APIConnectionException e) {
100+
// Connection error, should retry later
101+
LOG.error("Connection error, should retry later", e);
102+
103+
} catch (APIRequestException e) {
104+
// Should review the error, and fix the request
105+
LOG.error("Should review the error, and fix the request", e);
106+
LOG.info("HTTP Status: " + e.getStatus());
107+
LOG.info("Error Code: " + e.getErrorCode());
108+
LOG.info("Error Message: " + e.getErrorMessage());
109+
}
111110
```
112111

113112
进行推送的关键在于构建一个 PushPayload 对象。以下示例一般的构建对象的用法。
@@ -190,42 +189,62 @@
190189
> 以下片断来自项目代码里的文件:example / cn.jpush.api.examples.ReportsExample
191190
192191
```Java
193-
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
194-
try {
195-
ReceivedsResult result = jpushClient.getReportReceiveds("1942377665");
196-
LOG.debug("Got result - " + result);
197-
198-
} catch (APIConnectionException e) {
199-
// Connection error, should retry later
200-
LOG.error("Connection error, should retry later", e);
201-
202-
} catch (APIRequestException e) {
203-
// Should review the error, and fix the request
204-
LOG.error("Should review the error, and fix the request", e);
205-
LOG.info("HTTP Status: " + e.getStatus());
206-
LOG.info("Error Code: " + e.getErrorCode());
207-
LOG.info("Error Message: " + e.getErrorMessage());
208-
}
192+
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
193+
try {
194+
ReceivedsResult result = jpushClient.getReportReceiveds("1942377665");
195+
LOG.debug("Got result - " + result);
196+
197+
} catch (APIConnectionException e) {
198+
// Connection error, should retry later
199+
LOG.error("Connection error, should retry later", e);
200+
201+
} catch (APIRequestException e) {
202+
// Should review the error, and fix the request
203+
LOG.error("Should review the error, and fix the request", e);
204+
LOG.info("HTTP Status: " + e.getStatus());
205+
LOG.info("Error Code: " + e.getErrorCode());
206+
LOG.info("Error Message: " + e.getErrorMessage());
207+
}
209208
```
210209

211210
### Tag/Alias 样例
212211

213212
> 以下片断来自项目代码里的文件:example / cn.jpush.api.examples.DeviceExample
214213
215214
```Java
216-
try {
217-
TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID1);
218-
219-
LOG.info(result.alias);
220-
LOG.info(result.tags.toString());
221-
222-
} catch (APIConnectionException e) {
223-
LOG.error("Connection error. Should retry later. ", e);
224-
225-
} catch (APIRequestException e) {
226-
LOG.error("Error response from JPush server. Should review and fix it. ", e);
227-
LOG.info("HTTP Status: " + e.getStatus());
228-
LOG.info("Error Code: " + e.getErrorCode());
229-
LOG.info("Error Message: " + e.getErrorMessage());
230-
}
215+
try {
216+
TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID1);
217+
218+
LOG.info(result.alias);
219+
LOG.info(result.tags.toString());
220+
} catch (APIConnectionException e) {
221+
LOG.error("Connection error. Should retry later. ", e);
222+
} catch (APIRequestException e) {
223+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
224+
LOG.info("HTTP Status: " + e.getStatus());
225+
LOG.info("Error Code: " + e.getErrorCode());
226+
LOG.info("Error Message: " + e.getErrorMessage());
227+
}
228+
```
229+
230+
### Schedule 样例
231+
232+
> 以下片断来自项目代码里的文件:example / cn.jpush.api.examples.ScheduleExample
233+
234+
```Java
235+
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
236+
String name = "test_schedule_example";
237+
String time = "2016-07-30 12:30:25";
238+
PushPayload push = PushPayload.alertAll("test schedule example.");
239+
try {
240+
ScheduleResult result = jpushClient.createSingleSchedule(name, time, push);
241+
LOG.info("schedule result is " + result);
242+
} catch (APIConnectionException e) {
243+
LOG.error("Connection error. Should retry later. ", e);
244+
} catch (APIRequestException e) {
245+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
246+
LOG.info("HTTP Status: " + e.getStatus());
247+
LOG.info("Error Code: " + e.getErrorCode());
248+
LOG.info("Error Message: " + e.getErrorMessage());
249+
}
231250
```

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

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

3+
import cn.jpush.api.common.ClientConfig;
34
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
56

@@ -21,8 +22,8 @@ public class PushExample {
2122
protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class);
2223

2324
// demo App defined in resources/jpush-api.conf
24-
private static final String appKey ="dd1066407b044738b6479275";
25-
private static final String masterSecret = "2b38ce69b1de2a7fa95706ea";
25+
private static final String appKey ="e5c0d34f58732cf09b2d4d74";
26+
private static final String masterSecret = "4cdda6d3c8b029941dbc5cb3";
2627

2728
public static final String TITLE = "Test from API example";
2829
public static final String ALERT = "Test from API Example - alert";
@@ -31,7 +32,7 @@ public class PushExample {
3132
public static final String TAG = "tag_api";
3233

3334
public static void main(String[] args) {
34-
testSendPush();
35+
testSendPushWithCustomConfig();
3536
}
3637

3738

@@ -126,7 +127,32 @@ public static PushPayload buildPushObject_ios_audienceMore_messageWithExtras() {
126127
.build())
127128
.build();
128129
}
129-
130-
130+
131+
public static void testSendPushWithCustomConfig() {
132+
ClientConfig config = ClientConfig.getInstance();
133+
// Setup the custom hostname
134+
config.setPushHostName("https://api.jpush.cn");
135+
136+
JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3, null, config);
137+
138+
// For push, all you need do is to build PushPayload object.
139+
PushPayload payload = buildPushObject_all_all_alert();
140+
141+
try {
142+
PushResult result = jpushClient.sendPush(payload);
143+
LOG.info("Got result - " + result);
144+
145+
} catch (APIConnectionException e) {
146+
LOG.error("Connection error. Should retry later. ", e);
147+
148+
} catch (APIRequestException e) {
149+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
150+
LOG.info("HTTP Status: " + e.getStatus());
151+
LOG.info("Error Code: " + e.getErrorCode());
152+
LOG.info("Error Message: " + e.getErrorMessage());
153+
LOG.info("Msg ID: " + e.getMsgId());
154+
}
155+
}
156+
131157
}
132158

0 commit comments

Comments
 (0)