2023-11-07 13:48:04 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace wchat\wx\V3;
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
use JetBrains\PhpStorm\ArrayShape;
|
|
|
|
|
use Kiri\Client;
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
$client = new Client('api.mch.weixin.qq.com', 443, TRUE);
|
|
|
|
|
$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();
|
|
|
|
|
|
|
|
|
|
return json_decode($client->getBody(), TRUE);
|
|
|
|
|
}
|
|
|
|
|
}
|