Skip to content

补充企业微信智能机器人 API 模式 JSON 回调消息模型与服务调用入口#4011

Merged
binarywang merged 3 commits into
developfrom
copilot/support-wechat-robot-integration
May 20, 2026
Merged

补充企业微信智能机器人 API 模式 JSON 回调消息模型与服务调用入口#4011
binarywang merged 3 commits into
developfrom
copilot/support-wechat-robot-integration

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

当前 weixin-java-cp 已覆盖智能机器人管理与会话相关服务端 API,但对文档(path/101039 / path/100719)中的 API 模式 JSON 回调消息体缺少统一模型,接入侧需要自行拼装解析。
本 PR 在不扩展不存在接口的前提下,补齐官方回调结构的 SDK 级解析能力,并补充服务层统一调用入口。

  • 新增回调消息模型(intelligentrobot 包)

    • 新增 WxCpIntelligentRobotMessage
    • 覆盖官方回调关键字段:msgidaibotidchatidchattypefromresponse_urlmsgtype
    • 覆盖消息载荷结构:text / image / mixed / voice / file / video / quote / stream
    • 提供 fromJson / toJson,统一接入方序列化与反序列化入口
  • 新增服务调用入口(反馈补充)

    • WxCpIntelligentRobotService 新增 parseCallbackMessage(String callbackMessageJson)
    • WxCpIntelligentRobotServiceImpl 完成实现,内部基于 WxCpIntelligentRobotMessage.fromJson(...) 解析
    • 使调用方可通过 wxCpService.getIntelligentRobotService() 直接解析回调消息,而不必手动依赖模型静态方法
  • 补充契约测试(JSON 结构稳定性)

    • 新增 WxCpIntelligentRobotMessageTest
    • 覆盖文本消息解析、mixed+quote 复合结构解析、序列化回归校验
    • WxCpIntelligentRobotServiceImplTest 新增 testParseCallbackMessage,覆盖服务入口调用路径
  • 文档更新(接入路径补全)

    • 更新 weixin-java-cp/INTELLIGENT_ROBOT.md
    • 将 JSON 回调示例调整为通过 robotService.parseCallbackMessage(jsonBody) 调用,明确 SDK 推荐入口

示例:

WxCpIntelligentRobotMessage callbackMessage =
    robotService.parseCallbackMessage(jsonBody);

String botId = callbackMessage.getAiBotId();
String userId = callbackMessage.getFrom().getUserid();
String msgType = callbackMessage.getMsgType();

if ("text".equals(msgType) && callbackMessage.getText() != null) {
  String content = callbackMessage.getText().getContent();
}

Copilot AI linked an issue May 19, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add support for WeChat robot integration 补充企业微信智能机器人 API 模式 JSON 回调消息模型与示例 May 19, 2026
Copilot AI requested a review from binarywang May 19, 2026 05:07
@binarywang binarywang marked this pull request as ready for review May 19, 2026 09:31
Copilot AI review requested due to automatic review settings May 19, 2026 09:31
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 93417276dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +113 to +114
@SerializedName("url")
private String url;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Capture media aeskey in callback payloads

For image/file/video callbacks, WeCom sends the download URL together with an aeskey used to decrypt the downloaded media. These media payload classes only retain url, so fromJson() silently drops the key and callers receiving encrypted image, file, or video messages cannot use the SDK model to decrypt the media without reparsing the raw JSON.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Copilot AI left a 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 为 weixin-java-cp 的企业微信「智能机器人」能力补齐 API 模式 JSON 回调消息体的 SDK 级模型与解析入口,降低接入侧自行拼装/解析 JSON 的成本,并提供契约测试与文档示例以稳定回归。

Changes:

  • 新增 WxCpIntelligentRobotMessage:覆盖回调公共字段及多种消息载荷结构,并提供 fromJson/toJson 统一序列化入口。
  • 新增 WxCpIntelligentRobotMessageTest:覆盖文本与 mixed+quote 复合结构解析及序列化回归。
  • 更新 INTELLIGENT_ROBOT.md:补充 API 模式 JSON 回调解析示例与文档排版修正。

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/intelligentrobot/WxCpIntelligentRobotMessage.java 新增智能机器人 API 模式 JSON 回调消息模型,提供 Gson 序列化/反序列化入口
weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/intelligentrobot/WxCpIntelligentRobotMessageTest.java 新增契约测试,验证 JSON 解析与序列化回归
weixin-java-cp/INTELLIGENT_ROBOT.md 补充 JSON 回调解析示例并修正文档列表格式

@binarywang
Copy link
Copy Markdown
Owner

@copilot 这个新增的模型要如何调用?没有入口吗?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 20, 2026

@copilot 这个新增的模型要如何调用?没有入口吗?

已补上统一入口:wxCpService.getIntelligentRobotService().parseCallbackMessage(jsonBody),内部会解析为 WxCpIntelligentRobotMessage。同时补了对应测试与文档示例。提交:2782478

Copilot AI changed the title 补充企业微信智能机器人 API 模式 JSON 回调消息模型与示例 补充企业微信智能机器人 API 模式 JSON 回调消息模型与服务调用入口 May 20, 2026
@binarywang binarywang merged commit 93017a5 into develop May 20, 2026
1 check passed
@binarywang binarywang deleted the copilot/support-wechat-robot-integration branch May 20, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

企业微信智能机器人接入支持

3 participants