From 69c85983d1f353099bd12e26d33e09059ccc7725 Mon Sep 17 00:00:00 2001 From: v2board Date: Fri, 8 Dec 2023 15:27:33 +0800 Subject: [PATCH] update: add custom subscribe path --- app/Http/Controllers/V1/Admin/ConfigController.php | 1 + app/Http/Controllers/V1/Admin/UserController.php | 6 +++--- app/Http/Controllers/V1/User/KnowledgeController.php | 2 +- app/Http/Controllers/V1/User/UserController.php | 4 ++-- app/Http/Requests/Admin/ConfigSave.php | 1 + app/Http/Routes/V1/ClientRoute.php | 7 ++++++- app/Protocols/Surfboard.php | 2 +- app/Protocols/Surge.php | 1 - app/Utils/Helper.php | 4 +++- 9 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/V1/Admin/ConfigController.php b/app/Http/Controllers/V1/Admin/ConfigController.php index 2a8a40aa..a17fa3b2 100755 --- a/app/Http/Controllers/V1/Admin/ConfigController.php +++ b/app/Http/Controllers/V1/Admin/ConfigController.php @@ -92,6 +92,7 @@ class ConfigController extends Controller 'app_description' => config('v2board.app_description', 'V2Board is best!'), 'app_url' => config('v2board.app_url'), 'subscribe_url' => config('v2board.subscribe_url'), + 'subscribe_path' => config('v2board.subscribe_path'), 'try_out_plan_id' => (int)config('v2board.try_out_plan_id', 0), 'try_out_hour' => (int)config('v2board.try_out_hour', 1), 'tos_url' => config('v2board.tos_url'), diff --git a/app/Http/Controllers/V1/Admin/UserController.php b/app/Http/Controllers/V1/Admin/UserController.php index c5c3e866..c442c534 100644 --- a/app/Http/Controllers/V1/Admin/UserController.php +++ b/app/Http/Controllers/V1/Admin/UserController.php @@ -74,7 +74,7 @@ class UserController extends Controller $res[$i]['plan_name'] = $plan[$k]['name']; } } - $res[$i]['subscribe_url'] = Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $res[$i]['token']); + $res[$i]['subscribe_url'] = Helper::getSubscribeUrl($res[$i]['token']); } return response([ 'data' => $res, @@ -165,7 +165,7 @@ class UserController extends Controller $transferEnable = $user['transfer_enable'] ? $user['transfer_enable'] / 1073741824 : 0; $notUseFlow = (($user['transfer_enable'] - ($user['u'] + $user['d'])) / 1073741824) ?? 0; $planName = $user['plan_name'] ?? '无订阅'; - $subscribeUrl = Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user['token']); + $subscribeUrl = Helper::getSubscribeUrl($user['token']); $data .= "{$user['email']},{$balance},{$commissionBalance},{$transferEnable},{$notUseFlow},{$expireDate},{$planName},{$subscribeUrl}\r\n"; } echo "\xEF\xBB\xBF" . $data; @@ -240,7 +240,7 @@ class UserController extends Controller $expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']); $createDate = date('Y-m-d H:i:s', $user['created_at']); $password = $request->input('password') ?? $user['email']; - $subscribeUrl = Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user['token']); + $subscribeUrl = Helper::getSubscribeUrl($user['token']); $data .= "{$user['email']},{$password},{$expireDate},{$user['uuid']},{$createDate},{$subscribeUrl}\r\n"; } echo $data; diff --git a/app/Http/Controllers/V1/User/KnowledgeController.php b/app/Http/Controllers/V1/User/KnowledgeController.php index a1e485bd..ea3f1873 100644 --- a/app/Http/Controllers/V1/User/KnowledgeController.php +++ b/app/Http/Controllers/V1/User/KnowledgeController.php @@ -24,7 +24,7 @@ class KnowledgeController extends Controller if (!$userService->isAvailable($user)) { $this->formatAccessData($knowledge['body']); } - $subscribeUrl = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); + $subscribeUrl = Helper::getSubscribeUrl($user['token']); $knowledge['body'] = str_replace('{{siteName}}', config('v2board.app_name', 'V2Board'), $knowledge['body']); $knowledge['body'] = str_replace('{{subscribeUrl}}', $subscribeUrl, $knowledge['body']); $knowledge['body'] = str_replace('{{urlEncodeSubscribeUrl}}', urlencode($subscribeUrl), $knowledge['body']); diff --git a/app/Http/Controllers/V1/User/UserController.php b/app/Http/Controllers/V1/User/UserController.php index 2f827011..eb5d9b6e 100755 --- a/app/Http/Controllers/V1/User/UserController.php +++ b/app/Http/Controllers/V1/User/UserController.php @@ -151,7 +151,7 @@ class UserController extends Controller abort(500, __('Subscription plan does not exist')); } } - $user['subscribe_url'] = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); + $user['subscribe_url'] = Helper::getSubscribeUrl($user['token']); $userService = new UserService(); $user['reset_day'] = $userService->getResetDay($user); return response([ @@ -171,7 +171,7 @@ class UserController extends Controller abort(500, __('Reset failed')); } return response([ - 'data' => Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user->token) + 'data' => Helper::getSubscribeUrl($user['token']) ]); } diff --git a/app/Http/Requests/Admin/ConfigSave.php b/app/Http/Requests/Admin/ConfigSave.php index 01e2195c..09d105d1 100755 --- a/app/Http/Requests/Admin/ConfigSave.php +++ b/app/Http/Requests/Admin/ConfigSave.php @@ -29,6 +29,7 @@ class ConfigSave extends FormRequest 'app_description' => '', 'app_url' => 'nullable|url', 'subscribe_url' => 'nullable', + 'subscribe_path' => 'nullable', 'try_out_enable' => 'in:0,1', 'try_out_plan_id' => 'integer', 'try_out_hour' => 'numeric', diff --git a/app/Http/Routes/V1/ClientRoute.php b/app/Http/Routes/V1/ClientRoute.php index 81644acb..abc25406 100644 --- a/app/Http/Routes/V1/ClientRoute.php +++ b/app/Http/Routes/V1/ClientRoute.php @@ -12,10 +12,15 @@ class ClientRoute 'middleware' => 'client' ], function ($router) { // Client - $router->get('/subscribe', 'V1\\Client\\ClientController@subscribe'); + if (!config('v2board.subscribe_path')) { + $router->get('/subscribe', 'V1\\Client\\ClientController@subscribe'); + } // App $router->get('/app/getConfig', 'V1\\Client\\AppController@getConfig'); $router->get('/app/getVersion', 'V1\\Client\\AppController@getVersion'); }); + if (config('v2board.subscribe_path')) { + \Route::get(config('v2board.subscribe_path'), 'V1\\Client\\ClientController@subscribe'); + } } } diff --git a/app/Protocols/Surfboard.php b/app/Protocols/Surfboard.php index c4b36ad1..eba851b5 100644 --- a/app/Protocols/Surfboard.php +++ b/app/Protocols/Surfboard.php @@ -64,7 +64,7 @@ class Surfboard } // Subscription link - $subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); + $subsURL = Helper::getSubscribeUrl($user['token']); $subsDomain = $_SERVER['HTTP_HOST']; $config = str_replace('$subs_link', $subsURL, $config); diff --git a/app/Protocols/Surge.php b/app/Protocols/Surge.php index ed970852..7cf3e1e8 100644 --- a/app/Protocols/Surge.php +++ b/app/Protocols/Surge.php @@ -64,7 +64,6 @@ class Surge } // Subscription link - $subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); $subsDomain = $_SERVER['HTTP_HOST']; $subsURL = 'https://' . $subsDomain . '/api/v1/client/subscribe?token=' . $user['token']; diff --git a/app/Utils/Helper.php b/app/Utils/Helper.php index 196b4769..0bf38119 100644 --- a/app/Utils/Helper.php +++ b/app/Utils/Helper.php @@ -108,8 +108,10 @@ class Helper } } - public static function getSubscribeUrl($path) + public static function getSubscribeUrl($token) { + $path = config('v2board.subscribe_path', '/client/subscribe'); + $path = "/api/v1{$path}?token={$token}"; $subscribeUrls = explode(',', config('v2board.subscribe_url')); $subscribeUrl = $subscribeUrls[rand(0, count($subscribeUrls) - 1)]; if ($subscribeUrl) return $subscribeUrl . $path;