From 89e553dced7575fe82bc5b647f1fcb21c6420b12 Mon Sep 17 00:00:00 2001 From: Hankin Date: Tue, 12 Aug 2025 17:34:04 +0800 Subject: [PATCH] test --- app/Http/Controllers/Controller.php | 6 ++++++ app/Services/WechatPayService.php | 24 ++++++++++++++++-------- routes/util/api.php | 2 ++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 9900f06..ba0c979 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -23,4 +23,10 @@ class Controller extends BaseController $res = WechatPayService::officialUserTransfer($trade_no, $scene_id, $openid, $amount, $remark); dd($res); } + + public function getWechatplatformcCert() + { + $res = WechatPayService::getPlatformCert(); + dd($res); + } } diff --git a/app/Services/WechatPayService.php b/app/Services/WechatPayService.php index 7fc20d6..e409306 100644 --- a/app/Services/WechatPayService.php +++ b/app/Services/WechatPayService.php @@ -25,20 +25,20 @@ class WechatPayService $merchantCertificateSerial = config("wechatpay.payment.serial"); // 从本地文件中加载「微信支付平台证书」,可由内置CLI工具下载到,用来验证微信支付应答的签名 - $platformCertificateFilePath = 'file://' . config("wechatpay.payment.platform_cert_path"); - $onePlatformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC); + // $platformCertificateFilePath = 'file://' . config("wechatpay.payment.platform_cert_path"); + // $onePlatformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC); // 「微信支付平台证书」的「平台证书序列号」 // 可以从「微信支付平台证书」文件解析,也可以在 商户平台 -> 账户中心 -> API安全 查询到 - $platformCertificateSerial = config("wechatpay.payment.platform_cert_serial"); + // $platformCertificateSerial = config("wechatpay.payment.platform_cert_serial"); // // 从本地文件中加载「微信支付公钥」,用来验证微信支付应答的签名 - // $platformPublicKeyFilePath = 'file://' . config("wechatpay.payment.public_key_path"); - // $twoPlatformPublicKeyInstance = Rsa::from($platformPublicKeyFilePath, Rsa::KEY_TYPE_PUBLIC); + $platformPublicKeyFilePath = 'file://' . config("wechatpay.payment.public_key_path"); + $twoPlatformPublicKeyInstance = Rsa::from($platformPublicKeyFilePath, Rsa::KEY_TYPE_PUBLIC); // // 「微信支付公钥」的「微信支付公钥ID」 // // 需要在 商户平台 -> 账户中心 -> API安全 查询 - // $platformPublicKeyId = config("wechatpay.payment.public_key_id"); + $platformPublicKeyId = config("wechatpay.payment.public_key_id"); // 构造一个 APIv3 客户端实例 $instance = Builder::factory([ @@ -46,13 +46,21 @@ class WechatPayService 'serial' => $merchantCertificateSerial, 'privateKey' => $merchantPrivateKeyInstance, 'certs' => [ - $platformCertificateSerial => $onePlatformPublicKeyInstance, - // $platformPublicKeyId => $twoPlatformPublicKeyInstance, + // $platformCertificateSerial => $onePlatformPublicKeyInstance, + $platformPublicKeyId => $twoPlatformPublicKeyInstance, ], ]); return $instance; } + public function getPlatformCert() + { + $instance = $this->newClient(); + $resp = $instance->chain('v3/fund-app/mch-transfer/transfer-bills')->get(); + $res = json_decode($resp->getBody(), true); + dd($res); + } + /** * 转账零钱 * @return void diff --git a/routes/util/api.php b/routes/util/api.php index 57e90a3..ca55c0a 100644 --- a/routes/util/api.php +++ b/routes/util/api.php @@ -20,3 +20,5 @@ Route::prefix("transfer")->group(function () { }); Route::get("test", [Controller::class, "test"]); + +Route::get("wechat/platform/cert", [Controller::class, "getWechatplatformcCert"]);