Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 895988cf27 | |||
| 87c597c3fe | |||
| f536b12f00 | |||
| d3b0f436fa | |||
| f5b6bd54f4 | |||
| 59a3b45c77 | |||
| dd96d653d1 | |||
| 97d1c32310 | |||
| d7733525bc | |||
| 62e57b99a0 | |||
| 24655a4644 |
+4
-3
@@ -19,9 +19,10 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">= 8.0",
|
"php": ">= 8.4",
|
||||||
"game-worker/kiri-client": "~v2.0",
|
"game-worker/kiri-client": "^v2.5",
|
||||||
"psr/container": "*"
|
"psr/container": "*",
|
||||||
|
"ext-openssl": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"swoole/ide-helper": "@dev"
|
"swoole/ide-helper": "@dev"
|
||||||
|
|||||||
@@ -0,0 +1,228 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace wchat\wx\V3\Libs;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class TransferDetail
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
private string $out_bill_no;
|
||||||
|
private string $transfer_scene_id;
|
||||||
|
private string $openid;
|
||||||
|
private string $user_name = '';
|
||||||
|
private int $transfer_amount;
|
||||||
|
private string $transfer_remark;
|
||||||
|
private string $notify_url = '';
|
||||||
|
private string $user_recv_perception = '';
|
||||||
|
private array $transfer_scene_report_infos;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getOutBillNo(): string
|
||||||
|
{
|
||||||
|
return $this->out_bill_no;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $out_bill_no
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setOutBillNo(string $out_bill_no): void
|
||||||
|
{
|
||||||
|
$this->out_bill_no = $out_bill_no;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTransferSceneId(): string
|
||||||
|
{
|
||||||
|
return $this->transfer_scene_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $transfer_scene_id
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTransferSceneId(string $transfer_scene_id): void
|
||||||
|
{
|
||||||
|
$this->transfer_scene_id = $transfer_scene_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getOpenid(): string
|
||||||
|
{
|
||||||
|
return $this->openid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $openid
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setOpenid(string $openid): void
|
||||||
|
{
|
||||||
|
$this->openid = $openid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserName(): string
|
||||||
|
{
|
||||||
|
return $this->user_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $user_name
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUserName(string $user_name): void
|
||||||
|
{
|
||||||
|
$this->user_name = $user_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getTransferAmount(): int
|
||||||
|
{
|
||||||
|
return $this->transfer_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $transfer_amount
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTransferAmount(int $transfer_amount): void
|
||||||
|
{
|
||||||
|
$this->transfer_amount = $transfer_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTransferRemark(): string
|
||||||
|
{
|
||||||
|
return $this->transfer_remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $transfer_remark
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTransferRemark(string $transfer_remark): void
|
||||||
|
{
|
||||||
|
$this->transfer_remark = $transfer_remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getNotifyUrl(): string
|
||||||
|
{
|
||||||
|
return $this->notify_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $notify_url
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setNotifyUrl(string $notify_url): void
|
||||||
|
{
|
||||||
|
$this->notify_url = $notify_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserRecvPerception(): string
|
||||||
|
{
|
||||||
|
return $this->user_recv_perception;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $user_recv_perception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUserRecvPerception(string $user_recv_perception): void
|
||||||
|
{
|
||||||
|
$this->user_recv_perception = $user_recv_perception;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<TransferSceneReportInfo>
|
||||||
|
*/
|
||||||
|
public function getTransferSceneReportInfos(): array
|
||||||
|
{
|
||||||
|
return $this->transfer_scene_report_infos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $transfer_scene_report_infos
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTransferSceneReportInfos(TransferSceneReportInfo ...$transfer_scene_report_infos): void
|
||||||
|
{
|
||||||
|
$this->transfer_scene_report_infos = $transfer_scene_report_infos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function toArray(): array
|
||||||
|
{
|
||||||
|
$transfer_scene_report_infos = [];
|
||||||
|
foreach ($this->transfer_scene_report_infos as $transfer_scene_report_info) {
|
||||||
|
$transfer_scene_report_infos[] = $transfer_scene_report_info->toArray();
|
||||||
|
}
|
||||||
|
$array = [
|
||||||
|
'out_bill_no' => $this->out_bill_no,
|
||||||
|
'transfer_scene_id' => $this->transfer_scene_id,
|
||||||
|
'openid' => $this->openid,
|
||||||
|
'transfer_amount' => $this->transfer_amount,
|
||||||
|
'transfer_remark' => $this->transfer_remark,
|
||||||
|
'transfer_scene_report_infos' => $transfer_scene_report_infos,
|
||||||
|
];
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
if (empty($value)) {
|
||||||
|
throw new Exception('必填项' . $key . '不能为空.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($this->user_name)) {
|
||||||
|
$array['user_name'] = $this->user_name;
|
||||||
|
}
|
||||||
|
if (!empty($this->notify_url)) {
|
||||||
|
$array['notify_url'] = $this->notify_url;
|
||||||
|
}
|
||||||
|
if (!empty($this->user_recv_perception)) {
|
||||||
|
$array['user_recv_perception'] = $this->user_recv_perception;
|
||||||
|
}
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace wchat\wx\V3\Libs;
|
||||||
|
|
||||||
|
use Arrayable;
|
||||||
|
|
||||||
|
readonly class TransferSceneReportInfo implements Arrayable
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public string $info_type,
|
||||||
|
public string $info_content,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
"info_type" => $this->info_type,
|
||||||
|
"info_content" => $this->info_content
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace wchat\wx\V3;
|
|
||||||
|
|
||||||
use JetBrains\PhpStorm\ArrayShape;
|
|
||||||
use wchat\wx\SmallProgram;
|
|
||||||
|
|
||||||
class TransferBatches extends SmallProgram
|
|
||||||
{
|
|
||||||
use WxV3PaymentTait;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $transfer_scene_id
|
|
||||||
* @param array $transfer_scene_report_infos
|
|
||||||
* @param TransferDetail $detail
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
#[ArrayShape([])]
|
|
||||||
public function transfer(string $transfer_scene_id ,array $transfer_scene_report_infos ,TransferDetail $detail): array
|
|
||||||
{
|
|
||||||
$payConfig = $this->getPayConfig();
|
|
||||||
$body = [];
|
|
||||||
if ($payConfig->typeIsApp()) {
|
|
||||||
$body['appid'] = $payConfig->pay->wx->appId;
|
|
||||||
} else {
|
|
||||||
$body['appid'] = $payConfig->appId;
|
|
||||||
}
|
|
||||||
$body['out_batch_no'] = $detail->out_detail_no;
|
|
||||||
$body["batch_name"] = $payConfig->getBody();
|
|
||||||
$body["body"] = $payConfig->getBody();
|
|
||||||
$body["batch_remark"] = $payConfig->getBody();
|
|
||||||
$body["total_amount"] = $detail->transfer_amount;
|
|
||||||
$body["total_num"] = 1;
|
|
||||||
$body["transfer_scene_id"] = $transfer_scene_id;
|
|
||||||
$body["transfer_scene_report_infos"] = $transfer_scene_report_infos;
|
|
||||||
$body["transfer_detail_list"] = [$detail->toArray()];
|
|
||||||
|
|
||||||
$sign = $this->signature('POST' ,'/v3/transfer/batches' ,$json = json_encode($body ,JSON_UNESCAPED_UNICODE));
|
|
||||||
|
|
||||||
$client = $this->createClient($sign ,$json);
|
|
||||||
$client->post('/v3/transfer/batches');
|
|
||||||
$client->close();
|
|
||||||
|
|
||||||
$data = json_decode($client->getBody() ,TRUE);
|
|
||||||
if (json_last_error() != JSON_ERROR_NONE) {
|
|
||||||
return ['code' => $client->getStatusCode() ,'message' => $client->getBody()];
|
|
||||||
} else {
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace wchat\wx\V3;
|
|
||||||
|
|
||||||
use JetBrains\PhpStorm\ArrayShape;
|
|
||||||
|
|
||||||
class TransferDetail
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $out_detail_no
|
|
||||||
* @param int|float $transfer_amount
|
|
||||||
* @param string $transfer_remark
|
|
||||||
* @param string $openid
|
|
||||||
* @param string $user_name
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
public string $out_detail_no,
|
|
||||||
public int|float $transfer_amount,
|
|
||||||
public string $transfer_remark,
|
|
||||||
public string $openid,
|
|
||||||
public string $user_name = ''
|
|
||||||
)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
#[ArrayShape(['out_detail_no' => "string", 'transfer_amount' => "float|int", 'transfer_remark' => "string", 'openid' => "string", 'user_name' => "string"])]
|
|
||||||
public function toArray(): array
|
|
||||||
{
|
|
||||||
if (empty($this->user_name)) {
|
|
||||||
return [
|
|
||||||
'out_detail_no' => $this->out_detail_no,
|
|
||||||
'transfer_amount' => $this->transfer_amount,
|
|
||||||
'transfer_remark' => $this->transfer_remark,
|
|
||||||
'openid' => $this->openid,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
return [
|
|
||||||
'out_detail_no' => $this->out_detail_no,
|
|
||||||
'transfer_amount' => $this->transfer_amount,
|
|
||||||
'transfer_remark' => $this->transfer_remark,
|
|
||||||
'openid' => $this->openid,
|
|
||||||
'user_name' => $this->user_name,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,7 @@ class WxV3AppPayment extends SmallProgram
|
|||||||
* @return array
|
* @return array
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function payment(string $orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array
|
public function payment(string $orderNo, int $total, ?string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array
|
||||||
{
|
{
|
||||||
$body = $this->getInitCore($orderNo, $total);
|
$body = $this->getInitCore($orderNo, $total);
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class WxV3NativePayment extends SmallProgram
|
|||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
#[ArrayShape(['code_url' => "string"])]
|
#[ArrayShape(['code_url' => "string"])]
|
||||||
public function payment(string $orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array
|
public function payment(string $orderNo, int $total, ?string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array
|
||||||
{
|
{
|
||||||
$body = $this->getInitCore($orderNo, $total);
|
$body = $this->getInitCore($orderNo, $total);
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class WxV3Payment extends SmallProgram
|
|||||||
* @return array
|
* @return array
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function payment(string $orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array
|
public function payment(string $orderNo, int $total, ?string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array
|
||||||
{
|
{
|
||||||
$body = $this->getInitCore($orderNo, $total);
|
$body = $this->getInitCore($orderNo, $total);
|
||||||
$body['payer'] = ['openid' => $openId];
|
$body['payer'] = ['openid' => $openId];
|
||||||
|
|||||||
@@ -63,10 +63,14 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
$this->lineFeed($inWechatpayTimestamp, $inWechatpayNonce, $inBody),
|
$this->lineFeed($inWechatpayTimestamp, $inWechatpayNonce, $inBody),
|
||||||
$inWechatpaySignature,
|
$inWechatpaySignature,
|
||||||
$platformPublicKeyInstance);
|
$platformPublicKeyInstance);
|
||||||
|
|
||||||
|
$this->decode($this->resource['ciphertext'], $this->resource['nonce'], $this->resource['associated_data']);
|
||||||
|
|
||||||
if (!$timeOffsetStatus || !$verifiedStatus) {
|
if (!$timeOffsetStatus || !$verifiedStatus) {
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return $this->decode($this->resource['ciphertext'], $this->resource['nonce'], $this->resource['associated_data']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -168,4 +172,4 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace wchat\wx\V3;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use JetBrains\PhpStorm\ArrayShape;
|
||||||
|
use Kiri;
|
||||||
|
use wchat\wx\SmallProgram;
|
||||||
|
use wchat\wx\V3\Libs\TransferDetail;
|
||||||
|
|
||||||
|
class WxV3Transfer extends SmallProgram
|
||||||
|
{
|
||||||
|
use WxV3PaymentTait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransferDetail $detail
|
||||||
|
* @return array<'out_bill_no', 'transfer_bill_no', 'create_time', 'state'>
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
#[ArrayShape([])]
|
||||||
|
public function transfer(TransferDetail $detail): array
|
||||||
|
{
|
||||||
|
$payConfig = $this->getPayConfig();
|
||||||
|
$body = $detail->toArray();
|
||||||
|
if ($payConfig->typeIsApp()) {
|
||||||
|
$body['appid'] = $payConfig->pay->wx->appId;
|
||||||
|
} else {
|
||||||
|
$body['appid'] = $payConfig->appId;
|
||||||
|
}
|
||||||
|
$sign = $this->signature('POST', '/v3/fund-app/mch-transfer/transfer-bills', $json = json_encode($body, JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
|
$client = $this->createClient($sign, $json);
|
||||||
|
$client->post('/v3/fund-app/mch-transfer/transfer-bills');
|
||||||
|
$client->close();
|
||||||
|
|
||||||
|
Kiri::getLogger()->println($client->getBody());
|
||||||
|
|
||||||
|
if ($client->getStatusCode() == 200) {
|
||||||
|
return json_decode($client->getBody(), TRUE);
|
||||||
|
}
|
||||||
|
throw new Exception('转账申请发起失败');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,8 +4,8 @@ namespace wchat\wx\V3;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use JetBrains\PhpStorm\ArrayShape;
|
use JetBrains\PhpStorm\ArrayShape;
|
||||||
use Kiri\Client;
|
|
||||||
use wchat\wx\SmallProgram;
|
use wchat\wx\SmallProgram;
|
||||||
|
use wchat\wx\V3\Libs\TransferDetail;
|
||||||
|
|
||||||
class WxV3Withdrawal extends SmallProgram
|
class WxV3Withdrawal extends SmallProgram
|
||||||
{
|
{
|
||||||
@@ -66,4 +66,34 @@ class WxV3Withdrawal extends SmallProgram
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransferDetail $detail
|
||||||
|
* @return array<'out_bill_no', 'transfer_bill_no', 'create_time', 'state'>
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
#[ArrayShape([])]
|
||||||
|
public function transfer(TransferDetail $detail): array
|
||||||
|
{
|
||||||
|
$payConfig = $this->getPayConfig();
|
||||||
|
$body = $detail->toArray();
|
||||||
|
if ($payConfig->typeIsApp()) {
|
||||||
|
$body['appid'] = $payConfig->pay->wx->appId;
|
||||||
|
} else {
|
||||||
|
$body['appid'] = $payConfig->appId;
|
||||||
|
}
|
||||||
|
$sign = $this->signature('POST', '/v3/fund-app/mch-transfer/transfer-bills', $json = json_encode($body, JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
|
$client = $this->createClient($sign, $json);
|
||||||
|
$client->post('/v3/fund-app/mch-transfer/transfer-bills');
|
||||||
|
$client->close();
|
||||||
|
|
||||||
|
Kiri::getLogger()->println($client->getBody());
|
||||||
|
|
||||||
|
if ($client->getStatusCode() == 200) {
|
||||||
|
return json_decode($client->getBody(), TRUE);
|
||||||
|
}
|
||||||
|
throw new Exception('转账申请发起失败');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user