mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 17:31:49 +08:00 
			
		
		
		
	update: payment add custom notify domain name
This commit is contained in:
		| @@ -26,7 +26,12 @@ class PaymentController extends Controller | |||||||
|     { |     { | ||||||
|         $payments = Payment::all(); |         $payments = Payment::all(); | ||||||
|         foreach ($payments as $k => $v) { |         foreach ($payments as $k => $v) { | ||||||
|             $payments[$k]['notify_url'] = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}"); |             $notifyUrl = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}"); | ||||||
|  |             if ($v->notify_domain) { | ||||||
|  |                 $parseUrl = parse_url($notifyUrl); | ||||||
|  |                 $notifyUrl = $v->notify_domain . $parseUrl['path']; | ||||||
|  |             } | ||||||
|  |             $payments[$k]['notify_url'] = $notifyUrl; | ||||||
|         } |         } | ||||||
|         return response([ |         return response([ | ||||||
|             'data' => $payments |             'data' => $payments | ||||||
| @@ -58,22 +63,20 @@ class PaymentController extends Controller | |||||||
|                 'data' => true |                 'data' => true | ||||||
|             ]); |             ]); | ||||||
|         } |         } | ||||||
|         $request->validate([ |         $params = $request->validate([ | ||||||
|             'name' => 'required', |             'name' => 'required', | ||||||
|  |             'icon' => 'nullable', | ||||||
|             'payment' => 'required', |             'payment' => 'required', | ||||||
|             'config' => 'required' |             'config' => 'required', | ||||||
|  |             'notify_domain' => 'nullable|url' | ||||||
|         ], [ |         ], [ | ||||||
|             'name.required' => '显示名称不能为空', |             'name.required' => '显示名称不能为空', | ||||||
|             'payment.required' => '网关参数不能为空', |             'payment.required' => '网关参数不能为空', | ||||||
|             'config.required' => '配置参数不能为空' |             'config.required' => '配置参数不能为空', | ||||||
|  |             'notify_domain.url' => '自定义通知域名格式有误' | ||||||
|         ]); |         ]); | ||||||
|         if (!Payment::create([ |         $params['uuid'] = Helper::randomChar(8); | ||||||
|             'name' => $request->input('name'), |         if (!Payment::create($params)) { | ||||||
|             'icon' => $request->input('icon'), |  | ||||||
|             'payment' => $request->input('payment'), |  | ||||||
|             'config' => $request->input('config'), |  | ||||||
|             'uuid' => Helper::randomChar(8) |  | ||||||
|         ])) { |  | ||||||
|             abort(500, '保存失败'); |             abort(500, '保存失败'); | ||||||
|         } |         } | ||||||
|         return response([ |         return response([ | ||||||
|   | |||||||
| @@ -32,25 +32,16 @@ class MGate { | |||||||
|                 'label' => 'AppSecret', |                 'label' => 'AppSecret', | ||||||
|                 'description' => '', |                 'description' => '', | ||||||
|                 'type' => 'input', |                 'type' => 'input', | ||||||
|             ], |  | ||||||
|             'notify_domain' => [ |  | ||||||
|                 'label' => '通知域名(选填)', |  | ||||||
|                 'description' => '用于接收来自网关的支付通知', |  | ||||||
|                 'type' => 'input' |  | ||||||
|             ] |             ] | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public function pay($order) |     public function pay($order) | ||||||
|     { |     { | ||||||
|         if (isset($this->config['notify_domain'])) { |  | ||||||
|             $parseUrl = parse_url($order['notify_url']); |  | ||||||
|             $notifyUrl = "{$parseUrl['scheme']}://{$this->config['notify_domain']}{$parseUrl['path']}"; |  | ||||||
|         } |  | ||||||
|         $params = [ |         $params = [ | ||||||
|             'out_trade_no' => $order['trade_no'], |             'out_trade_no' => $order['trade_no'], | ||||||
|             'total_amount' => $order['total_amount'], |             'total_amount' => $order['total_amount'], | ||||||
|             'notify_url' => $notifyUrl ?? $order['notify_url'], |             'notify_url' => $order['notify_url'], | ||||||
|             'return_url' => $order['return_url'] |             'return_url' => $order['return_url'] | ||||||
|         ]; |         ]; | ||||||
|         $params['app_id'] = $this->config['mgate_app_id']; |         $params['app_id'] = $this->config['mgate_app_id']; | ||||||
|   | |||||||
| @@ -26,6 +26,7 @@ class PaymentService | |||||||
|             $this->config['enable'] = $payment['enable']; |             $this->config['enable'] = $payment['enable']; | ||||||
|             $this->config['id'] = $payment['id']; |             $this->config['id'] = $payment['id']; | ||||||
|             $this->config['uuid'] = $payment['uuid']; |             $this->config['uuid'] = $payment['uuid']; | ||||||
|  |             $this->config['notify_domain'] = $payment['notify_domain']; | ||||||
|         }; |         }; | ||||||
|         $this->payment = new $this->class($this->config); |         $this->payment = new $this->class($this->config); | ||||||
|         if (isset($this->payment->customResult)) $this->customResult = $this->payment->customResult; |         if (isset($this->payment->customResult)) $this->customResult = $this->payment->customResult; | ||||||
| @@ -39,8 +40,15 @@ class PaymentService | |||||||
|  |  | ||||||
|     public function pay($order) |     public function pay($order) | ||||||
|     { |     { | ||||||
|  |         // custom notify domain name | ||||||
|  |         $notifyUrl = url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}"); | ||||||
|  |         if ($this->config['notify_domain']) { | ||||||
|  |             $parseUrl = parse_url($notifyUrl); | ||||||
|  |             $notifyUrl = $this->config['notify_domain'] . $parseUrl['path']; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         return $this->payment->pay([ |         return $this->payment->pay([ | ||||||
|             'notify_url' => url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}"), |             'notify_url' => $notifyUrl, | ||||||
|             'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order/' . $order['trade_no'], |             'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order/' . $order['trade_no'], | ||||||
|             'trade_no' => $order['trade_no'], |             'trade_no' => $order['trade_no'], | ||||||
|             'total_amount' => $order['total_amount'], |             'total_amount' => $order['total_amount'], | ||||||
|   | |||||||
| @@ -144,6 +144,7 @@ CREATE TABLE `v2_payment` ( | |||||||
|                               `name` varchar(255) NOT NULL, |                               `name` varchar(255) NOT NULL, | ||||||
|                               `icon` varchar(255) DEFAULT NULL, |                               `icon` varchar(255) DEFAULT NULL, | ||||||
|                               `config` text NOT NULL, |                               `config` text NOT NULL, | ||||||
|  |                               `notify_domain` varchar(128) DEFAULT NULL, | ||||||
|                               `enable` tinyint(1) NOT NULL DEFAULT '0', |                               `enable` tinyint(1) NOT NULL DEFAULT '0', | ||||||
|                               `sort` int(11) DEFAULT NULL, |                               `sort` int(11) DEFAULT NULL, | ||||||
|                               `created_at` int(11) NOT NULL, |                               `created_at` int(11) NOT NULL, | ||||||
| @@ -389,4 +390,4 @@ CREATE TABLE `v2_user` ( | |||||||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||||||
|  |  | ||||||
|  |  | ||||||
| -- 2022-02-19 16:59:30 | -- 2022-02-23 07:42:04 | ||||||
|   | |||||||
| @@ -504,3 +504,7 @@ CREATE TABLE `v2_stat_user` ( | |||||||
|                                 `updated_at` int(11) NOT NULL, |                                 `updated_at` int(11) NOT NULL, | ||||||
|                                 PRIMARY KEY (`id`) |                                 PRIMARY KEY (`id`) | ||||||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ALTER TABLE `v2_payment` | ||||||
|  |     ADD `notify_domain` varchar(128) COLLATE 'utf8mb4_general_ci' NULL AFTER `config`; | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								public/assets/admin/umi.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								public/assets/admin/umi.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Reference in New Issue
	
	Block a user