Skip to content

feat: 支持企业微信智能机器人 API 模式 - #4100

Merged
binarywang merged 4 commits into
developfrom
fix/4099-cp-intelligent-robot-api-mode
Aug 22, 2026
Merged

feat: 支持企业微信智能机器人 API 模式#4100
binarywang merged 4 commits into
developfrom
fix/4099-cp-intelligent-robot-api-mode

Conversation

@binarywang

Copy link
Copy Markdown
Owner

关联

Fixes #4099

变更

  • 新增新版智能机器人 API 模式的 Token/AESKey/机器人 ID 加解密工具。
  • 支持解密加密 JSON 回调并解析为 WxCpIntelligentRobotMessage
  • 支持通过回调的 response_url 加密回复,且明确使用无 access_token 的请求通道。
  • 更新接入文档,区分旧 access-token 接口和新版机器人 API 模式。

验证

  • 编译新增生产与测试代码。
  • TestNG:3 项测试通过(加密信封往返、加密回调解析、response_url 加密无-token 回复)。

@binarywang
binarywang marked this pull request as ready for review August 21, 2026 03:34
Copilot AI lite review requested due to automatic review settings August 21, 2026 03:34
@augmentcode

augmentcode Bot commented Aug 21, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

概要:本 PR 为企业微信智能机器人的新版 API 模式增加回调加解密与回复支持。


变更:

  • 新增基于 Token、EncodingAESKey 和机器人 ID 的 `WxCpIntelligentRobotCryptUtil`。
  • 封装 JSON 加密信封生成、签名校验、回调解密及 URL 校验解密。
  • 在 `WxCpIntelligentRobotService` 中加入加密回调解析和 `response_url` 回复方法。
  • 回复请求使用 `postWithoutToken`,避免向临时 URL 附加企业应用 `access_token`。
  • 新增加密往返、加密回调解析和无 token 回复的 TestNG 测试。
  • 更新智能机器人文档,区分旧版 access-token 接口与新版 API 模式接入链路。
技术说明:加密层复用 `WxCryptUtil` 的 AES-CBC/PKCS#7 和 SHA-1 签名机制,并将机器人 ID作为加密接收方标识。

🤖 Was this summary useful? React with 👍 or 👎

Copilot AI left a comment

Copy link
Copy Markdown

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 回调解密解析能力,并支持使用回调中的 response_url 进行不带 access_token 的加密回复,同时更新文档以区分旧版 access-token 接口链路与新版 API 模式链路。

Changes:

  • 新增 WxCpIntelligentRobotCryptUtil:基于现有 WxCryptUtil 封装机器人 API 模式 JSON 信封的加解密、签名与 URL 校验解密。
  • 扩展 WxCpIntelligentRobotService / WxCpIntelligentRobotServiceImpl:新增解密回调解析 parseEncryptedCallbackMessage(...)response_url 加密回复 replyMessage(...)(走 postWithoutToken)。
  • 新增针对加解密封装、回调解密解析、response_url 无 token 回复的 TestNG 用例,并更新 INTELLIGENT_ROBOT.md 文档示例。

验证(基于 PR 描述)

  • 已编译新增生产与测试代码;TestNG 3 项测试通过。

剩余风险 / 需要关注点

  • WxCpIntelligentRobotService 作为 public 接口新增非 default 方法,存在对下游自定义实现/Mock 的源码与二进制兼容性风险(见已留评审意见)。

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/crypto/WxCpIntelligentRobotCryptUtil.java 新增机器人 API 模式 JSON 信封加解密工具(签名、encrypt/decrypt/verifyUrl)。
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpIntelligentRobotService.java 新增 API 模式回调解密解析与 response_url 加密回复接口方法。
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpIntelligentRobotServiceImpl.java 实现新增的 API 模式能力,并通过 postWithoutToken 走无 token 通道。
weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/crypto/WxCpIntelligentRobotCryptUtilTest.java 覆盖加密信封可解密回原文的回归单测。
weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpIntelligentRobotApiModeServiceTest.java 覆盖加密回调解析与 response_url 加密回复(mock postWithoutToken)的单测。
weixin-java-cp/INTELLIGENT_ROBOT.md 更新接入文档:区分旧 access-token 与新版 API 模式链路与示例。
docs/superpowers/specs/2026-08-21-cp-intelligent-robot-api-mode-design.md 增加设计说明,明确范围、接口与验证点。
docs/superpowers/plans/2026-08-21-cp-intelligent-robot-api-mode.md 增加实施计划文档(当前存在测试框架/测试类名与实际不一致点)。
Suppressed comments (4)

docs/superpowers/plans/2026-08-21-cp-intelligent-robot-api-mode.md:55

  • Task 2 的测试文件路径/类名与本 PR 实际新增的 API-mode 测试不一致:本次新增的是 WxCpIntelligentRobotApiModeServiceTest,而不是把用例放到 WxCpIntelligentRobotServiceImplTest。建议同步更新该计划文档中的测试文件指向,方便按文档执行验证。
**Files:**
- Modify: `weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpIntelligentRobotService.java`
- Modify: `weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpIntelligentRobotServiceImpl.java`
- Test: `weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpIntelligentRobotServiceImplTest.java`

docs/superpowers/plans/2026-08-21-cp-intelligent-robot-api-mode.md:70

  • 计划文档中运行单测的命令使用了 -Dtest=WxCpIntelligentRobotServiceImplTest,但 API 模式新增用例在 WxCpIntelligentRobotApiModeServiceTest;按当前文档执行会漏跑关键用例。建议改为运行新增的测试类。
Run: `mvn -pl weixin-java-cp -Dtest=WxCpIntelligentRobotServiceImplTest test`
Expected: compilation failure because new service methods do not exist.

docs/superpowers/plans/2026-08-21-cp-intelligent-robot-api-mode.md:79

  • 同上,Step 4 的 PASS 命令也应运行本次新增的 WxCpIntelligentRobotApiModeServiceTest,否则无法验证加密回调解析与 response_url 回复链路。
Run: `mvn -pl weixin-java-cp -Dtest=WxCpIntelligentRobotServiceImplTest test`
Expected: PASS.

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpIntelligentRobotService.java:115

  • 同上,replyMessage 作为新增的非 default 接口方法也会带来实现类二进制不兼容风险。建议改为 default 方法(默认抛 UnsupportedOperationException),由 WxCpIntelligentRobotServiceImpl 提供实际实现。
  String replyMessage(String responseUrl, String plainJson, String token, String encodingAesKey, String aiBotId,
                      String timestamp, String nonce) throws WxErrorException;

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/superpowers/plans/2026-08-21-cp-intelligent-robot-api-mode.md Outdated

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

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

Copy link
Copy Markdown

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: ae7b04e7dd

ℹ️ 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".

@binarywang
binarywang merged commit ade05b7 into develop Aug 22, 2026
1 check passed
@binarywang
binarywang deleted the fix/4099-cp-intelligent-robot-api-mode branch August 22, 2026 03:58
@binarywang binarywang added this to the 4.8.6 milestone Aug 22, 2026
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.

智能机器人与源码中的使用方式对应不上

2 participants