Skip to content

#2837 【企业微信】企业微信添加撤回应用消息功能 #2844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 21, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,16 @@ public interface WxCpMessageService {
*/
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;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -56,4 +57,12 @@ public WxCpSchoolContactMessageSendResult sendSchoolContactMessage(WxCpSchoolCon
.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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ interface Message {
*/
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";

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class WxCpMessageServiceImplTest {
private Runner mockRunner;
private ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage;

private WxCpMessageSendResult wxCpMessageSendResult;

/**
* Sets .
*/
Expand Down Expand Up @@ -96,6 +98,7 @@ public void testSendMessage1() throws WxErrorException {

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());
Expand Down Expand Up @@ -222,4 +225,13 @@ public void testGetStatistics() throws WxErrorException {
assertThat(statistics.getStatistics()).isNotNull();
}

/**
* Test message recall
* @throws WxErrorException
*/
@Test(dependsOnMethods = "testSendMessage1")
public void testRecall() throws WxErrorException {
this.wxService.getMessageService().recall(wxCpMessageSendResult.getMsgId());
}

}