mirror of
https://github.com/cedar2025/Xboard.git
synced 2025-01-22 10:38:14 -05:00
refactor: subscription URL retrieval logic
This commit is contained in:
parent
73b25d2eec
commit
ab52e61ed1
@ -73,7 +73,7 @@ class UserController extends Controller
|
|||||||
$res[$i]['plan_name'] = $plan[$k]['name'];
|
$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([
|
return response([
|
||||||
'data' => $res,
|
'data' => $res,
|
||||||
@ -162,7 +162,7 @@ class UserController extends Controller
|
|||||||
$transferEnable = $user['transfer_enable'] ? $user['transfer_enable'] / 1073741824 : 0;
|
$transferEnable = $user['transfer_enable'] ? $user['transfer_enable'] / 1073741824 : 0;
|
||||||
$notUseFlow = (($user['transfer_enable'] - ($user['u'] + $user['d'])) / 1073741824) ?? 0;
|
$notUseFlow = (($user['transfer_enable'] - ($user['u'] + $user['d'])) / 1073741824) ?? 0;
|
||||||
$planName = $user['plan_name'] ?? '无订阅';
|
$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";
|
$data .= "{$user['email']},{$balance},{$commissionBalance},{$transferEnable},{$notUseFlow},{$expireDate},{$planName},{$subscribeUrl}\r\n";
|
||||||
}
|
}
|
||||||
echo "\xEF\xBB\xBF" . $data;
|
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']);
|
$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']);
|
$createDate = date('Y-m-d H:i:s', $user['created_at']);
|
||||||
$password = $request->input('password') ?? $user['email'];
|
$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";
|
$data .= "{$user['email']},{$password},{$expireDate},{$user['uuid']},{$createDate},{$subscribeUrl}\r\n";
|
||||||
}
|
}
|
||||||
echo $data;
|
echo $data;
|
||||||
|
@ -25,7 +25,7 @@ class KnowledgeController extends Controller
|
|||||||
if (!$userService->isAvailable($user)) {
|
if (!$userService->isAvailable($user)) {
|
||||||
$this->formatAccessData($knowledge['body']);
|
$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('{{siteName}}', admin_setting('app_name', 'XBoard'), $knowledge['body']);
|
||||||
$knowledge['body'] = str_replace('{{subscribeUrl}}', $subscribeUrl, $knowledge['body']);
|
$knowledge['body'] = str_replace('{{subscribeUrl}}', $subscribeUrl, $knowledge['body']);
|
||||||
$knowledge['body'] = str_replace('{{urlEncodeSubscribeUrl}}', urlencode($subscribeUrl), $knowledge['body']);
|
$knowledge['body'] = str_replace('{{urlEncodeSubscribeUrl}}', urlencode($subscribeUrl), $knowledge['body']);
|
||||||
|
@ -140,7 +140,7 @@ class UserController extends Controller
|
|||||||
return $this->fail([400, __('Subscription plan does not exist')]);
|
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();
|
$userService = new UserService();
|
||||||
$user['reset_day'] = $userService->getResetDay($user);
|
$user['reset_day'] = $userService->getResetDay($user);
|
||||||
return $this->success($user);
|
return $this->success($user);
|
||||||
@ -157,7 +157,7 @@ class UserController extends Controller
|
|||||||
if (!$user->save()) {
|
if (!$user->save()) {
|
||||||
return $this->fail([400, __('Reset failed')]);
|
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)
|
public function update(UserUpdate $request)
|
||||||
|
@ -12,7 +12,7 @@ class ClientRoute
|
|||||||
'middleware' => 'client'
|
'middleware' => 'client'
|
||||||
], function ($router) {
|
], function ($router) {
|
||||||
// Client
|
// Client
|
||||||
$router->get('/subscribe', 'V1\\Client\\ClientController@subscribe');
|
$router->get('/subscribe', 'V1\\Client\\ClientController@subscribe')->name('client.subscribe');
|
||||||
// App
|
// App
|
||||||
$router->get('/app/getConfig', 'V1\\Client\\AppController@getConfig');
|
$router->get('/app/getConfig', 'V1\\Client\\AppController@getConfig');
|
||||||
$router->get('/app/getVersion', 'V1\\Client\\AppController@getVersion');
|
$router->get('/app/getVersion', 'V1\\Client\\AppController@getVersion');
|
||||||
|
@ -63,7 +63,7 @@ class Surfboard
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Subscription link
|
// Subscription link
|
||||||
$subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");
|
$subsURL = Helper::getSubscribeUrl($user['token']);
|
||||||
$subsDomain = request()->header('Host');
|
$subsDomain = request()->header('Host');
|
||||||
|
|
||||||
$config = str_replace('$subs_link', $subsURL, $config);
|
$config = str_replace('$subs_link', $subsURL, $config);
|
||||||
|
@ -69,9 +69,8 @@ class Surge
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Subscription link
|
// Subscription link
|
||||||
$subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");
|
|
||||||
$subsDomain = request()->header('Host');
|
$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_link', $subsURL, $config);
|
||||||
$config = str_replace('$subs_domain', $subsDomain, $config);
|
$config = str_replace('$subs_domain', $subsDomain, $config);
|
||||||
|
@ -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'));
|
$path = route('client.subscribe', ['token' => $token], false);
|
||||||
$subscribeUrl = $subscribeUrls[array_rand($subscribeUrls)];
|
if(!$subscribeUrl){
|
||||||
$subscribeUrl = self::replaceByPattern($subscribeUrl);
|
$subscribeUrls = explode(',', admin_setting('subscribe_url'));
|
||||||
if ($subscribeUrl) return $subscribeUrl . $path;
|
$subscribeUrl = \Arr::random($subscribeUrls);
|
||||||
return url($path);
|
$subscribeUrl = self::replaceByPattern($subscribeUrl);
|
||||||
|
}
|
||||||
|
return $subscribeUrl ? rtrim($subscribeUrl, '/') . $path : url($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function randomPort($range) {
|
public static function randomPort($range) {
|
||||||
|
Loading…
Reference in New Issue
Block a user