From 8135c6942e458d14550d805af4af1d83f913a6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Sat, 18 Dec 2021 11:57:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Controllers/WeChatPayController.php | 23 +++++++++++++++++++ app/Endpoint/Callback/routes.php | 9 ++++---- app/Providers/AppServiceProvider.php | 15 ++++++++++++ app/Services/WeChatPayService.php | 12 ++++++++++ config/settings.php | 3 +++ 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 app/Endpoint/Callback/Http/Controllers/WeChatPayController.php diff --git a/app/Endpoint/Callback/Http/Controllers/WeChatPayController.php b/app/Endpoint/Callback/Http/Controllers/WeChatPayController.php new file mode 100644 index 00000000..4af543a5 --- /dev/null +++ b/app/Endpoint/Callback/Http/Controllers/WeChatPayController.php @@ -0,0 +1,23 @@ +handlePaidNotify(function ($message, $fail) { + logger()->debug('wechat notify', $message); + + return true; + }); + } +} diff --git a/app/Endpoint/Callback/routes.php b/app/Endpoint/Callback/routes.php index fb69c598..3bd4ad4e 100644 --- a/app/Endpoint/Callback/routes.php +++ b/app/Endpoint/Callback/routes.php @@ -1,10 +1,9 @@ 'v1', -], function () { - Route::post('kuaidi100', [Kuaidi100Controller::class, 'callback']); -}); +Route::post('kuaidi100', [Kuaidi100Controller::class, 'callback']); +// 微信支付通知 +Route::post('wxpay/paid-notify', [WeChatPayController::class, 'paidNotify'])->name('wxpay.paid_notify'); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3126c855..97ea6236 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,6 +2,8 @@ namespace App\Providers; +use EasyWeChat\Factory as EasyWeChatFactory; +use EasyWeChat\Payment\Application as EasyWeChatPaymentApplication; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; @@ -18,6 +20,7 @@ class AppServiceProvider extends ServiceProvider public function register() { $this->registerEasySms(); + $this->registerEasyWeChat(); $this->registerRequestRealIp(); } @@ -35,6 +38,18 @@ class AppServiceProvider extends ServiceProvider JsonResource::withoutWrapping(); } + /** + * 注册微信服务 + * + * @return void + */ + protected function registerEasyWeChat() + { + $this->app->singleton(EasyWeChatPaymentApplication::class, function ($app) { + return EasyWeChatFactory::payment($app['config']->get('wechat.payment.default')); + }); + } + /** * 注册短信发送服务 * diff --git a/app/Services/WeChatPayService.php b/app/Services/WeChatPayService.php index 5ab563c3..87ef6542 100644 --- a/app/Services/WeChatPayService.php +++ b/app/Services/WeChatPayService.php @@ -3,6 +3,7 @@ namespace App\Services; use App\Exceptions\WeChatPayException; +use Closure; use EasyWeChat\Factory; use EasyWeChat\Payment\Application; @@ -87,4 +88,15 @@ class WeChatPayService return $this->app->jssdk->bridgeConfig($prepayId, false); } + + /** + * 支付结果通知 + * + * @param \Closure $closure + * @return \Symfony\Component\HttpFoundation\Response + */ + public function handlePaidNotify(Closure $closure) + { + return $this->app->handlePaidNotify($closure); + } } diff --git a/config/settings.php b/config/settings.php index ab2c2403..9f83f19b 100644 --- a/config/settings.php +++ b/config/settings.php @@ -1,6 +1,9 @@ '子春生', + // 订单支付过期时间(秒) 'order_payment_expires_at' => 1800,