Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
</dependency>
```
### jar 包方式
Expand Down
16 changes: 11 additions & 5 deletions example/main/java/cn/jpush/api/examples/PushExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.Map;

import cn.jiguang.common.ServiceHelper;
import cn.jiguang.common.connection.ApacheHttpClient;
import cn.jiguang.common.connection.HttpProxy;
import cn.jiguang.common.connection.NativeHttpClient;
import cn.jiguang.common.connection.NettyHttpClient;
import cn.jiguang.common.resp.ResponseWrapper;
Expand Down Expand Up @@ -183,13 +181,21 @@ public void run() {
}
}

public static void testSendGroupPush() {
public void testSendGroupPush() {
GroupPushClient groupPushClient = new GroupPushClient(GROUP_MASTER_SECRET, GROUP_PUSH_KEY);
final PushPayload payload = buildPushObject_android_and_ios();
try {
PushResult result = groupPushClient.sendGroupPush(payload);
LOG.info("Got result - " + result);
Map<String, PushResult> result = groupPushClient.sendGroupPush(payload);
for (Map.Entry<String, PushResult> entry : result.entrySet()) {
PushResult pushResult = entry.getValue();
PushResult.Error error = pushResult.error;
if (error != null) {
LOG.info("AppKey: " + entry.getKey() + " error code : " + error.getCode() + " error message: " + error.getMessage());
} else {
LOG.info("AppKey: " + entry.getKey() + " sendno: " + pushResult.sendno + " msg_id:" + pushResult.msg_id);
}

}
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
LOG.error("Sendno: " + payload.getSendno());
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<url>https://github.com/jpush/jpush-api-java-client</url>
<connection>scm:git:git@github.com:jpush/jpush-api-java-client.git</connection>
<developerConnection>scm:git:git@github.com:jpush/jpush-api-java-client.git</developerConnection>
<tag>v3.3.2</tag>
<tag>v3.3.3</tag>
</scm>

<dependencies>
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/cn/jpush/api/push/GroupPushClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import cn.jiguang.common.connection.NativeHttpClient;
import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jiguang.common.resp.BaseResult;
import cn.jiguang.common.resp.ResponseWrapper;
import cn.jiguang.common.utils.Preconditions;
import cn.jpush.api.push.model.PushPayload;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.Map;

/**
* Created by caiyaoguan on 2017/7/4.
Expand All @@ -20,6 +23,7 @@ public class GroupPushClient {
private IHttpClient _httpClient;
private String _baseUrl;
private String _groupPushPath;
private Gson _gson = new Gson();

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

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

ResponseWrapper response = _httpClient.sendPost(_baseUrl + _groupPushPath, pushPayload.toString());

return BaseResult.fromResponse(response, PushResult.class);
return _gson.fromJson(response.responseContent,
new TypeToken<Map<String, PushResult>>(){}.getType());
}

}
13 changes: 13 additions & 0 deletions src/main/java/cn/jpush/api/push/PushResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ public class PushResult extends BaseResult {
@Expose public long msg_id;
@Expose public int sendno;
@Expose public int statusCode;
@Expose public Error error;
public class Error {
@Expose String message;
@Expose int code;

public String getMessage() {
return this.message;
}

public int getCode() {
return this.code;
}
}

}

14 changes: 12 additions & 2 deletions src/test/java/cn/jpush/api/push/GroupPushClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class GroupPushClientTest extends BaseTest {

protected static final Logger LOG = LoggerFactory.getLogger(GroupPushClientTest.class);
Expand All @@ -22,9 +24,17 @@ public void testSendGroupPush() {
GroupPushClient groupPushClient = new GroupPushClient(GROUP_MASTER_SECRET, GROUP_PUSH_KEY);
final PushPayload payload = buildPushObject_android();
try {
PushResult result = groupPushClient.sendGroupPush(payload);
LOG.info("Got result - " + result);
Map<String, PushResult> result = groupPushClient.sendGroupPush(payload);
for (Map.Entry<String, PushResult> entry : result.entrySet()) {
PushResult pushResult = entry.getValue();
PushResult.Error error = pushResult.error;
if (error != null) {
LOG.info("AppKey: " + entry.getKey() + " error code : " + error.getCode() + " error message: " + error.getMessage());
} else {
LOG.info("AppKey: " + entry.getKey() + " sendno: " + pushResult.sendno + " msg_id:" + pushResult.msg_id);
}

}
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
LOG.error("Sendno: " + payload.getSendno());
Expand Down