50 lines
1.6 KiB
PHP
50 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 string $orderNo
|
|
* @param int $total
|
|
* @param string $openId
|
|
* @return array
|
|
* @throws Exception
|
|
*/
|
|
#[ArrayShape(['code_url' => "string"])]
|
|
public function request(string $orderNo, int $total, string $openId): array
|
|
{
|
|
$body['appid'] = $this->getConfig()->getAppid();
|
|
$body['out_trade_no'] = $orderNo;
|
|
$body["batch_name"] = $this->getConfig()->getBody();
|
|
$body["batch_remark"] = $this->getConfig()->getBody();
|
|
$body["total_amount"] = $total;
|
|
$body["total_num"] = 1;
|
|
$body["transfer_detail_list"] = [
|
|
[
|
|
"out_detail_no" => $orderNo,
|
|
"transfer_amount" => $total,
|
|
"transfer_remark" => $this->getConfig()->getBody(),
|
|
"openid" => $openId,
|
|
]
|
|
];
|
|
|
|
$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)
|
|
->post('/v3/transfer/batches');
|
|
$client->close();
|
|
|
|
return json_decode($client->getBody(), TRUE);
|
|
}
|
|
} |