微信平台收付通,请求分账接口一直报错:请求参数错误
微信平台收付通(分账)-请求分账接口一直报错:请求参数错误。
严格按照文档要求的参数,严格按照官方提供PHP版本SDK,
已经添加分账接收方,已经添加合单支付标识。
为啥还一直报参数错误,我应该怎么排查错误
PHP代码如下:
public function profitsharing($params){
try {
// 硬编码测试数据
$requestData = [
'sub_mchid' => '1709441164', // 二级商户号
'transaction_id' => '4343102484202503116409408407', // 微信支付订单号
'out_order_no' => '4343102484202503116409408407', // 系统自定义订单号
'receivers' => [
[
'type' => 'MERCHANT_ID',
'receiver_account' => '1704664915', // 接收方商户号
'amount' => 3, // 3元=300分
'description' => '测试分账'
]
],
'finish' => false // 是否完成分账
];
$debug = json_encode($requestData, JSON_UNESCAPED_UNICODE);
// 添加调试日志
Log::debug('分账请求原始数据:'.$debug );
// 请求头配置
$headers = [
'Wechatpay-Serial' => config('pay.wechatpay.platform_serial_no'),
'Accept' => 'application/json',
'Content-Type' => 'application/json'
];
// 发起请求
$response = $this->wechatPayClient
->chain('v3/ecommerce/profitsharing/orders')
->post([
'json' => $requestData,
'headers' => $headers,
'verify' => false // 生产环境验证证书
]);
// Log::debug('分账响应详情', json_decode($response, true));
return json_decode((string)$response->getBody(), true);
} catch (\Throwable $e) {
// 解析具体错误
$errorInfo = [
'message' => $e->getMessage(),
'code' => $e->getCode()
];
if ($e instanceof RequestException && $e->hasResponse()) {
$response = $e->getResponse();
$errorInfo['status_code'] = $response->getStatusCode();
$errorInfo['headers'] = $response->getHeaders();
$errorInfo['response'] = (string)$response->getBody();
}
Log::error('分账异常详情', $errorInfo);
throw new Exception('分账请求失败: '.$e->getMessage());
}
}
apipost测试返回结果如下:
[2025-03-11T11:40:19+08:00][debug] 分账请求原始数据:{"sub_mchid":"1709441164","transaction_id":"4343102484202503116409408407","out_order_no":"4343102484202503116409408407","receivers":[{"type":"MERCHANT_ID","receiver_account":"1704664915","amount":6,"description":"测试分账"}],"finish":false}
[2025-03-11T11:40:19+08:00][error] 分账异常详情
[2025-03-11T11:40:19+08:00][error] [0]分账请求失败: Client error: `POST https://api.mch.weixin.qq.com/v3/ecommerce/profitsharing/orders` resulted in a `400 Bad Request` response:
{"code":"PARAM_ERROR","message":"请求参数错误"}