收藏
回答

微信平台收付通,请求分账接口一直报错:请求参数错误

微信平台收付通(分账)-请求分账接口一直报错:请求参数错误。
严格按照文档要求的参数,严格按照官方提供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":"请求参数错误"}


最后一次编辑于  03-11
回答关注问题邀请回答
收藏

2 个回答

  • Memory
    Memory
    03-11

    APPID呢?

    03-11
    有用 2
    回复
  • 与中同行
    与中同行
    03-11

    请求分账文档:微信分配的公众账号ID是选填,但实际是这个appid是必填项,感谢!

    appid  选填 string(32)

    【微信分配的公众账号ID】微信分配的公众账号ID

    因为文档写的选填,之前添加了后来请求接口报参数错误,又去掉后请求接口还是报参数参数。刚刚我又添加了appid。请求接口成功返回:
    
    {
        "status": 1000,
        "msg": "",
        "data": {
            "order_id": "30001909912025031183873449929",
            "out_order_no": "4343102484202503116409408407",
            "receivers": [
                {
                    "amount": 3,
                    "description": "测试分账",
                    "detail_id": "36001909912025031119786248039",
                    "finish_time": "2025-03-11T13:24:54+08:00",
                    "receiver_account": "1704664915",
                    "receiver_mchid": "1704664915",
                    "result": "SUCCESS",
                    "type": "MERCHANT_ID"
                }
            ],
            "status": "FINISHED",
            "sub_mchid": "1709441164",
            "transaction_id": "4343102484202503116409408407"
        },
        "refresh_ticket": ""
    }
    
    03-11
    有用 1
    回复
登录 后发表内容