tokumeikoi 4 years ago
parent
commit
dc6317db97

+ 3 - 1
app/Http/Controllers/Admin/PaymentController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\Admin;
 
 use App\Services\PaymentService;
+use App\Utils\Helper;
 use Illuminate\Http\Request;
 use App\Http\Controllers\Controller;
 use App\Models\Payment;
@@ -56,7 +57,8 @@ class PaymentController extends Controller
         if (!Payment::create([
             'name' => $request->input('name'),
             'payment' => $request->input('payment'),
-            'config' => $request->input('config')
+            'config' => $request->input('config'),
+            'uuid' => Helper::guid()
         ])) {
             abort(500, '保存失败');
         }

+ 2 - 2
app/Http/Controllers/Guest/PaymentController.php

@@ -11,10 +11,10 @@ use App\Http\Controllers\Controller;
 
 class PaymentController extends Controller
 {
-    public function notify($method, $id, Request $request)
+    public function notify($method, $uuid, Request $request)
     {
         try {
-            $paymentService = new PaymentService($method, $id);
+            $paymentService = new PaymentService($method, null, $uuid);
             $verify = $paymentService->notify($request->input());
             if (!$verify) abort(500, 'verify error');
             if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {

+ 1 - 1
app/Http/Routes/GuestRoute.php

@@ -21,7 +21,7 @@ class GuestRoute
             // Telegram
             $router->post('/telegram/webhook', 'Guest\\TelegramController@webhook');
             // Payment
-            $router->match(['get', 'post'], '/payment/notify/{method}/{id}', 'Guest\\PaymentController@notify');
+            $router->match(['get', 'post'], '/payment/notify/{method}/{uuid}', 'Guest\\PaymentController@notify');
             // Comm
             $router->get ('/comm/config', 'Guest\\CommController@config');
         });

+ 4 - 2
app/Services/PaymentService.php

@@ -7,17 +7,19 @@ use App\Models\Payment;
 
 class PaymentService
 {
-    public function __construct($method, $id = NULL)
+    public function __construct($method, $id = NULL, $uuid = NULL)
     {
         $this->method = $method;
         $this->class = '\\App\\Payments\\' . $this->method;
         if (!class_exists($this->class)) abort(500, 'gate is not found');
         if ($id) $payment = Payment::find($id)->toArray();
+        if ($uuid) $payment = Payment::where('uuid', $uuid)->first()->toArray();
         $this->config = [];
         if (isset($payment)) {
             $this->config = json_decode($payment['config'], true);
             $this->config['enable'] = $payment['enable'];
             $this->config['id'] = $payment['id'];
+            $this->config['uuid'] = $payment['uuid'];
         };
         $this->payment = new $this->class($this->config);
     }
@@ -31,7 +33,7 @@ class PaymentService
     public function pay($order)
     {
         return $this->payment->pay([
-            'notify_url' => url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['id']}"),
+            'notify_url' => url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}"),
             'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order/' . $order['trade_no'],
             'trade_no' => $order['trade_no'],
             'total_amount' => $order['total_amount'],

+ 2 - 1
database/install.sql

@@ -119,6 +119,7 @@ CREATE TABLE `v2_order` (
 DROP TABLE IF EXISTS `v2_payment`;
 CREATE TABLE `v2_payment` (
                               `id` int(11) NOT NULL AUTO_INCREMENT,
+                              `uuid` char(32) NOT NULL,
                               `payment` varchar(16) NOT NULL,
                               `name` varchar(255) NOT NULL,
                               `config` text NOT NULL,
@@ -346,4 +347,4 @@ CREATE TABLE `v2_user` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 
--- 2021-04-28 08:53:45
+-- 2021-05-06 16:14:04

+ 3 - 0
database/update.sql

@@ -408,3 +408,6 @@ CREATE TABLE `v2_payment` (
 
 ALTER TABLE `v2_order`
     ADD `payment_id` int(11) NULL AFTER `coupon_id`;
+
+ALTER TABLE `v2_payment`
+    ADD `uuid` char(32) NOT NULL AFTER `id`;