Files
kiri-wchat/wchat/wx/V3/TransferBatches.php
T

52 lines
1.7 KiB
PHP
Raw Normal View History

2023-11-07 13:48:04 +08:00
<?php
namespace wchat\wx\V3;
use Exception;
use JetBrains\PhpStorm\ArrayShape;
use Kiri\Client;
2023-11-07 15:55:50 +08:00
use Kiri\CurlClient;
2023-11-07 13:48:04 +08:00
use wchat\wx\SmallProgram;
class TransferBatches extends SmallProgram
{
use WxV3PaymentTait;
/**
2023-11-07 14:02:43 +08:00
* @param TransferDetail $detail
2023-11-07 13:48:04 +08:00
* @return array
* @throws Exception
*/
#[ArrayShape(['code_url' => "string"])]
2023-11-07 14:02:43 +08:00
public function request(TransferDetail $detail): array
2023-11-07 13:48:04 +08:00
{
2023-11-07 15:17:59 +08:00
$body = [];
2023-11-07 13:48:04 +08:00
$body['appid'] = $this->getConfig()->getAppid();
2023-11-07 14:02:43 +08:00
$body['out_trade_no'] = $detail->out_detail_no;
2023-11-07 13:48:04 +08:00
$body["batch_name"] = $this->getConfig()->getBody();
$body["batch_remark"] = $this->getConfig()->getBody();
2023-11-07 14:02:43 +08:00
$body["total_amount"] = $detail->transfer_amount;
2023-11-07 13:48:04 +08:00
$body["total_num"] = 1;
2023-11-07 15:17:59 +08:00
$body["transfer_detail_list"] = [$detail->toArray()];
2023-11-07 13:48:04 +08:00
$sign = $this->signature('POST', '/v3/transfer/batches', $json = json_encode($body, JSON_UNESCAPED_UNICODE));
2023-11-07 15:55:50 +08:00
$client = new CurlClient('api.mch.weixin.qq.com', 443, TRUE);
2023-11-07 13:48:04 +08:00
$client->withAddedHeader('Authorization', $sign)->withContentType('application/json')
2023-11-07 15:13:11 +08:00
->withAgent('application/json')->withBody($json)->withAddedHeader("Accept", "*/*");
2023-11-07 15:14:25 +08:00
2023-11-07 15:13:11 +08:00
$proxyHost = $this->getConfig()->getProxyHost();
$proxyPort = $this->getConfig()->getProxyPort();
if (!empty($proxyHost) && $proxyPort > 0) {
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
}
2023-11-07 15:17:59 +08:00
2023-11-07 15:13:11 +08:00
$client->post('/v3/transfer/batches');
2023-11-07 13:48:04 +08:00
$client->close();
2023-11-07 15:56:53 +08:00
var_dump($client);
2023-11-07 13:48:04 +08:00
return json_decode($client->getBody(), TRUE);
}
}