Files
kiri-wchat/wchat/wx/V3/TransferBatches.php
T
2023-11-07 15:13:11 +08:00

46 lines
1.6 KiB
PHP

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