Skip to content

docs: clarify that micropay sign/appid/nonceStr are auto-filled by the SDK - #152

Merged
binarywang merged 4 commits into
masterfrom
copilot/fix-wxpay-signature-issue
Mar 6, 2026
Merged

docs: clarify that micropay sign/appid/nonceStr are auto-filled by the SDK#152
binarywang merged 4 commits into
masterfrom
copilot/fix-wxpay-signature-issue

Conversation

Copilot AI commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Users calling wxPayService.micropay() were getting "签名错误" after manually computing and setting sign via SignUtils — which conflicts with the SDK's own signing logic.

Changes

  • Extended the WxPayController#micropay Javadoc to explicitly state that appid, mch_id, nonce_str, and sign are populated automatically from merchant config; manually setting them (especially sign) causes signature failures
  • Added a minimal usage example showing only the fields callers need to set:
WxPayMicropayRequest request = new WxPayMicropayRequest();
request.setBody("商品描述");
request.setOutTradeNo("商户系统内部订单号");
request.setTotalFee(100);          // 单位:分
request.setSpbillCreateIp("终端IP");
request.setAuthCode("用户付款码");
WxPayMicropayResult result = wxPayService.micropay(request);
Original prompt

This section details on the original issue you should resolve

<issue_title>付款码支付 WxPayMicropayRequest 中的签名,怎么弄的?</issue_title>
<issue_description>How do I get a payment code to pay a signature in WxPayMicropayRequest?

Version 4.8.0

String nonceStr = IdUtil.fastSimpleUUID();

WxPayMicropayRequest request = new WxPayMicropayRequest();
request.setAppid(wxPayService.getConfig().getAppId());
request.setMchId(wxPayService.getConfig().getMchId());
request.setNonceStr(nonceStr);
request.setBody(body);
request.setOutTradeNo(outTradeNo);
request.setTotalFee(totalFee);
request.setSpbillCreateIp(ip);
request.setAuthCode(authCode);


HashMap<String,String> map = new HashMap<>();
map.put("appid",wxPayService.getConfig().getAppId());
map.put("mch_id",wxPayService.getConfig().getMchId());
map.put("nonce_str",nonceStr);
map.put("body",body);
map.put("out_trade_no",outTradeNo);
map.put("total_fee",totalFee.toString());
map.put("spbill_create_ip",ip);
map.put("auth_code",authCode);

String[] ignoredParams = new String[]{};
String sign = SignUtils.createSign(map, "", apiV2Key, ignoredParams);

request.setSign(sign); 

WxPayMicropayResult micropayResult = wxPayService.micropay(request);

----报错-----

返回代码:[FAIL],返回信息:[签名错误,请检查后再试],微信返回的原始报文:
<return_code></return_code>
<return_msg></return_msg>

@binarywang 签名部分能给个例子吗?谢谢🙏</issue_description>

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


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…xample

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix signature generation for WxPayMicropayRequest docs: clarify that micropay sign/appid/nonceStr are auto-filled by the SDK Feb 22, 2026
Copilot AI requested a review from binarywang February 22, 2026 03:11
@binarywang
binarywang marked this pull request as ready for review March 6, 2026 04:19
Copilot AI review requested due to automatic review settings March 6, 2026 04:19

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

This PR clarifies the micropay API usage in the demo controller docs to prevent callers from manually setting SDK-managed common fields (especially sign), which can lead to signature failures.

Changes:

  • Expanded WxPayController#micropay Javadoc to state appid/mch_id/nonce_str/sign are auto-filled and signed by the SDK.
  • Added a minimal WxPayMicropayRequest usage example showing only required business fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/com/github/binarywang/demo/wx/pay/controller/WxPayController.java Outdated
Comment thread src/main/java/com/github/binarywang/demo/wx/pay/controller/WxPayController.java Outdated
binarywang and others added 2 commits March 6, 2026 12:23
…ayController.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ayController.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@binarywang
binarywang merged commit a760276 into master Mar 6, 2026
@binarywang
binarywang deleted the copilot/fix-wxpay-signature-issue branch March 6, 2026 04:24
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.

付款码支付 WxPayMicropayRequest 中的签名,怎么弄的?

3 participants