完善微信小程序消息推送(安全模式)JSON 入参的验签解密能力#4069
Open
binarywang with Copilot wants to merge 2 commits into
Open
Conversation
Copilot
AI
changed the title
[WIP] Fix incomplete support for JSON data in message push
完善微信小程序消息推送(安全模式)JSON 入参的验签解密能力
Jul 15, 2026
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 安全模式验签通过与签名不匹配异常用例。 |
Comment on lines
+641
to
+650
| public static WxMaMessage fromEncryptedJson(String encryptedJson, WxMaConfig config, | ||
| String timestamp, String nonce, String msgSignature) { | ||
| try { | ||
| WxMaMessage encryptedMessage = fromJson(encryptedJson); | ||
| String plainText = new WxMaCryptUtils(config).decryptContent(msgSignature, timestamp, nonce, | ||
| encryptedMessage.getEncrypt()); | ||
| return fromJson(plainText); | ||
| } catch (Exception e) { | ||
| throw new WxRuntimeException(e); | ||
| } |
🤖 Augment PR SummarySummary: 补齐 Changes:
Technical Notes: 保留原有 2 参数重载的“仅解密”行为以确保兼容性。 🤖 Was this summary useful? React with 👍 or 👎 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
当前
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)保持不变,继续提供“仅解密”行为,不影响既有调用。变更三:补充针对性用例
示例调用: