参考文档:
https://github.com/wechatpay-apiv3/wechatpay-php/tree/main#%E5%90%8C%E6%AD%A5%E8%AF%B7%E6%B1%82
在空目录下 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) { } }
根本拿不到文档里的应答参数:
var_dump((string) $resp->getBody());缺类型转换 (string)