update: get subscribe url

This commit is contained in:
tokumeikoi 2022-05-09 23:26:59 +08:00
parent d74ab728fe
commit ed749f85ae
9 changed files with 19 additions and 31 deletions

View File

@ -56,13 +56,11 @@ class ConfigController extends Controller
public function setTelegramWebhook(Request $request)
{
$appUrl = config('v2board.app_url');
if (!$appUrl) abort(500, '请先配置正确的站点地址');
$hookUrl = '/api/v1/guest/telegram/webhook?access_token=' . md5(config('v2board.telegram_bot_token', $request->input('telegram_bot_token')));
$hookUrl - str_replace('http://', 'https://', $hookUrl);
$telegramService = new TelegramService($request->input('telegram_bot_token'));
$telegramService->getMe();
$telegramService->setWebhook(
$appUrl . '/api/v1/guest/telegram/webhook?access_token=' . md5(config('v2board.telegram_bot_token', $request->input('telegram_bot_token')))
);
$telegramService->setWebhook($hookUrl);
return response([
'data' => true
]);

View File

@ -26,7 +26,7 @@ class PaymentController extends Controller
{
$payments = Payment::all();
foreach ($payments as $k => $v) {
$notifyUrl = config('v2board.app_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'];

View File

@ -74,7 +74,7 @@ class UserController extends Controller
$res[$i]['plan_name'] = $plan[$k]['name'];
}
}
$res[$i]['subscribe_url'] = Helper::getSubscribeHost() . '/api/v1/client/subscribe?token=' . $res[$i]['token'];
$res[$i]['subscribe_url'] = Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $res[$i]['token']);
}
return response([
'data' => $res,
@ -153,7 +153,6 @@ class UserController extends Controller
}
$data = "邮箱,余额,推广佣金,总流量,剩余流量,套餐到期时间,订阅计划,订阅地址\r\n";
$baseUrl = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL')));
foreach($res as $user) {
$expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']);
$balance = $user['balance'] / 100;
@ -161,7 +160,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 = $baseUrl . '/api/v1/client/subscribe?token=' . $user['token'];
$subscribeUrl = Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user['token']);
$data .= "{$user['email']},{$balance},{$commissionBalance},{$transferEnable},{$notUseFlow},{$expireDate},{$planName},{$subscribeUrl}\r\n";
}
echo "\xEF\xBB\xBF" . $data;
@ -232,12 +231,11 @@ class UserController extends Controller
}
DB::commit();
$data = "账号,密码,过期时间,UUID,创建时间,订阅地址\r\n";
$baseUrl = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL')));
foreach($users as $user) {
$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 = $baseUrl . '/api/v1/client/subscribe?token=' . $user['token'];
$subscribeUrl = Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user['token']);
$data .= "{$user['email']},{$password},{$expireDate},{$user['uuid']},{$createDate},{$subscribeUrl}\r\n";
}
echo $data;

View File

@ -54,8 +54,7 @@ class Surfboard
}
// Subscription link
$subsHost = Helper::getSubscribeHost();
$subsURL = "{$subsHost}/api/v1/client/subscribe?token={$user['token']}";
$subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");
$subsDomain = $_SERVER['SERVER_NAME'];
$config = str_replace('$subs_link', $subsURL, $config);

View File

@ -54,8 +54,7 @@ class Surge
}
// Subscription link
$subsHost = Helper::getSubscribeHost();
$subsURL = "{$subsHost}/api/v1/client/subscribe?token={$user['token']}";
$subsURL = Helper::getSubscribeHost("/api/v1/client/subscribe?token={$user['token']}");
$subsDomain = $_SERVER['SERVER_NAME'];
$config = str_replace('$subs_link', $subsURL, $config);

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Services\UserService;
use App\Utils\Helper;
use Illuminate\Http\Request;
use App\Models\Knowledge;
@ -28,12 +29,7 @@ class KnowledgeController extends Controller
$appleIdPassword = __('No active subscription. Unable to use our provided Apple ID');
$this->formatAccessData($knowledge['body']);
}
$subscribeUrl = config('v2board.app_url', env('APP_URL'));
$subscribeUrls = explode(',', config('v2board.subscribe_url'));
if ($subscribeUrls) {
$subscribeUrl = $subscribeUrls[rand(0, count($subscribeUrls) - 1)];
}
$subscribeUrl = "{$subscribeUrl}/api/v1/client/subscribe?token={$user['token']}";
$subscribeUrl = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$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']);

View File

@ -120,7 +120,7 @@ class UserController extends Controller
abort(500, __('Subscription plan does not exist'));
}
}
$user['subscribe_url'] = Helper::getSubscribeHost() . "/api/v1/client/subscribe?token={$user['token']}";
$user['subscribe_url'] = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");
$user['reset_day'] = $this->getResetDay($user);
return response([
'data' => $user
@ -139,7 +139,7 @@ class UserController extends Controller
abort(500, __('Reset failed'));
}
return response([
'data' => config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user->token
'data' => Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user->token)
]);
}

View File

@ -39,7 +39,7 @@ class PaymentService
public function pay($order)
{
// custom notify domain name
$notifyUrl = config('v2board.app_url', env('APP_URL')) . "/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}";
$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'];
@ -47,7 +47,7 @@ class PaymentService
return $this->payment->pay([
'notify_url' => $notifyUrl,
'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order/' . $order['trade_no'],
'return_url' => config('v2board.app_url') . '/#/order/' . $order['trade_no'],
'trade_no' => $order['trade_no'],
'total_amount' => $order['total_amount'],
'user_id' => $order['user_id'],

View File

@ -103,14 +103,12 @@ class Helper
}
}
public static function getSubscribeHost()
public static function getSubscribeUrl($path)
{
$subscribeUrl = config('v2board.app_url');
$subscribeUrls = explode(',', config('v2board.subscribe_url'));
if ($subscribeUrls && $subscribeUrls[0]) {
$subscribeUrl = $subscribeUrls[rand(0, count($subscribeUrls) - 1)];
}
return $subscribeUrl;
$subscribeUrl = $subscribeUrls[rand(0, count($subscribeUrls) - 1)];
if ($subscribeUrl) return $subscribeUrl . $path;
return url($path);
}
public static function randomPort($range) {