Webman easywehcat 6.x 支付回调报错 #2735
Answered
by
reatang
qianshi-tech
asked this question in
Q&A
-
框架:Webman v1.5.8 支付:Easywechat 6.8 官方文档: use EasyWeChat\MiniApp\Application;
use EasyWeChat\Pay\Message;
$app = new Application($config);
$server = $app->getServer();
$server->handlePaid(function (Message $message, \Closure $next) {
// $message->out_trade_no 获取商户订单号
// $message->payer['openid'] 获取支付者 openid
// 注意:推送信息不一定靠谱哈,请务必验证
// 建议是拿订单号调用微信支付查询接口,以查询到的订单状态为准
return $next($message);
});
// 默认返回 ['code' => 'SUCCESS', 'message' => '成功']
return $server->serve(); 这个办法根本无法接收通知内容。一直报错,后来我在webman官方提问有个大佬给我解决了,他的代码: use EasyWeChat\Pay\Application;
use EasyWeChat\Pay\Message;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
$app = new Application($config);
$symfony_request = new SymfonyRequest( $request->get(),$request->post(),[],$request->cookie(),[],[],$request->rawBody() );
$header = $request->header();
$symfony_request->headers = new HeaderBag( $header );
$app->setRequestFromSymfonyRequest($symfony_request);
$server = $app->getServer();
$server->handlePaid(function (Message $message, \Closure $next) {
// $message->out_trade_no 获取商户订单号
// $message->payer['openid'] 获取支付者 openid
// 注意:推送信息不一定靠谱哈,请务必验证
// 建议是拿订单号调用微信支付查询接口,以查询到的订单状态为准
return $next($message);
});
// 默认返回 ['code' => 'SUCCESS', 'message' => '成功']
return $server->serve(); 这个办法解决了问题,可以正常处理业务,但我看日志还是在报错。。。 报错信息: ValueError: max(): Argument #1 ($value) must contain at least one element in /vendor/w7corp/easywechat/src/Kernel/ServerResponse.php(193): max()
default.ERROR: max(): Argument #1 ($value) must contain at least one element [] [] 报错位置: public function __toString(): string
{
$headers = $this->getHeaders();
ksort($headers);
$max = max(array_map('strlen', array_keys($headers))) + 1;
$headersString = '';
foreach ($headers as $name => $values) {
$name = ucwords($name, '-');
foreach ($values as $value) {
$headersString .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
}
}
return sprintf(
'HTTP/%s %s %s',
$this->getProtocolVersion(),
$this->getStatusCode(),
$this->getReasonPhrase()
)."\r\n".
$headersString."\r\n".
$this->getBody();
} 哪位好心大佬帮我看看, 两天多了还没有解决,都不知道哪里出问题, 提前感谢您 。 |
Beta Was this translation helpful? Give feedback.
Answered by
reatang
Aug 18, 2023
Replies: 2 comments 4 replies
-
这个报错很明显呀。$headers 数组是空数组,导致max函数报错了。 给你一个机会提交pr。 |
Beta Was this translation helpful? Give feedback.
1 reply
-
然后,解决你问题的方案就是: // 默认返回 ['code' => 'SUCCESS', 'message' => '成功']
return $server->serve(); 改为:(我也没用过webman,你看着意思改改) // 默认返回 ['code' => 'SUCCESS', 'message' => '成功']
$resp = $server->serve();
return response($resp->getBody(), 200, $resp->getHeaders()); |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
qianshi-tech
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
然后,解决你问题的方案就是:
改为:(我也没用过webman,你看着意思改改)