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
支付回调getRequestMessage()报Invalid request body错误 #2737
Comments
你接收到的推送请求可能不来自微信,而是一些恶意请求 |
这个链接跳转到了 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_16 这个页面,而商户中心前台文档中心里面进去的是这个链接 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_11.shtml ,看到区别是前者是 api,后者是 apiv3 ,打开的文档页面前者是 xml,后者是 JSON |
在微信开放社区里面搜到了相关问题:通过微信支付商户平台设置的退款结果回调通知走的是APIV2协议? |
输出(appid、mch_id、nonce_str 已脱敏处理)
easywechat/src/Pay/Server.php
WeChatController
|
所以它妈的,这帮人真的推送的XML…… |
我也是看得简直无语了,开放社区提出来都快两年半了,还没搞一个APIV3的填写框,报错调了一整天各种蒙圈,我还一直在想如果后台手动处理的退款该怎么去推到系统里。原来是微信那边这个回调推送还是用的APIV2的XML,服了服了 |
改一下试试: if (str_starts_with($originContent, '<xml')) {
$attributes = Xml::parse($originContent);
} else {
$attributes = json_decode($originContent, true);
} |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
到这里卡住了,不知道怎么解决了。 [2023-08-27 01:23:56] local.ERROR: openssl_decrypt(): IV passed is 32 bytes long which is longer than the 0 expected by selected cipher, truncating {"exception":"[object] (ErrorException(code: 0): openssl_decrypt(): IV passed is 32 bytes long which is longer than the 0 expected by selected cipher, truncating at {laravel_path}\vendor\w7corp\easywechat\src\Kernel\Support\AesEcb.php:35) 相关代码: Server.php
EasyWeChat\Kernel\Support\AesEcb
好奇怪为什么是预期0长度,网上搜到的openssl_decrypt是预期16长度,也试了stackoverflow 这个 hex2bin 方案,依然报 openssl_decrypt(): IV passed is 16 bytes long which is longer than the 0 expected by selected cipher 错误,这里这个openssl_decrypt为什么要求0长度的IV值?我如果IV值传空字符串的话,解密就失败了。 |
AesEcb::decrypt(
$attributes['req_info'],
md5($this->merchant->getV2SecretKey()),
), 这样试试? |
[2023-08-27 13:39:32] local.ERROR: error:1C800064:Provider routines::bad decrypt {"exception":"[object] (EasyWeChat\Kernel\Exceptions\InvalidArgumentException(code: 0): error:1C800064:Provider routines::bad decrypt at {laravel_path}\vendor\w7corp\easywechat\src\Kernel\Support\AesEcb.php:44)
|
解决了,最终解决方案是: // 建议使用单独的路由处理退款!
$server = $app->getServer();
// 推送消息,已解密
// 结构参考:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_16&index=10
$message = $server->getReqeustMessage();
// 你的逻辑...
// 返回 SUCCESS 或者 FAIL 等其他状态
return new \Nyholm\Psr7\Response(
200, [],
\EasyWeChat\Kernel\Support\Xml::build([
'return_code' => 'SUCCESS',
'return_msg' => 'OK'
])
); |
我用的环境
问题及现象
支付回调
getRequestMessage()
报Invalid request body
错误,从{laravel_path}\\vendor\\w7corp\\easywechat\\src\\Pay\\Server.php(117)
抛出,此错误可被 try catch 捕获,但是return ['code' => 'SUCCESS', 'message' => '成功'];
后微信仍然会一直重新发起通知。BeforeMiddleware中打印的请求日志:
抛出的错误日志
日志:
堆栈跟踪:
相关代码块
{laravel_path}\vendor\w7corp\easywechat\src\Pay\Server.php(117)
{laravel_path}\app\Http\Controllers\WeChatController.php(68): EasyWeChat\Pay\Server->getRequestMessage()
BeforeMiddleware
The text was updated successfully, but these errors were encountered: