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

44 lines
1.1 KiB
PHP
Raw Normal View History

2022-09-09 16:42:55 +08:00
<?php
namespace wchat\wx\V3;
use Exception;
use wchat\wx\SmallProgram;
class WxV3AppPayment extends SmallProgram
{
2023-11-07 15:13:11 +08:00
use WxV3PaymentTait;
/**
2023-11-14 14:10:36 +08:00
* @param string $orderNo
2023-11-07 15:13:11 +08:00
* @param int $total
* @param string|null $openId
* @param string $payer_client_ip
* @return array
2023-12-12 15:35:37 +08:00
* @throws
2023-11-07 15:13:11 +08:00
*/
2025-07-14 18:34:14 +08:00
public function payment(string $orderNo, int $total, ?string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array
2023-11-07 15:13:11 +08:00
{
$body = $this->getInitCore($orderNo, $total);
$body['scene_info'] = ['payer_client_ip' => $payer_client_ip];
$sign = $this->signature('POST', '/v3/pay/transactions/components', $json = json_encode($body, JSON_UNESCAPED_UNICODE));
2023-11-13 21:20:10 +08:00
$client = $this->createClient($sign, $json);
2023-11-07 15:13:11 +08:00
$client->post('/v3/pay/transactions/components');
$client->close();
2026-06-12 23:57:22 +08:00
$json = json_decode($client->body, TRUE);
2023-11-07 15:13:11 +08:00
if (!isset($json['prepay_id'])) {
throw new Exception('微信支付调用失败');
}
return $this->createResponse($json, $body);
}
2022-09-09 16:42:55 +08:00
}