diff --git a/app/Http/Controllers/V1/Admin/UserController.php b/app/Http/Controllers/V1/Admin/UserController.php index c3ed2bc..8117aa1 100644 --- a/app/Http/Controllers/V1/Admin/UserController.php +++ b/app/Http/Controllers/V1/Admin/UserController.php @@ -73,7 +73,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, @@ -162,7 +162,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 ac412aa..6861e81 100644 --- a/app/Http/Controllers/V1/User/KnowledgeController.php +++ b/app/Http/Controllers/V1/User/KnowledgeController.php @@ -25,7 +25,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}}', admin_setting('app_name', 'XBoard'), $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 0dbe572..abb97bf 100755 --- a/app/Http/Controllers/V1/User/UserController.php +++ b/app/Http/Controllers/V1/User/UserController.php @@ -140,7 +140,7 @@ class UserController extends Controller return $this->fail([400, __('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 $this->success($user); @@ -157,7 +157,7 @@ class UserController extends Controller if (!$user->save()) { return $this->fail([400, __('Reset failed')]); } - return $this->success(Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user->token)); + return $this->success(Helper::getSubscribeUrl($user->token)); } public function update(UserUpdate $request) diff --git a/app/Http/Routes/V1/ClientRoute.php b/app/Http/Routes/V1/ClientRoute.php index 81644ac..ef5e4d1 100644 --- a/app/Http/Routes/V1/ClientRoute.php +++ b/app/Http/Routes/V1/ClientRoute.php @@ -12,7 +12,7 @@ class ClientRoute 'middleware' => 'client' ], function ($router) { // Client - $router->get('/subscribe', 'V1\\Client\\ClientController@subscribe'); + $router->get('/subscribe', 'V1\\Client\\ClientController@subscribe')->name('client.subscribe'); // App $router->get('/app/getConfig', 'V1\\Client\\AppController@getConfig'); $router->get('/app/getVersion', 'V1\\Client\\AppController@getVersion'); diff --git a/app/Protocols/Surfboard.php b/app/Protocols/Surfboard.php index 007e3eb..be44640 100644 --- a/app/Protocols/Surfboard.php +++ b/app/Protocols/Surfboard.php @@ -63,7 +63,7 @@ class Surfboard } // Subscription link - $subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); + $subsURL = Helper::getSubscribeUrl($user['token']); $subsDomain = request()->header('Host'); $config = str_replace('$subs_link', $subsURL, $config); diff --git a/app/Protocols/Surge.php b/app/Protocols/Surge.php index 4e09b82..c89f2ef 100644 --- a/app/Protocols/Surge.php +++ b/app/Protocols/Surge.php @@ -69,9 +69,8 @@ class Surge } // Subscription link - $subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); $subsDomain = request()->header('Host'); - $subsURL = 'https://' . $subsDomain . '/api/v1/client/subscribe?token=' . $user['token']; + $subsURL = Helper::getSubscribeUrl($user['token'], $subsDomain ? 'https://' . $subsDomain : null); $config = str_replace('$subs_link', $subsURL, $config); $config = str_replace('$subs_domain', $subsDomain, $config); diff --git a/app/Utils/Helper.php b/app/Utils/Helper.php index 6844327..341df4e 100644 --- a/app/Utils/Helper.php +++ b/app/Utils/Helper.php @@ -108,13 +108,15 @@ class Helper } } - public static function getSubscribeUrl($path) + public static function getSubscribeUrl(string $token, $subscribeUrl = null) { - $subscribeUrls = explode(',', admin_setting('subscribe_url')); - $subscribeUrl = $subscribeUrls[array_rand($subscribeUrls)]; - $subscribeUrl = self::replaceByPattern($subscribeUrl); - if ($subscribeUrl) return $subscribeUrl . $path; - return url($path); + $path = route('client.subscribe', ['token' => $token], false); + if(!$subscribeUrl){ + $subscribeUrls = explode(',', admin_setting('subscribe_url')); + $subscribeUrl = \Arr::random($subscribeUrls); + $subscribeUrl = self::replaceByPattern($subscribeUrl); + } + return $subscribeUrl ? rtrim($subscribeUrl, '/') . $path : url($path); } public static function randomPort($range) {