Skip to content

Commit aa293fb

Browse files
authored
Merge pull request #98 from jpush/dev
prepare release 3.3.3
2 parents f3b798f + 8e213b7 commit aa293fb

File tree

6 files changed

+46
-13
lines changed

6 files changed

+46
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>cn.jpush.api</groupId>
2828
<artifactId>jpush-client</artifactId>
29-
<version>3.3.2</version>
29+
<version>3.3.3</version>
3030
</dependency>
3131
```
3232
### jar 包方式

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import java.util.Map;
77

88
import cn.jiguang.common.ServiceHelper;
9-
import cn.jiguang.common.connection.ApacheHttpClient;
10-
import cn.jiguang.common.connection.HttpProxy;
119
import cn.jiguang.common.connection.NativeHttpClient;
1210
import cn.jiguang.common.connection.NettyHttpClient;
1311
import cn.jiguang.common.resp.ResponseWrapper;
@@ -183,13 +181,21 @@ public void run() {
183181
}
184182
}
185183

186-
public static void testSendGroupPush() {
184+
public void testSendGroupPush() {
187185
GroupPushClient groupPushClient = new GroupPushClient(GROUP_MASTER_SECRET, GROUP_PUSH_KEY);
188186
final PushPayload payload = buildPushObject_android_and_ios();
189187
try {
190-
PushResult result = groupPushClient.sendGroupPush(payload);
191-
LOG.info("Got result - " + result);
188+
Map<String, PushResult> result = groupPushClient.sendGroupPush(payload);
189+
for (Map.Entry<String, PushResult> entry : result.entrySet()) {
190+
PushResult pushResult = entry.getValue();
191+
PushResult.Error error = pushResult.error;
192+
if (error != null) {
193+
LOG.info("AppKey: " + entry.getKey() + " error code : " + error.getCode() + " error message: " + error.getMessage());
194+
} else {
195+
LOG.info("AppKey: " + entry.getKey() + " sendno: " + pushResult.sendno + " msg_id:" + pushResult.msg_id);
196+
}
192197

198+
}
193199
} catch (APIConnectionException e) {
194200
LOG.error("Connection error. Should retry later. ", e);
195201
LOG.error("Sendno: " + payload.getSendno());

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<url>https://github.com/jpush/jpush-api-java-client</url>
3636
<connection>scm:git:[email protected]:jpush/jpush-api-java-client.git</connection>
3737
<developerConnection>scm:git:[email protected]:jpush/jpush-api-java-client.git</developerConnection>
38-
<tag>v3.3.2</tag>
38+
<tag>v3.3.3</tag>
3939
</scm>
4040

4141
<dependencies>

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
import cn.jiguang.common.connection.NativeHttpClient;
88
import cn.jiguang.common.resp.APIConnectionException;
99
import cn.jiguang.common.resp.APIRequestException;
10-
import cn.jiguang.common.resp.BaseResult;
1110
import cn.jiguang.common.resp.ResponseWrapper;
1211
import cn.jiguang.common.utils.Preconditions;
1312
import cn.jpush.api.push.model.PushPayload;
13+
import com.google.gson.Gson;
14+
import com.google.gson.reflect.TypeToken;
15+
16+
import java.util.Map;
1417

1518
/**
1619
* Created by caiyaoguan on 2017/7/4.
@@ -20,6 +23,7 @@ public class GroupPushClient {
2023
private IHttpClient _httpClient;
2124
private String _baseUrl;
2225
private String _groupPushPath;
26+
private Gson _gson = new Gson();
2327

2428
public GroupPushClient(String groupMasterSecret, String groupKey) {
2529
this(groupMasterSecret, groupKey, null, ClientConfig.getInstance());
@@ -33,12 +37,12 @@ public GroupPushClient(String groupMasterSecret, String groupKey, HttpProxy prox
3337
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
3438
}
3539

36-
public PushResult sendGroupPush(PushPayload pushPayload) throws APIConnectionException, APIRequestException {
40+
public Map<String, PushResult> sendGroupPush(PushPayload pushPayload) throws APIConnectionException, APIRequestException {
3741
Preconditions.checkArgument(! (null == pushPayload), "pushPayload should not be null");
3842

3943
ResponseWrapper response = _httpClient.sendPost(_baseUrl + _groupPushPath, pushPayload.toString());
40-
41-
return BaseResult.fromResponse(response, PushResult.class);
44+
return _gson.fromJson(response.responseContent,
45+
new TypeToken<Map<String, PushResult>>(){}.getType());
4246
}
4347

4448
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ public class PushResult extends BaseResult {
1111
@Expose public long msg_id;
1212
@Expose public int sendno;
1313
@Expose public int statusCode;
14+
@Expose public Error error;
15+
public class Error {
16+
@Expose String message;
17+
@Expose int code;
18+
19+
public String getMessage() {
20+
return this.message;
21+
}
22+
23+
public int getCode() {
24+
return this.code;
25+
}
26+
}
1427

1528
}
1629

src/test/java/cn/jpush/api/push/GroupPushClientTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
1515

16+
import java.util.Map;
17+
1618
public class GroupPushClientTest extends BaseTest {
1719

1820
protected static final Logger LOG = LoggerFactory.getLogger(GroupPushClientTest.class);
@@ -22,9 +24,17 @@ public void testSendGroupPush() {
2224
GroupPushClient groupPushClient = new GroupPushClient(GROUP_MASTER_SECRET, GROUP_PUSH_KEY);
2325
final PushPayload payload = buildPushObject_android();
2426
try {
25-
PushResult result = groupPushClient.sendGroupPush(payload);
26-
LOG.info("Got result - " + result);
27+
Map<String, PushResult> result = groupPushClient.sendGroupPush(payload);
28+
for (Map.Entry<String, PushResult> entry : result.entrySet()) {
29+
PushResult pushResult = entry.getValue();
30+
PushResult.Error error = pushResult.error;
31+
if (error != null) {
32+
LOG.info("AppKey: " + entry.getKey() + " error code : " + error.getCode() + " error message: " + error.getMessage());
33+
} else {
34+
LOG.info("AppKey: " + entry.getKey() + " sendno: " + pushResult.sendno + " msg_id:" + pushResult.msg_id);
35+
}
2736

37+
}
2838
} catch (APIConnectionException e) {
2939
LOG.error("Connection error. Should retry later. ", e);
3040
LOG.error("Sendno: " + payload.getSendno());

0 commit comments

Comments
 (0)