Compare commits

...

10 Commits

Author SHA1 Message Date
b77c99a9ba transfer 2026-04-23 11:30:49 +08:00
a590f1c486 transfer 2025-08-13 14:05:56 +08:00
09d369b50a transfer 2025-08-13 14:02:24 +08:00
7b84fb3b89 transfer 2025-08-13 14:00:53 +08:00
1e6efdcd80 transfer 2025-08-13 13:58:48 +08:00
8e054d0b08 transfer 2025-08-13 13:55:15 +08:00
ae7cc0f1ab transfer 2025-08-13 13:54:33 +08:00
ff37d8f17e transfer 2025-08-13 13:53:48 +08:00
f2e8429286 test 2025-08-13 11:44:39 +08:00
1881a4be5b test 2025-08-13 11:16:34 +08:00
3 changed files with 54 additions and 35 deletions

View File

@ -15,18 +15,15 @@ class Controller extends BaseController
public function test() public function test()
{ {
$trade_no = UtilService::getTradeNo(); $trade_no1 = UtilService::getTradeNo();
$trade_no2 = UtilService::getTradeNo();
$scene_id = config("wechatpay.screen.commission"); $scene_id = config("wechatpay.screen.commission");
$openid = "oPC_2vneOWpQbicNZQAUCxuwZ4mw"; $openid = "oPC_2vneOWpQbicNZQAUCxuwZ4mw";
$amount = 100; $amount = 1;
$remark = "测试"; $remark = "测试";
$res = WechatPayService::officialUserTransfer($trade_no, $scene_id, $openid, $amount, $remark); // $res = WechatPayService::transferBatches($trade_no1, $trade_no2, $openid, $amount, $remark);
dd($res); $res = WechatPayService::mchTransfer($trade_no1, $scene_id, $openid, $amount, $remark);
}
public function getWechatplatformcCert()
{
$res = WechatPayService::getPlatformCert();
dd($res); dd($res);
} }
} }

View File

@ -28,7 +28,6 @@ class WechatPayService
// 从本地文件中加载「微信支付平台证书」可由内置CLI工具下载到用来验证微信支付应答的签名 // 从本地文件中加载「微信支付平台证书」可由内置CLI工具下载到用来验证微信支付应答的签名
$platformCertificateFilePath = 'file://' . config("wechatpay.payment.platform_cert_path"); $platformCertificateFilePath = 'file://' . config("wechatpay.payment.platform_cert_path");
$onePlatformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC); $onePlatformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);
Log::info($onePlatformPublicKeyInstance);
// 「微信支付平台证书」的「平台证书序列号」 // 「微信支付平台证书」的「平台证书序列号」
// 可以从「微信支付平台证书」文件解析,也可以在 商户平台 -> 账户中心 -> API安全 查询到 // 可以从「微信支付平台证书」文件解析,也可以在 商户平台 -> 账户中心 -> API安全 查询到
@ -56,30 +55,11 @@ class WechatPayService
return $instance; 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 * @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))) { if (empty(count($transfer_scene_report_infos))) {
@ -125,6 +105,51 @@ class WechatPayService
} }
} }
/**
* 商家批量转账到零钱
*/
public function transferBatches(string $trade_no, string $trade_no2, string $openid, int $amount, string $remark): array
{
// try {
$appid = config("wechat.official_account.default.app_id");
$data = [
"appid" => $appid,
"out_batch_no" => $trade_no,
"batch_name" => $remark,
"batch_remark" => $remark,
"total_amount" => $amount,
"total_num" => 1,
"transfer_detail_list" => [
[
"out_detail_no" => $trade_no2,
"transfer_amount" => $amount,
"transfer_remark" => $remark,
"openid" => $openid,
]
]
];
Log::info("转账到零钱数据", $data);
$instance = $this->newClient();
$resp = $instance->chain('v3/transfer/batches')->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 * @return void

View File

@ -7,9 +7,7 @@ use Illuminate\Support\Facades\Route;
//ueditor上传 //ueditor上传
Route::prefix("upload")->group(function () { Route::prefix("upload")->group(function () {
Route::get('/ueditor', [CommonController::class, "upload"]); Route::match(["get", "post"], '/ueditor', [CommonController::class, "upload"]);
Route::post('/ueditor', [CommonController::class, "upload"]);
}); });
//微信转账 //微信转账
@ -21,4 +19,3 @@ Route::prefix("transfer")->group(function () {
Route::get("test", [Controller::class, "test"]); Route::get("test", [Controller::class, "test"]);
Route::get("wechat/platform/cert", [Controller::class, "getWechatplatformcCert"]);