The cURL request was retried 3 times and did not succeed. The most likely reason for the failure is that cURL was unable to rewind the body of the request and subsequent retries resulted in the same error. Turn on the debug option to see what went wrong. See https://bugs.php.net/bug.php?id=47204 for more information."
而且文档https://gitee.com/TheNorthMemory/wechatpay-php/blob/v1.1/README.md中说的用
'mchid' => '1900000109',// 注意这个商户号,key是`mchid`非`mch_id`
我用mchid,报错,加上了mch_id又报上面的错误了, 麻烦解答一下这个问题,感谢
<?php /** * 向微信用户个人付款(同步模式) * @param array<string,mixed> $options * @link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 */ public function post(array $options = [ 'xml' => [ 'mch_appid' => 'wx8888888888888888', 'mchid' => '1900000109', 'device_info' => '013467007045764', 'partner_trade_no' => '10000098201411111234567890', 'openid' => 'oxTWIuGaIt6gTKsQRLau2M0yL16E', 'check_name' => 'FORCE_CHECK', 're_user_name' => '王小王', 'amount' => '10099', 'desc' => '理赔', 'spbill_create_ip' => '192.168.0.1', 'scene' => 'BRAND_REDPACKET', 'brand_id' => '1234', 'finder_template_id' => '1243100000000000', ], 'security' => true, ]): ResponseInterface;
https://github.com/TheNorthMemory/wechatpay-openapi/blob/b20adb4e541969bc99eda0f6241ca2c3a8ef56c2/src/V2/Mmpaymkttransfers/Promotion/Transfers.php#L13-L35
参数示例如上,问题来了,你是怎么请求的?
修正APIv2上,转账至用户零钱接口,xml入参是mchid引发的不适问题;
增加APIv2上转账至用户零钱接口测试用例,样例说明如何进行异常捕获;
另外你需要安装至少v1.1.1版本
use WeChatPay\Transformer;
$res = $instance
->v2->mmpaymkttransfers->promotion->transfers
->postAsync([
'xml' => [
'mch_appid' => 'wx8888888888888888',
'mchid' => '1900000109',// 注意这个商户号,key是`mchid`非`mch_id`
'partner_trade_no' => '10000098201411111234567890',
'openid' => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
'check_name' => 'FORCE_CHECK',
're_user_name' => '王小王',
'amount' => 10099,
'desc' => '理赔',
'spbill_create_ip' => '192.168.0.1',
],
'security' => true,
'debug' => true //开启调试模式
])
->then(static function($response) {
return Transformer::toArray((string)$response->getBody());
})
->otherwise(static function($e) {
if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
return Transformer::toArray((string)$e->getResponse()->getBody());
}
return [];
})
->wait();
print_r($res);
问题就在于,企业付款到零钱是需要加载商户rsa私钥及证书,未加载到的时候请求就会失败,进而引发重试失败,所以你需要排查Builder::factory([‘merchant’ => []]) 中的 cert 及 key 文件路径是否可以访问到。
另外建议使用一个Linux环境做开发调试,在Windows上也可以尝试docker,已知在windows上跑php有许多莫名其妙的问题无法解决。
<?php
/**
* This function ensures that a response was set on a transaction. If one
* was not set, then the request is retried if possible. This error
* typically means you are sending a payload, curl encountered a
* "Connection died, retrying a fresh connect" error, tried to rewind the
* stream, and then encountered a "necessary data rewind wasn't possible"
* error, causing the request to be sent through curl_multi_info_read()
* without an error status.
*
* @param callable(RequestInterface, array): PromiseInterface $handler
*/
$ctx['error'] = 'The cURL request was retried 3 times '
. 'and did not succeed. The most likely reason for the failure '
. 'is that cURL was unable to rewind the body of the request '
. 'and subsequent retries resulted in the same error. Turn on '
. 'the debug option to see what went wrong. See '
. 'https://bugs.php.net/bug.php?id=47204 for more information.';
<?php
->postAsync([
//...
'xml' => [/**/],
'security' => true,
'retries' => 0,//关闭Guzzle重试
]);