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

微信小程序支付签名错误 #206

Closed
deweizhu opened this issue Mar 11, 2020 · 5 comments
Closed

微信小程序支付签名错误 #206

deweizhu opened this issue Mar 11, 2020 · 5 comments

Comments

@deweizhu
Copy link

deweizhu commented Mar 11, 2020

你好,反馈一下,最新版5.x的微信小程序支付签名算法有误。
最多5个参数,参与签名算法。我用以下代码通过测试。

//签名要自己做,集成的SDK 5.x有BUG
$param = [
'appId' => $this->wxconfig['app_id'],
'nonceStr' => $ret['nonce_str'],
'package' => 'prepay_id=' . $ret['prepay_id'],
'signType' => $this->wxconfig['sign_type'],
'timeStamp' => TIMENOW,
];
$signStr = http_build_query($param, PHP_QUERY_RFC3986, '&');
$signStr = str_replace('%3D', '=', $signStr);
$signStr .= '&key=' . $this->wxconfig['md5_key'];
$sign = strtoupper(hash_hmac('sha256', $signStr, $this->wxconfig['md5_key']));

@helei112g
Copy link
Owner

helei112g commented Mar 15, 2020

你这个签名方式是从哪里来的呢?我看微信文档并没有说明需要 http_build_query并进行替换。

https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3

@deweizhu
Copy link
Author

你这个签名方式是从哪里来的呢?我看微信文档并没有说明需要 http_build_query并进行替换。

https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3

我是参考 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=5 编写的,http_build_query和手写foreach效果一样的,替换是因为http_build_query会把prepay_id=编码为prepay_id%3D 导致签名前的字符串有误。

@helei112g
Copy link
Owner

这个与我参考的文档是一致。
你确定只有小程序有问题?其它正常?

@deweizhu
Copy link
Author

这个与我参考的文档是一致。
你确定只有小程序有问题?其它正常?

我只用小程序支付,其它的没试过。

@helei112g
Copy link
Owner

目前我这里并不能复现(不知道是否跟我用的测试账号有关系);我会持续关注这个问题

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

No branches or pull requests

2 participants