🆕 #2837 【企业微信】增加撤回应用消息的接口

This commit is contained in:
oldmanl 2022-10-21 13:54:41 +08:00 committed by GitHub
parent b6ad48dff7
commit 791ec8d2db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 0 deletions

View File

@ -65,4 +65,16 @@ public interface WxCpMessageService {
*/ */
WxCpSchoolContactMessageSendResult sendSchoolContactMessage(WxCpSchoolContactMessage message) throws WxErrorException; WxCpSchoolContactMessageSendResult sendSchoolContactMessage(WxCpSchoolContactMessage message) throws WxErrorException;
/**
* <pre>
* 撤回应用消息
*
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/message/recall?access_token=ACCESS_TOKEN
* 文档地址: https://developer.work.weixin.qq.com/document/path/94867
* </pre>
* @param msgId 消息id
* @throws WxErrorException
*/
void recall(String msgId) throws WxErrorException;
} }

View File

@ -1,6 +1,7 @@
package me.chanjar.weixin.cp.api.impl; package me.chanjar.weixin.cp.api.impl;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpMessageService; import me.chanjar.weixin.cp.api.WxCpMessageService;
@ -56,4 +57,12 @@ public class WxCpMessageServiceImpl implements WxCpMessageService {
.getApiUrl(Message.EXTERNAL_CONTACT_MESSAGE_SEND), message.toJson())); .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());
}
} }

View File

@ -84,6 +84,12 @@ public interface WxCpApiPathConsts {
*/ */
String EXTERNAL_CONTACT_MESSAGE_SEND = "/cgi-bin/externalcontact/message/send"; 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";
} }
/** /**

View File

@ -41,6 +41,8 @@ public class WxCpMessageServiceImplTest {
private Runner mockRunner; private Runner mockRunner;
private ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage; private ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage;
private WxCpMessageSendResult wxCpMessageSendResult;
/** /**
* Sets . * Sets .
*/ */
@ -96,6 +98,7 @@ public class WxCpMessageServiceImplTest {
WxCpMessageSendResult messageSendResult = this.wxService.getMessageService().send(message); WxCpMessageSendResult messageSendResult = this.wxService.getMessageService().send(message);
assertNotNull(messageSendResult); assertNotNull(messageSendResult);
wxCpMessageSendResult = messageSendResult;
System.out.println(messageSendResult); System.out.println(messageSendResult);
System.out.println(messageSendResult.getInvalidPartyList()); System.out.println(messageSendResult.getInvalidPartyList());
System.out.println(messageSendResult.getInvalidUserList()); System.out.println(messageSendResult.getInvalidUserList());
@ -222,4 +225,13 @@ public class WxCpMessageServiceImplTest {
assertThat(statistics.getStatistics()).isNotNull(); assertThat(statistics.getStatistics()).isNotNull();
} }
/**
* Test message recall
* @throws WxErrorException
*/
@Test(dependsOnMethods = "testSendMessage1")
public void testRecall() throws WxErrorException {
this.wxService.getMessageService().recall(wxCpMessageSendResult.getMsgId());
}
} }