diff --git a/app/Http/Controllers/Admin/PaymentController.php b/app/Http/Controllers/Admin/PaymentController.php index 159ab41b..2efb0ec1 100644 --- a/app/Http/Controllers/Admin/PaymentController.php +++ b/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, '保存失败'); } diff --git a/app/Http/Controllers/Guest/PaymentController.php b/app/Http/Controllers/Guest/PaymentController.php index 7daea11d..8e2ca8a2 100644 --- a/app/Http/Controllers/Guest/PaymentController.php +++ b/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'])) { diff --git a/app/Http/Routes/GuestRoute.php b/app/Http/Routes/GuestRoute.php index f79fc3d5..13d4a338 100644 --- a/app/Http/Routes/GuestRoute.php +++ b/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'); }); diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 90903852..862358f2 100644 --- a/app/Services/PaymentService.php +++ b/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'], diff --git a/database/install.sql b/database/install.sql index 10aca6ba..eee4b460 100644 --- a/database/install.sql +++ b/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 diff --git a/database/update.sql b/database/update.sql index 407a9099..5a89cce2 100644 --- a/database/update.sql +++ b/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`;