feat(cp-tp):为企业微信第三方应用SDK添加消息发送服务(WxCpTpMessageService)#3931
Conversation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
本次变更在 weixin-java-cp 的第三方应用(TP)能力中补齐“代授权企业发送/撤回应用消息”等消息推送相关接口,并将其挂载到 WxCpTpService 体系中,便于调用方通过统一入口获取消息服务。
Changes:
- 新增
WxCpTpMessageService及其实现WxCpTpMessageServiceImpl,支持发送消息、查询统计、互联企业消息、学校通知、撤回消息(均按 corpId 使用对应 access_token,并以withoutSuiteAccessToken=true发起请求)。 - 在
WxCpTpService/BaseWxCpTpServiceImpl中新增并初始化消息服务的 getter/setter。 - 补充对应的 TestNG 用例并纳入
testng.xml测试套件。
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| weixin-java-cp/src/test/resources/testng.xml | 将新增的消息服务测试类加入 TestNG 执行列表 |
| weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpMessageServiceImplTest.java | 新增消息服务单测,验证调用时 withoutSuiteAccessToken=true 且使用 corpId 对应 access_token |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java | 在 TP 总入口接口上新增消息服务的 get/set 声明 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpMessageService.java | 新增第三方应用消息推送服务接口定义 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpMessageServiceImpl.java | 新增接口实现,封装消息相关 API 调用 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java | 初始化并暴露消息服务实例 |
🤖 Augment PR Summary总结:本 PR 为企业微信「第三方应用(TP)」模块补齐了缺失的消息发送能力,提供与自建应用 变更内容:
技术要点:TP 场景下没有默认应用上下文,调用方需要自行在消息体中设置 🤖 Was this summary useful? React with 👍 or 👎 |
| * @return 消息发送结果 | ||
| * @throws WxErrorException 微信错误异常 | ||
| */ | ||
| WxCpMessageSendResult send(WxCpMessage message, String corpId) throws WxErrorException; |
There was a problem hiding this comment.
TP 场景下如果消息体未显式设置 agentId(例如 WxCpMessage/WxCpLinkedCorpMessage/WxCpSchoolContactMessage),接口通常会直接返回参数错误;这里建议在接口 Javadoc 里明确“调用方必须自行设置 agentId”,避免误用。
Severity: low
Other Locations
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpMessageService.java:55weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpMessageService.java:71
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
|
|
||
| @Override | ||
| public WxCpMessageSendResult send(WxCpMessage message, String corpId) throws WxErrorException { | ||
| String url = mainService.getWxCpTpConfigStorage().getApiUrl(MESSAGE_SEND) |
There was a problem hiding this comment.
这里用 + "?access_token=" 直接拼接 URL,若 getApiUrl(...) 在某些私有化/网关场景下已带查询参数,可能生成 ?? 导致请求失败;可以考虑按 uri.contains("?") ? "&" : "?" 的方式拼接以规避边界问题。
Severity: low
Other Locations
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpMessageServiceImpl.java:35weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpMessageServiceImpl.java:44weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpMessageServiceImpl.java:52weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpMessageServiceImpl.java:61
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| * | ||
| * @throws WxErrorException 微信错误异常 | ||
| */ | ||
| @Test |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot 更新当前PR的标题和描述为中文,并解决合并冲突 |
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
已完成:
|
企业微信第三方应用 SDK(
tp模块)缺少消息发送相关的 Service。与普通api包中已有WxCpMessageService不同,第三方应用代授权企业发送消息需要使用授权企业的access_token,因此需要独立封装。变更内容
新增
WxCpTpMessageService接口(tp/service/)—— 对应WxCpMessageService,所有方法增加corpId参数:send(WxCpMessage, String corpId)— 发送应用消息getStatistics(int timeType, String corpId)— 查询消息发送统计sendLinkedCorpMessage(WxCpLinkedCorpMessage, String corpId)— 互联企业发送消息sendSchoolContactMessage(WxCpSchoolContactMessage, String corpId)— 发送学校通知recall(String msgId, String corpId)— 撤回应用消息新增
WxCpTpMessageServiceImpl实现类 —— 通过getAccessToken(corpId)获取授权企业的access_token,并以withoutSuiteAccessToken=true发起请求,防止误附加suite_access_token。与WxCpTpOAServiceImpl、WxCpTpUserServiceImpl等实现模式保持一致。修改
WxCpTpService接口 +BaseWxCpTpServiceImpl—— 新增getWxCpTpMessageService()/setWxCpTpMessageService()并完成默认初始化。新增单元测试(
WxCpTpMessageServiceImplTest)—— 使用 Mockito 验证corpId对应的access_token正确使用,以及withoutSuiteAccessToken=true参数正确传递;已纳入testng.xml测试套件。使用示例
与普通
WxCpMessageService的核心区别:每次调用需显式传入corpId,且调用方必须自行在消息中设置agentId(TP 上下文中没有默认 agent 配置)。Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.