Skip to content

Commit 8b563e2

Browse files
committed
Merge pull request #46 from Liuchy1/master
add ClientExample, modify readme
2 parents 1e84ea9 + a670b91 commit 8b563e2

File tree

6 files changed

+85
-24
lines changed

6 files changed

+85
-24
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,30 @@
304304

305305
### Custom Client 样例
306306

307-
> 一下片断来自项目代码里面的文件:example / cn.jpush.api.examples.DeviceExample
307+
> 一下片断来自项目代码里面的文件:example / cn.jpush.api.examples.ClientExample
308308
309309
```Java
310310
public static void testCustomClient() {
311311
ClientConfig config = ClientConfig.getInstance();
312-
config.setMaxRetryTimes(5);
313-
config.setConnectionTimeout(10 * 1000);// 10 seconds
314-
config.setSSLVersion("TLSv1.1");
315-
ClientConfig.setReadTimeout(ClientConfig.getInstance(), 30 * 1000);// 30 seconds
316-
JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
312+
config.setMaxRetryTimes(5);
313+
config.setConnectionTimeout(10 * 1000); // 10 seconds
314+
config.setSSLVersion("TLSv1.1"); // JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2
315+
316+
ClientConfig.setReadTimeout(ClientConfig.getInstance(), 30 * 1000); // 30 seconds
317+
318+
JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
317319
}
320+
321+
public static void testCustomPushClient() {
322+
ClientConfig config = ClientConfig.getInstance();
323+
config.setApnsProduction(false); // development env
324+
config.setTimeToLive(60 * 60 * 24); // one day
325+
326+
// config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day
327+
328+
JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); // JPush client
329+
330+
// PushClient pushClient = new PushClient(masterSecret, appKey, null, config); // push client only
331+
332+
}
318333
```
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package cn.jpush.api.examples;
2+
3+
import cn.jpush.api.JPushClient;
4+
import cn.jpush.api.common.ClientConfig;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
public class ClientExample {
9+
protected static final Logger LOG = LoggerFactory.getLogger(ClientExample.class);
10+
11+
private static final String appKey = "dd1066407b044738b6479275";
12+
private static final String masterSecret = "6b135be0037a5c1e693c3dfa";
13+
private static final String TAG1 = "tag1";
14+
private static final String ALIAS1 = "alias1";
15+
private static final String ALIAS2 = "alias2";
16+
private static final String REGISTRATION_ID1 = "0900e8d85ef";
17+
private static final String REGISTRATION_ID2 = "0a04ad7d8b4";
18+
19+
20+
public static void main(String[] args) {
21+
// testDefaultClient();
22+
// testCustomClient();
23+
testCustomPushClient();
24+
}
25+
26+
public static void testDefaultClient() {
27+
JPushClient client = new JPushClient(masterSecret, appKey);
28+
29+
// JPushClient client1 = new JPushClient(masterSecret, appKey, null, ClientConfig.getInstance());
30+
}
31+
32+
public static void testCustomClient() {
33+
ClientConfig config = ClientConfig.getInstance();
34+
config.setMaxRetryTimes(5);
35+
config.setConnectionTimeout(10 * 1000); // 10 seconds
36+
config.setSSLVersion("TLSv1.1"); // JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2
37+
38+
ClientConfig.setReadTimeout(ClientConfig.getInstance(), 30 * 1000); // 30 seconds
39+
40+
JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
41+
}
42+
43+
public static void testCustomPushClient() {
44+
ClientConfig config = ClientConfig.getInstance();
45+
46+
config.setApnsProduction(false); // development env
47+
config.setTimeToLive(60 * 60 * 24); // one day
48+
49+
// config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day
50+
51+
JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); // JPush client
52+
53+
// PushClient pushClient = new PushClient(masterSecret, appKey, null, config); // push client only
54+
55+
}
56+
57+
}
58+
59+

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

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

33
import cn.jpush.api.JPushClient;
4-
import cn.jpush.api.common.ClientConfig;
54
import cn.jpush.api.common.resp.APIConnectionException;
65
import cn.jpush.api.common.resp.APIRequestException;
76
import cn.jpush.api.common.resp.DefaultResult;
@@ -28,7 +27,6 @@ public class DeviceExample {
2827
public static void main(String[] args) {
2928
// testGetDeviceTagAlias();
3029
// testGetUserOnlineStatus();
31-
testCustomClient();
3230
}
3331

3432
public static void testGetDeviceTagAlias() {
@@ -78,17 +76,6 @@ public static void testBindMobile() {
7876
LOG.info("Error Message: " + e.getErrorMessage());
7977
}
8078
}
81-
82-
public static void testCustomClient() {
83-
ClientConfig config = ClientConfig.getInstance();
84-
config.setMaxRetryTimes(5);
85-
config.setConnectionTimeout(10 * 1000);// 10 seconds
86-
config.setSSLVersion("TLSv1.1");
87-
88-
ClientConfig.setReadTimeout(ClientConfig.getInstance(), 30 * 1000);// 30 seconds
89-
90-
JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
91-
}
9279

9380
}
9481

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr
124124
*
125125
* If you are using JPush privacy cloud, and you want different settings from default globally,
126126
* maybe this constructor is what you needed.
127-
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGolbalPushSetting} instead of this constructor.
127+
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this constructor.
128128
*
129129
* @param masterSecret API access secret of the appKey.
130130
* @param appKey The KEY of one application on JPush.
@@ -151,7 +151,7 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr
151151
*
152152
* If you are using JPush privacy cloud, and you want different settings from default globally,
153153
* maybe this constructor is what you needed.
154-
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGolbalPushSetting} instead of this constructor.
154+
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this constructor.
155155
*
156156
* @param masterSecret API access secret of the appKey.
157157
* @param appKey The KEY of one application on JPush.
@@ -174,7 +174,7 @@ public JPushClient(String masterSecret, String appKey, HttpProxy proxy, ClientCo
174174
* Create a JPush Client with global settings.
175175
*
176176
* If you want different settings from default globally, this constructor is what you needed.
177-
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGolbalPushSetting} instead of this constructor.
177+
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this constructor.
178178
*
179179
* @param masterSecret API access secret of the appKey.
180180
* @param appKey The KEY of one application on JPush.

src/main/java/cn/jpush/api/common/ClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public void setTimeToLive(long timeToLive) {
229229
setTimeToLive(this, timeToLive);
230230
}
231231

232-
public void setGolbalPushSetting(boolean apnsProduction, long timeToLive) {
232+
public void setGlobalPushSetting(boolean apnsProduction, long timeToLive) {
233233
setApnsProduction(this, apnsProduction);
234234
setTimeToLive(timeToLive);
235235
}

src/main/java/cn/jpush/api/push/PushClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public PushClient(String masterSecret, String appKey, boolean apnsProduction, lo
121121
}
122122

123123
/**
124-
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGolbalPushSetting} instead of this method.
124+
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this method.
125125
*
126126
* @param apnsProduction Global APNs environment setting. It will override PushPayload Options.
127127
* @param timeToLive Global time_to_live setting. It will override PushPayload Options.

0 commit comments

Comments
 (0)