Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信支付结果通知接口请求signType为空时默认为统一下单时的signType,若统一下单时使用HMAC-SHA256签名会导致验签失败 #1585

Closed
joewee opened this issue May 26, 2020 · 7 comments

Comments

@joewee
Copy link

joewee commented May 26, 2020

简要描述

微信支付结果通知接口请求signType为空时默认为统一下单时的signType,若统一下单时使用HMAC-SHA256签名,支付结果通知请求中signType为空,若采用微信官方文档上所说采用MD5验签会导致验签失败。

模块版本情况

  • WxJava 模块名: weixin-java-pay
  • WxJava 版本号: 3.8.0

详细描述

支付通知报文:

<xml><appid><![CDATA[wxbabdf7a3a9acdfef]]></appid>
<bank_type><![CDATA[OTHERS]]></bank_type>
<cash_fee><![CDATA[1]]></cash_fee>
<fee_type><![CDATA[CNY]]></fee_type>
<is_subscribe><![CDATA[N]]></is_subscribe>
<mch_id><![CDATA[1583165551]]></mch_id>
<nonce_str><![CDATA[1590477937689]]></nonce_str>
<openid><![CDATA[oWeP25T9OE1ixbLUgN0DxMuSZ6N4]]></openid>
<out_trade_no><![CDATA[20052615250005]]></out_trade_no>
<result_code><![CDATA[SUCCESS]]></result_code>
<return_code><![CDATA[SUCCESS]]></return_code>
<sign><![CDATA[8172FF692C2606339C2C80B371F5695BAC78A52CBB64883F9A02B1C7A28B847C]]></sign>
<time_end><![CDATA[20200526152550]]></time_end>
<total_fee>1</total_fee>
<trade_type><![CDATA[JSAPI]]></trade_type>
<transaction_id><![CDATA[4200000540202005267407409907]]></transaction_id>
</xml>

日志

产生异常:
com.github.binarywang.wxpay.exception.WxPayException: 参数格式校验错误!
at com.github.binarywang.wxpay.bean.result.BaseWxPayResult.checkResult(BaseWxPayResult.java:331)
at com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult.checkResult(WxPayOrderNotifyResult.java:324)
at com.github.binarywang.wxpay.service.impl.BaseWxPayServiceImpl.parseOrderNotifyResult(BaseWxPayServiceImpl.java:158)

@binarywang
Copy link
Member

你自己指定的请求时的签名是 HMAC-SHA256 吗?

@joewee
Copy link
Author

joewee commented May 26, 2020

是的,统一下单时指定了HMAC-SHA256 @binarywang

@joewee
Copy link
Author

joewee commented May 26, 2020

现在微信接口实际情况和文档上好像有差异,支付通知的签名好像是用的统一下单时用的签名类型

@binarywang
Copy link
Member

这真是够坑爹的

@joewee joewee changed the title 微信支付结果通知接口官方文档显示signType为空默认MD5但是实际接口返回好像是HMAC-SHA256导致验签失败 微信支付结果通知接口请求signType为空时默认为统一下单时的signType,若统一下单时使用HMAC-SHA256签名会导致验签失败 May 26, 2020
@binarywang
Copy link
Member

建议先换签名类型为md5,解决此问题

@joewee
Copy link
Author

joewee commented May 26, 2020

我已经改为MD5了,我的想法也是增加个重载方法指定signType。另外或者默认为空时从config中取signType,但是好像这样不能完全解决这个问题 @binarywang

@binarywang
Copy link
Member

我已经增加了个重载方法,你可以看看最新代码,如果有更好的方法,欢迎随时提交PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants