Skip to content

Commit a8df83f

Browse files
author
yutaipu
committed
支持推送撤销
1 parent 0d0b3e5 commit a8df83f

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,16 @@ public PushResult sendMessageWithRegistrationID(String title, String msgContent,
860860
return _pushClient.sendPush(payload);
861861
}
862862

863+
/**
864+
* Delete a push by msgId.
865+
* @param msgId The message id
866+
* @return delete result
867+
* @throws APIConnectionException if a remote or network exception occurs.
868+
* @throws APIRequestException if a request exception occurs
869+
*/
870+
public DefaultResult deletePush(String msgId) throws APIConnectionException, APIRequestException {
871+
return _pushClient.deletePush(msgId);
872+
}
863873

864874

865875
// ----------------------- Device

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import cn.jiguang.common.ClientConfig;
44
import cn.jiguang.common.ServiceHelper;
55
import cn.jiguang.common.connection.*;
6-
import cn.jiguang.common.resp.APIConnectionException;
7-
import cn.jiguang.common.resp.APIRequestException;
8-
import cn.jiguang.common.resp.BaseResult;
9-
import cn.jiguang.common.resp.ResponseWrapper;
6+
import cn.jiguang.common.resp.*;
107
import cn.jiguang.common.utils.Base64;
118
import cn.jiguang.common.utils.Preconditions;
129
import cn.jiguang.common.utils.StringUtils;
@@ -272,6 +269,21 @@ public CIDResult getCidList(int count, String type) throws APIConnectionExceptio
272269
return BaseResult.fromResponse(responseWrapper, CIDResult.class);
273270
}
274271

272+
/**
273+
* Delete a push by msgId.
274+
* @param msgId The message id
275+
* @return delete result
276+
* @throws APIConnectionException connect exception
277+
* @throws APIRequestException request exception
278+
*/
279+
public DefaultResult deletePush(String msgId) throws APIConnectionException, APIRequestException {
280+
Preconditions.checkArgument(StringUtils.isNotEmpty(msgId), "msgId should not be empty");
281+
282+
ResponseWrapper responseWrapper = _httpClient.sendDelete(_baseUrl + _pushPath + "/" + msgId);
283+
284+
return DefaultResult.fromResponse(responseWrapper);
285+
}
286+
275287
public void setHttpClient(IHttpClient client) {
276288
this._httpClient = client;
277289
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cn.jiguang.common.ClientConfig;
77
import cn.jiguang.common.ServiceHelper;
88
import cn.jiguang.common.connection.NettyHttpClient;
9+
import cn.jiguang.common.resp.DefaultResult;
910
import cn.jiguang.common.resp.ResponseWrapper;
1011
import cn.jpush.api.JPushClient;
1112
import cn.jpush.api.push.model.Options;
@@ -181,6 +182,23 @@ public void testSendFilePush() {
181182
}
182183
}
183184

185+
@Test
186+
public void testDeletePush() {
187+
JPushClient jPushClient = new JPushClient(MASTER_SECRET, APP_KEY);
188+
try {
189+
String msgId = "58546877793854733";
190+
DefaultResult result = jPushClient.deletePush(msgId);
191+
LOG.info("Got result - " + result);
192+
} catch (APIConnectionException e) {
193+
LOG.error("Connection error. Should retry later. ", e);
194+
} catch (APIRequestException e) {
195+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
196+
LOG.info("HTTP Status: " + e.getStatus());
197+
LOG.info("Error Code: " + e.getErrorCode());
198+
LOG.info("Error Message: " + e.getErrorMessage());
199+
}
200+
}
201+
184202
private static PushPayload buildFilePushPayload() {
185203
return PushPayload.newBuilder()
186204
.setPlatform(Platform.android())

0 commit comments

Comments
 (0)