完善微信小程序消息推送(安全模式)JSON 入参的验签解密能力#4069
Conversation
There was a problem hiding this comment.
Pull request overview
该 PR 针对 weixin-java-miniapp 中小程序消息推送“安全模式”场景,补齐 WxMaMessage 对 JSON 入参 的“验签 + 解密”能力,使其与现有 XML 处理能力对齐,减少调用方自行提取 Encrypt 与验签的负担。
Changes:
- 为
WxMaMessage新增带timestamp/nonce/msgSignature的fromEncryptedJson(...)重载,走WxMaCryptUtils.decryptContent(...)完成签名校验与解密。 - 增加对应的单测覆盖 JSON 安全模式成功路径与签名失败路径。
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaMessage.java | 新增 JSON 安全模式“验签+解密”重载入口(String/InputStream)。 |
| weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaMessageTest.java | 补充 JSON 安全模式验签通过与签名不匹配异常用例。 |
🤖 Augment PR SummarySummary: 补齐 Changes:
Technical Notes: 保留原有 2 参数重载的“仅解密”行为以确保兼容性。 🤖 Was this summary useful? React with 👍 or 👎 |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot 修复编译报错 Exited with code exit status 1 |
已修复。根本原因是新增方法使用了错误的缩进导致多了一个 修复内容(commit
|
当前
WxMaMessage对安全模式 XML 已支持“验签+解密”,但 JSON 仅支持解密,导致调用方需要手工提取Encrypt并自行验签。该变更补齐 JSON 与 XML 在安全模式下的能力对齐,支持直接完成来源校验与解密。变更一:补充 JSON 安全模式重载(验签 + 解密)
WxMaMessage新增 5 参数重载:fromEncryptedJson(String encryptedJson, WxMaConfig config, String timestamp, String nonce, String msgSignature)fromEncryptedJson(InputStream inputStream, WxMaConfig config, String timestamp, String nonce, String msgSignature)Encrypt后复用WxMaCryptUtils.decryptContent(...),按token/timestamp/nonce/msgSignature完成签名校验并解密。变更二:保持兼容
fromEncryptedJson(String/InputStream, WxMaConfig)保持不变,继续提供“仅解密”行为,不影响既有调用。变更三:补充针对性用例
示例调用: