From 791ec8d2db5c73519b573955afb8ddc757b1e9bc Mon Sep 17 00:00:00 2001 From: oldmanl <441331607@qq.com> Date: Fri, 21 Oct 2022 13:54:41 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#2837=20=E3=80=90=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E3=80=91=E5=A2=9E=E5=8A=A0=E6=92=A4=E5=9B=9E?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=B6=88=E6=81=AF=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/cp/api/WxCpMessageService.java | 12 ++++++++++++ .../weixin/cp/api/impl/WxCpMessageServiceImpl.java | 9 +++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 6 ++++++ .../cp/api/impl/WxCpMessageServiceImplTest.java | 12 ++++++++++++ 4 files changed, 39 insertions(+) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java index fa455bc5f..e49a36ba5 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java @@ -65,4 +65,16 @@ public interface WxCpMessageService { */ WxCpSchoolContactMessageSendResult sendSchoolContactMessage(WxCpSchoolContactMessage message) throws WxErrorException; + /** + *
+ * 撤回应用消息 + * + * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/message/recall?access_token=ACCESS_TOKEN + * 文档地址: https://developer.work.weixin.qq.com/document/path/94867 + *+ * @param msgId 消息id + * @throws WxErrorException + */ + void recall(String msgId) throws WxErrorException; + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java index 3d74f8249..6daea8ef2 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.cp.api.impl; import com.google.common.collect.ImmutableMap; +import com.google.gson.JsonObject; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpMessageService; @@ -56,4 +57,12 @@ public class WxCpMessageServiceImpl implements WxCpMessageService { .getApiUrl(Message.EXTERNAL_CONTACT_MESSAGE_SEND), message.toJson())); } + @Override + public void recall(String msgId) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("msgid", msgId); + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(Message.MESSAGE_RECALL); + this.cpService.post(apiUrl, jsonObject.toString()); + } + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index 9bf5ff5f5..1c549e2b4 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -84,6 +84,12 @@ public interface WxCpApiPathConsts { */ String EXTERNAL_CONTACT_MESSAGE_SEND = "/cgi-bin/externalcontact/message/send"; + /** + * 撤回应用消息 + * https://developer.work.weixin.qq.com/document/path/94867 + */ + String MESSAGE_RECALL = "/cgi-bin/message/recall"; + } /** diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImplTest.java index e1070a28a..708542f41 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImplTest.java @@ -41,6 +41,8 @@ public class WxCpMessageServiceImplTest { private Runner mockRunner; private ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage; + private WxCpMessageSendResult wxCpMessageSendResult; + /** * Sets . */ @@ -96,6 +98,7 @@ public class WxCpMessageServiceImplTest { WxCpMessageSendResult messageSendResult = this.wxService.getMessageService().send(message); assertNotNull(messageSendResult); + wxCpMessageSendResult = messageSendResult; System.out.println(messageSendResult); System.out.println(messageSendResult.getInvalidPartyList()); System.out.println(messageSendResult.getInvalidUserList()); @@ -222,4 +225,13 @@ public class WxCpMessageServiceImplTest { assertThat(statistics.getStatistics()).isNotNull(); } + /** + * Test message recall + * @throws WxErrorException + */ + @Test(dependsOnMethods = "testSendMessage1") + public void testRecall() throws WxErrorException { + this.wxService.getMessageService().recall(wxCpMessageSendResult.getMsgId()); + } + }