Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 28, 2025

微信小程序同城配送接口(如 querystore)配置签名密钥后返回 invalid signature (40234)。根本原因是签名 payload 和请求头缺少 RSA 私钥序列号。

修复内容

  • 签名 payload 补全:根据微信API签名文档,payload 格式应为 url_path\nappid\ntimestamp\nsn\nrequest_body,原实现缺少 sn
  • 请求头补全:添加缺失的 Wechatmp-Serial
  • 参数校验:增加 rsaKeySn 空值检查,提前暴露配置问题
// Before
String payload = urlPath + "\n" + appId + "\n" + timestamp + "\n" + requestJson;

// After  
String payload = urlPath + "\n" + appId + "\n" + timestamp + "\n" + rsaKeySn + "\n" + requestJson;
header.put("Wechatmp-Serial", rsaKeySn);

Fixes #3719

Original prompt

This section details on the original issue you should resolve

<issue_title>微信小程序同城配送功能配置签名密钥后,请求时报签名错误。</issue_title>
<issue_description>错误代码:40234, 错误信息:invalid signature rid: 684a2fb9-71ed0bf0-4715707f,微信原始报文:{"errcode":40234,"errmsg":"invalid signature rid: 684a2fb9-71ed0bf0-4715707f"}

简要描述

微信小程序同城配送功能配置签名密钥后,请求时报签名错误。

模块版本情况

  • WxJava 模块名: wx-java-miniapp-spring-boot-starter
  • WxJava 版本号: 4.7.0

详细描述

在使用微信小程序的同城配送功能时(获取小程序下所有门店),已正确配置签名密钥,但请求到小程序时返回签名错误。

具体情况:

  1. 已在小程序后台正确配置同城配送的签名密钥
  2. 调用 https://api.weixin.qq.com/cgi-bin/express/intracity/querystore 接口
  3. 请求中已按照文档要求设置了 ApiSignatureRsaPrivateKey、ApiSignatureAesKey、ApiSignatureAesKeySn、ApiSignatureRsaPrivateKeySn、WechatMpAppid 等
  4. ApiSignatureRsaPrivateKey 也已经按照要求通过OpenSSL 将 pkcs1 转换为 pkcs8
  5. 但仍然返回 40234 错误码,提示 invalid signature尝试过的解决方法:
  6. 检查密钥配置多次,确认密钥正确
  7. 尝试重新生成签名

Image
Image
</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: 自定义的
需要用中文


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix invalid signature error for WeChat delivery feature 修复微信小程序同城配送API签名错误(错误代码40234) Nov 28, 2025
Copilot AI requested a review from binarywang November 28, 2025 14:00
Copilot finished work on behalf of binarywang November 28, 2025 14:00
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