Skip to content

Commit 70e3b8a

Browse files
committed
Merge pull request #49 from jpush/dev
merge version 3.2.8
2 parents 81a93ba + 9884cfc commit 70e3b8a

File tree

13 files changed

+417
-122
lines changed

13 files changed

+417
-122
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,31 @@
301301
LOG.info("Error Message: " + e.getErrorMessage());
302302
}
303303
```
304+
305+
### Custom Client 样例
306+
307+
> 一下片断来自项目代码里面的文件:example / cn.jpush.api.examples.ClientExample
308+
309+
```Java
310+
public static void testCustomClient() {
311+
ClientConfig config = ClientConfig.getInstance();
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+
JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
317+
}
318+
319+
public static void testCustomPushClient() {
320+
ClientConfig config = ClientConfig.getInstance();
321+
config.setApnsProduction(false); // development env
322+
config.setTimeToLive(60 * 60 * 24); // one day
323+
324+
// config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day
325+
326+
JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); // JPush client
327+
328+
// PushClient pushClient = new PushClient(masterSecret, appKey, null, config); // push client only
329+
330+
}
331+
```
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 = "e8cc9a76d5b7a580859bcfa7";
13+
14+
public static void main(String[] args) {
15+
// testDefaultClient();
16+
// testCustomClient();
17+
// testCustomPushClient();
18+
}
19+
20+
public static void testDefaultClient() {
21+
JPushClient client = new JPushClient(masterSecret, appKey);
22+
23+
// JPushClient client1 = new JPushClient(masterSecret, appKey, null, ClientConfig.getInstance());
24+
}
25+
26+
public static void testCustomClient() {
27+
ClientConfig config = ClientConfig.getInstance();
28+
config.setMaxRetryTimes(5);
29+
config.setConnectionTimeout(10 * 1000); // 10 seconds
30+
config.setSSLVersion("TLSv1.1"); // JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2
31+
32+
JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
33+
}
34+
35+
public static void testCustomPushClient() {
36+
ClientConfig config = ClientConfig.getInstance();
37+
38+
config.setApnsProduction(false); // development env
39+
config.setTimeToLive(60 * 60 * 24); // one day
40+
41+
// config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day
42+
43+
JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); // JPush client
44+
45+
// PushClient pushClient = new PushClient(masterSecret, appKey, null, config); // push client only
46+
47+
}
48+
49+
}
50+
51+

example/main/java/cn/jpush/api/examples/DevcieExample.java renamed to example/main/java/cn/jpush/api/examples/DeviceExample.java

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

3-
import cn.jpush.api.common.resp.DefaultResult;
4-
import cn.jpush.api.device.OnlineStatus;
5-
import org.slf4j.Logger;
6-
import org.slf4j.LoggerFactory;
7-
83
import cn.jpush.api.JPushClient;
94
import cn.jpush.api.common.resp.APIConnectionException;
105
import cn.jpush.api.common.resp.APIRequestException;
6+
import cn.jpush.api.common.resp.DefaultResult;
7+
import cn.jpush.api.device.OnlineStatus;
118
import cn.jpush.api.device.TagAliasResult;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
1211

1312
import java.util.Map;
1413

15-
public class DevcieExample {
16-
protected static final Logger LOG = LoggerFactory.getLogger(DevcieExample.class);
14+
public class DeviceExample {
15+
protected static final Logger LOG = LoggerFactory.getLogger(DeviceExample.class);
1716

1817
private static final String appKey = "dd1066407b044738b6479275";
19-
private static final String masterSecret = "6b135be0037a5c1e693c3dfa";
18+
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";
2019
private static final String TAG1 = "tag1";
2120
private static final String ALIAS1 = "alias1";
2221
private static final String ALIAS2 = "alias2";
@@ -27,7 +26,7 @@ public class DevcieExample {
2726

2827
public static void main(String[] args) {
2928
// testGetDeviceTagAlias();
30-
testGetUserOnlineStatus();
29+
// testGetUserOnlineStatus();
3130
}
3231

3332
public static void testGetDeviceTagAlias() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class PushExample {
2222
protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class);
2323

2424
// demo App defined in resources/jpush-api.conf
25-
private static final String appKey ="e5c0d34f58732cf09b2d4d74";
26-
private static final String masterSecret = "4cdda6d3c8b029941dbc5cb3";
25+
private static final String appKey ="dd1066407b044738b6479275";
26+
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";
2727

2828
public static final String TITLE = "Test from API example";
2929
public static final String ALERT = "Test from API Example - alert";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ReportsExample {
1616

1717
// demo App defined in resources/jpush-api.conf
1818
private static final String appKey = "dd1066407b044738b6479275";
19-
private static final String masterSecret = "2b38ce69b1de2a7fa95706ea";
19+
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";
2020

2121
public static void main(String[] args) {
2222
testGetReport();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class ScheduleExample {
1717

1818
protected static final Logger LOG = LoggerFactory.getLogger(ScheduleExample.class);
1919

20-
private static final String appKey ="e5c0d34f58732cf09b2d4d74";
21-
private static final String masterSecret = "4cdda6d3c8b029941dbc5cb3";
20+
private static final String appKey ="dd1066407b044738b6479275";
21+
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";
2222

2323
public static void main(String[] args) {
2424

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

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,39 @@ public JPushClient(String masterSecret, String appKey) {
5454
_deviceClient = new DeviceClient(masterSecret, appKey);
5555
_scheduleClient = new ScheduleClient(masterSecret, appKey);
5656
}
57-
57+
58+
/**
59+
* Create a JPush Client by custom Client configuration.
60+
*
61+
* @param masterSecret API access secret of the appKey.
62+
* @param appKey The KEY of one application on JPush.
63+
* @param proxy The proxy, if there is no proxy, should be null.
64+
* @param conf The client configuration. Can use ClientConfig.getInstance() as default.
65+
*/
66+
public JPushClient(String masterSecret, String appKey, HttpProxy proxy, ClientConfig conf) {
67+
_pushClient = new PushClient(masterSecret, appKey, proxy, conf);
68+
_reportClient = new ReportClient(masterSecret, appKey, proxy, conf);
69+
_deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf);
70+
_scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf);
71+
}
72+
73+
/**
74+
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setMaxRetryTimes} instead of this constructor.
75+
*
76+
*/
77+
@Deprecated
5878
public JPushClient(String masterSecret, String appKey, int maxRetryTimes) {
5979
_pushClient = new PushClient(masterSecret, appKey, maxRetryTimes);
6080
_reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes);
6181
_deviceClient = new DeviceClient(masterSecret, appKey, maxRetryTimes);
6282
_scheduleClient = new ScheduleClient(masterSecret, appKey, maxRetryTimes);
6383
}
64-
84+
85+
/**
86+
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setMaxRetryTimes} instead of this constructor.
87+
*
88+
*/
89+
@Deprecated
6590
public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy) {
6691
_pushClient = new PushClient(masterSecret, appKey, maxRetryTimes, proxy);
6792
_reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes, proxy);
@@ -73,25 +98,33 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr
7398
* Create a JPush Client by custom Client configuration.
7499
*
75100
* If you are using JPush privacy cloud, maybe this constructor is what you needed.
101+
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setMaxRetryTimes} instead of this constructor.
76102
*
77103
* @param masterSecret API access secret of the appKey.
78104
* @param appKey The KEY of one application on JPush.
79105
* @param maxRetryTimes Client request retry times.
80106
* @param proxy The proxy, if there is no proxy, should be null.
81107
* @param conf The client configuration. Can use ClientConfig.getInstance() as default.
82108
*/
109+
@Deprecated
83110
public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, ClientConfig conf) {
84-
_pushClient = new PushClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
85-
_reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
86-
_deviceClient = new DeviceClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
87-
_scheduleClient = new ScheduleClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
111+
conf.setMaxRetryTimes(maxRetryTimes);
112+
113+
_pushClient = new PushClient(masterSecret, appKey, proxy, conf);
114+
_reportClient = new ReportClient(masterSecret, appKey, proxy, conf);
115+
_deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf);
116+
_scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf);
117+
88118
}
89119

120+
121+
90122
/**
91123
* Create a JPush Client by custom Client configuration with global settings.
92124
*
93125
* If you are using JPush privacy cloud, and you want different settings from default globally,
94126
* maybe this constructor is what you needed.
127+
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this constructor.
95128
*
96129
* @param masterSecret API access secret of the appKey.
97130
* @param appKey The KEY of one application on JPush.
@@ -101,33 +134,36 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr
101134
* @param apnsProduction Global APNs environment setting. It will override PushPayload Options.
102135
* @param timeToLive Global time_to_live setting. It will override PushPayload Options.
103136
*/
137+
@Deprecated
104138
public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, ClientConfig conf,
105139
boolean apnsProduction, long timeToLive) {
106-
_pushClient = new PushClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
107-
_reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
108-
_deviceClient = new DeviceClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
109-
_scheduleClient = new ScheduleClient(masterSecret, appKey, maxRetryTimes, proxy, conf);
140+
conf.setMaxRetryTimes(maxRetryTimes);
141+
_pushClient = new PushClient(masterSecret, appKey, proxy, conf);
142+
_reportClient = new ReportClient(masterSecret, appKey, proxy, conf);
143+
_deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf);
144+
_scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf);
110145
_pushClient.setDefaults(apnsProduction, timeToLive);
146+
111147
}
112148

113149
/**
114150
* Create a JPush Client with global settings.
115151
*
116152
* If you want different settings from default globally, this constructor is what you needed.
117-
*
153+
* This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this constructor.
154+
*
118155
* @param masterSecret API access secret of the appKey.
119156
* @param appKey The KEY of one application on JPush.
120157
* @param apnsProduction Global APNs environment setting. It will override PushPayload Options.
121158
* @param timeToLive Global time_to_live setting. It will override PushPayload Options.
122159
*/
160+
@Deprecated
123161
public JPushClient(String masterSecret, String appKey, boolean apnsProduction, long timeToLive) {
124162
_pushClient = new PushClient(masterSecret, appKey, apnsProduction, timeToLive);
125163
_reportClient = new ReportClient(masterSecret, appKey);
126164
_deviceClient = new DeviceClient(masterSecret, appKey);
127165
_scheduleClient = new ScheduleClient(masterSecret, appKey);
128166
}
129-
130-
131167
// ----------------------------- Push API
132168

133169
/**

0 commit comments

Comments
 (0)