This commit is contained in:
Hankin 2025-08-13 13:53:48 +08:00
parent f2e8429286
commit ff37d8f17e
3 changed files with 47 additions and 29 deletions

View File

@ -20,13 +20,7 @@ class Controller extends BaseController
$openid = "oPC_2vneOWpQbicNZQAUCxuwZ4mw";
$amount = 100;
$remark = "测试";
$res = WechatPayService::officialUserTransfer($trade_no, $scene_id, $openid, $amount, $remark);
dd($res);
}
public function getWechatplatformcCert()
{
$res = WechatPayService::getPlatformCert();
$res = WechatPayService::transferBatches($trade_no, $scene_id, $openid, $amount, $remark);
dd($res);
}
}

View File

@ -55,30 +55,11 @@ class WechatPayService
return $instance;
}
public function getPlatformCert()
{
try {
$instance = $this->newClient();
$resp = $instance->chain('v3/certificates')->get(
/** @see https://docs.guzzlephp.org/en/stable/request-options.html#debug */
// ['debug' => true] // 调试模式
);
return $resp->getBody();
} catch (\Exception $e) {
// 进行异常捕获并进行错误判断处理
Log::info($e->getMessage());
if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
return $resp->getBody();
}
return $e->getTraceAsString();
}
}
/**
* 转账零钱
* 商家转账
* @return void
*/
public function officialUserTransfer(string $trade_no, string $scene_id, string $openid, int $amount, string $remark, array $transfer_scene_report_infos = []): array
public function mchTransfer(string $trade_no, string $scene_id, string $openid, int $amount, string $remark, array $transfer_scene_report_infos = []): array
{
// 发送请求
if (empty(count($transfer_scene_report_infos))) {
@ -124,6 +105,50 @@ class WechatPayService
}
}
/**
* 商家批量转账到零钱
*/
public function transferBatches(string $trade_no, string $scene_id, string $openid, int $amount, string $remark): array
{
try {
$appid = config("wechat.official_account.default.app_id");
$data = [
"appid" => $appid,
"out_bill_no" => $trade_no,
"transfer_scene_id" => (string) $scene_id,
"batch_name" => $remark,
"batch_remark" => $remark,
"total_amount" => $amount,
"total_num" => 1,
"transfer_detail_list" => [
"out_detail_no" => $trade_no,
"transfer_amount" => $amount,
"transfer_remark" => $remark,
"openid" => $openid,
]
];
Log::info("转账到零钱数据", $data);
$instance = $this->newClient();
$resp = $instance->chain('v3/transfer/batche')->post([
"json" => $data
]);
$res = json_decode($resp->getBody(), true);
dd($res);
} catch (\Exception $e) {
// 进行异常捕获并进行错误判断处理
Log::info($e->getMessage());
if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
$r = $e->getResponse();
$res = json_decode($r->getBody());
return ["code" => 1, "err_msg" => $r->getBody()];
}
return ["code" => 1, "err_msg" => $e->getMessage()];
}
}
/**
* 转账银行卡
* @return void

View File

@ -21,4 +21,3 @@ Route::prefix("transfer")->group(function () {
Route::get("test", [Controller::class, "test"]);
Route::get("wechat/platform/cert", [Controller::class, "getWechatplatformcCert"]);