收藏
回答

APIv3发起商家转账接口请求返回结果问题,求指点

参考文档:

https://github.com/wechatpay-apiv3/wechatpay-php/tree/main#%E5%90%8C%E6%AD%A5%E8%AF%B7%E6%B1%82

https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/transfer-batch/initiate-batch-transfer.html

在空目录下  composer require wechatpay/wechatpay,然后新建一个 index.php 如下(不使用任何框架)

 $merchantId,
    'serial'     => $merchantCertificateSerial,
    'privateKey' => $merchantPrivateKeyInstance,
    'certs'      => [
        $platformCertificateSerial => $platformPublicKeyInstance,
    ],
]);

try {
    $resp = $instance
        ->chain('v3/transfer/batches')
        ->post(['json' => [
            'appid' => $confs['appid'],
            'out_batch_no' => 'QKtest' . date('YmdHis') . '1',
            'batch_name' => '请客-1',
            'batch_remark' => '请客-1',
            'total_amount' => 10,
            'total_num' => 1,
            'transfer_detail_list' => [
                [
                    'out_detail_no' => 'qktest' . date('YmdHis') . '1',
                    'transfer_amount' => 10,
                    'transfer_remark' => '请客-1',
                    'openid' => '1234567我的openid',
                ]
            ],
        ]]);
    var_dump($resp->getBody());
} catch (\Exception $e) {
    
}


请求页面得到如下结果(微信零钱确实收到了1毛钱)

object(GuzzleHttp\Psr7\Stream)#52 (7) { ["stream":"GuzzleHttp\Psr7\Stream":private]=> resource(58) of type (stream) ["size":"GuzzleHttp\Psr7\Stream":private]=> NULL ["seekable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["readable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["writable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["uri":"GuzzleHttp\Psr7\Stream":private]=> string(10) "php://temp" ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=> array(0) { } }


根本拿不到文档里的应答参数:

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

1 个回答

  • Memory (私信不回复)
    Memory (私信不回复)
    10-25

    var_dump((string) $resp->getBody());缺类型转换 (string)

    10-25
    有用
    回复
登录 后发表内容