修复同城配送接口RSA签名错误(错误码40234) - #3916
Conversation
根据微信官方API签名文档,待签名串格式应为: urlpath\nappid\ntimestamp\npostdata 原代码错误地在payload中包含了rsaKeySn,导致签名验证失败(40234错误)。 修复:从postWithSignature方法的签名payload中移除rsaKeySn字段。 新增:WxMaSignaturePayloadTest单元测试验证签名格式正确性。 Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
🤖 Augment PR SummarySummary: 修复小程序同城配送等接口在启用服务端 API 签名时,因 RSA 待签名串多拼接了
🤖 Was this summary useful? React with 👍 or 👎 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Pull request overview
本 PR 旨在修复微信小程序「服务端 API 签名」的待签名串(payload)拼接格式,使其符合官方文档要求,并尝试通过新增测试来解释/验证该格式。
Changes:
- 修复
postWithSignature的 RSA 签名 payload:移除将rsaKeySn拼入待签名串的逻辑 - 新增
WxMaSignaturePayloadTest,用于验证签名 payload 的换行拼接规则(含/不含rsaKeySn的差异)
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/api/impl/BaseWxMaServiceImpl.java | 调整签名 payload 拼接格式,确保待签名串不再包含 rsaKeySn |
| weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSignaturePayloadTest.java | 新增测试用例,尝试验证 payload 格式与签名验签结果的关系 |
Uh oh!
There was an error while loading. Please reload this page.
binarywang
commented
Mar 10, 2026
@copilot apply changes based on the comments in this thread |
- 将 postWithSignature 中的 payload 拼接逻辑提取为包可见静态方法 buildSignaturePayload - 重写 WxMaSignaturePayloadTest,直接测试生产代码的 payload 格式 - 新测试断言:恰好4个字段、不含rsaKeySn、格式与官方规范完全一致 - 如果将来有人误将 rsaKeySn 加回 payload,测试将立即失败 Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
已按评审意见重构(commit 将 payload 拼接逻辑提取为包可见静态方法
若将来有人误将 |
Uh oh!
There was an error while loading. Please reload this page.
postWithSignaturewas constructing the RSA signing payload with an extrarsaKeySnfield, causing WeChat to reject all intracity API calls with error 40234 (invalid signature).Per the WeChat API signature spec, the signing string must be exactly 4 fields:
Fix
rsaKeySnfrom the RSA signature payload inBaseWxMaServiceImpl#postWithSignature. The serial number is still correctly sent via theWechatmp-Serialrequest header.buildSignaturePayloadinBaseWxMaServiceImpl, enabling direct unit testing of the production logic.Tests
WxMaSignaturePayloadTest: directly callsBaseWxMaServiceImpl.buildSignaturePayloadand asserts:rsaKeySnIf
rsaKeySnis ever mistakenly added back to the payload, these tests will immediately fail, preventing regression.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.