GeezerVison is showing github.com — 添加企微智能机器人消息接收和主动发送功能 by Copilot · Pull Request #3815 · binarywang/WxJava
Conversation
Copilot
AI
commented
Dec 19, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
问题
API 模式创建的智能机器人回调消息无法被 WxCpXmlMessage 正确解析,缺少主动发送消息的 API。
变更
消息接收支持
- 在
WxCpXmlMessage 添加 robotId 和 sessionId 字段及 XStream 注解
// 现在可以正确解析智能机器人回调消息
WxCpXmlMessage message = WxCpXmlMessage.fromEncryptedXml(...);
String robotId = message.getRobotId();
String sessionId = message.getSessionId();
主动发送消息 API
- 新增
WxCpIntelligentRobotSendMessageRequest/Response 类
- 在
WxCpIntelligentRobotService 添加 sendMessage() 方法
- 添加
SEND_MESSAGE API 路径常量
WxCpIntelligentRobotSendMessageRequest request = new WxCpIntelligentRobotSendMessageRequest();
request.setRobotId("robot_id");
request.setUserid("user123");
request.setMessage("消息内容");
WxCpIntelligentRobotSendMessageResponse response = robotService.sendMessage(request);
文档和测试
- 更新
INTELLIGENT_ROBOT.md 添加使用示例
- 添加消息解析和发送的单元测试
参考文档: https://developer.work.weixin.qq.com/document/path/100719
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
developer.work.weixin.qq.com
- Triggering command:
/usr/bin/curl curl -s REDACTED (dns block)
If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>企微智能机器人接收消息和主动发消息</issue_title>
<issue_description># 提问前,请确保阅读过项目首页说明以及wiki开发文档相关内容,完成内容后,请务必移除包括本句在内的无用内容,以免影响他人阅读,否则直接关闭,谢谢合作~
简要描述
用”API模式创建“智能机器人后
将自己的智能体接入到智能机器人,接收并回复消息
目前4.7.9.B用WxCpXmlMessage接收消息无法解析
官方文档地址
https://developer.work.weixin.qq.com/document/path/100719
#3684</issue_description>
Comments on the Issue (you are @copilot in this section)
Custom agent used: 全部用中文
需要用中文,包括PR标题和分析总结过程
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Copilot
AI
changed the title
[WIP] Fix message parsing issue in intelligent robot
添加企微智能机器人消息接收和主动发送功能
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
本 PR 为企业微信智能机器人模块添加了消息接收解析和主动发送消息的功能支持,解决了 API 模式创建的智能机器人回调消息无法被正确解析的问题。
主要变更包括:
- 在
WxCpXmlMessage 中添加 robotId 和 sessionId 字段支持智能机器人消息解析
- 新增主动发送消息的请求/响应类和服务方法
- 完善相关测试用例和文档说明
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File |
Description |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java |
添加 robotId 和 sessionId 字段及 XStream 注解,支持智能机器人消息解析 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/intelligentrobot/WxCpIntelligentRobotSendMessageRequest.java |
新增主动发送消息请求类,包含 robotId、userid、message、sessionId、msgId 字段 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/intelligentrobot/WxCpIntelligentRobotSendMessageResponse.java |
新增主动发送消息响应类,包含 msgId 和 sessionId 字段 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpIntelligentRobotService.java |
在服务接口中添加 sendMessage 方法定义 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpIntelligentRobotServiceImpl.java |
实现 sendMessage 方法,调用微信 API 发送消息 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java |
添加 SEND_MESSAGE API 路径常量 |
| weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessageTest.java |
添加智能机器人消息解析测试用例 |
| weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpIntelligentRobotServiceImplTest.java |
添加主动发送消息请求/响应的序列化和反序列化测试用例 |
| weixin-java-cp/INTELLIGENT_ROBOT.md |
更新文档,添加主动发送消息和接收消息的使用说明和示例代码 |
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…gentrobot/WxCpIntelligentRobotSendMessageResponse.java
Co-authored-by: Copilot <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
binarywang
Awaiting requested review from binarywang
Uh oh!
There was an error while loading. Please reload this page.
Development
Successfully merging this pull request may close these issues.
企微智能机器人接收消息和主动发消息
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.