@@ -94,19 +94,25 @@ maven package
9494> 以下片断来自项目代码里的文件:cn.jpush.api.examples.PushExample
9595
9696```
97- JPushClient jpushClient = new JPushClient(masterSecret, appKey);
97+ JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
98+
99+ // For push, all you need do is to build PushPayload object.
98100 PushPayload payload = buildPushObject_all_all_alert();
99- LOG.info("Paylaod JSON - " + payload.toString());
100-
101- PushResult result = jpushClient.sendPush(payload);
102- if (result.isResultOK()) {
103- LOG.debug(result.toString());
104- } else {
105- if (result.getErrorCode() > 0) {
106- LOG.warn(result.getOriginalContent());
107- } else {
108- LOG.debug("Maybe connect error. Retry laster. ");
109- }
101+
102+ try {
103+ PushResult result = jpushClient.sendPush(payload);
104+ LOG.info("Got result - " + result);
105+
106+ } catch (APIConnectionException e) {
107+ // Connection error, should retry later
108+ LOG.error("Connection error, should retry later", e);
109+
110+ } catch (APIRequestException e) {
111+ // Should review the error, and fix the request
112+ LOG.error("Should review the error, and fix the request", e);
113+ LOG.info("HTTP Status: " + e.getStatus());
114+ LOG.info("Error Code: " + e.getErrorCode());
115+ LOG.info("Error Message: " + e.getErrorMessage());
110116 }
111117
112118```
@@ -193,21 +199,20 @@ maven package
193199> 以下片断来自项目代码里的文件:cn.jpush.api.examples.ReportsExample
194200
195201```
196- JPushClient jpushClient = new JPushClient(masterSecret, appKey);
197- ReceivedsResult receivedsResult = jpushClient.getReportReceiveds("1708010723,1774452771");
198- LOG.debug("responseContent - " + receivedsResult.responseResult.responseContent);
199- if (receivedsResult.isResultOK()) {
200- LOG.info("Receiveds - " + receivedsResult);
201- } else {
202- if (receivedsResult.getErrorCode() > 0) {
203- // 业务异常
204- LOG.warn("Service error - ErrorCode: "
205- + receivedsResult.getErrorCode() + ", ErrorMessage: "
206- + receivedsResult.getErrorMessage());
207- } else {
208- // 未到达 JPush
209- LOG.error("Other excepitons - "
210- + receivedsResult.responseResult.exceptionString);
211- }
212- }
202+ JPushClient jpushClient = new JPushClient(masterSecret, appKey);
203+ try {
204+ ReceivedsResult result = jpushClient.getReportReceiveds("1942377665");
205+ LOG.debug("Got result - " + result);
206+
207+ } catch (APIConnectionException e) {
208+ // Connection error, should retry later
209+ LOG.error("Connection error, should retry later", e);
210+
211+ } catch (APIRequestException e) {
212+ // Should review the error, and fix the request
213+ LOG.error("Should review the error, and fix the request", e);
214+ LOG.info("HTTP Status: " + e.getStatus());
215+ LOG.info("Error Code: " + e.getErrorCode());
216+ LOG.info("Error Message: " + e.getErrorMessage());
217+ }
213218```
0 commit comments