2019-10-29 15:33:36 +08:00
|
|
|
<?php
|
|
|
|
|
2020-01-29 16:08:50 +08:00
|
|
|
namespace App\Http\Controllers\Client;
|
2019-10-29 15:33:36 +08:00
|
|
|
|
2023-03-09 20:36:35 +08:00
|
|
|
use App\Http\Controllers\Client\Protocols\General;
|
2019-10-29 15:33:36 +08:00
|
|
|
use App\Http\Controllers\Controller;
|
2020-06-12 00:18:35 +08:00
|
|
|
use App\Services\ServerService;
|
2023-05-22 00:34:24 +08:00
|
|
|
use App\Utils\Helper;
|
2020-01-29 16:08:50 +08:00
|
|
|
use Illuminate\Http\Request;
|
2020-02-28 01:12:55 +08:00
|
|
|
use App\Services\UserService;
|
2019-10-29 15:33:36 +08:00
|
|
|
|
|
|
|
class ClientController extends Controller
|
|
|
|
{
|
2020-01-11 13:36:52 +08:00
|
|
|
public function subscribe(Request $request)
|
|
|
|
{
|
2020-10-24 23:08:14 +08:00
|
|
|
$flag = $request->input('flag')
|
2022-12-02 13:52:20 +08:00
|
|
|
?? ($_SERVER['HTTP_USER_AGENT'] ?? '');
|
2020-10-24 23:08:14 +08:00
|
|
|
$flag = strtolower($flag);
|
2019-10-29 15:33:36 +08:00
|
|
|
$user = $request->user;
|
2020-02-07 19:34:24 +08:00
|
|
|
// account not expired and is not banned.
|
2020-02-28 17:16:05 +08:00
|
|
|
$userService = new UserService();
|
|
|
|
if ($userService->isAvailable($user)) {
|
2020-06-12 00:18:35 +08:00
|
|
|
$serverService = new ServerService();
|
2020-11-14 17:26:17 +08:00
|
|
|
$servers = $serverService->getAvailableServers($user);
|
2022-06-07 22:11:13 +08:00
|
|
|
$this->setSubscribeInfoToServers($servers, $user);
|
2020-10-24 23:08:14 +08:00
|
|
|
if ($flag) {
|
2023-03-08 02:31:46 +08:00
|
|
|
foreach (array_reverse(glob(app_path('Http//Controllers//Client//Protocols') . '/*.php')) as $file) {
|
2021-07-02 22:34:42 +08:00
|
|
|
$file = 'App\\Http\\Controllers\\Client\\Protocols\\' . basename($file, '.php');
|
|
|
|
$class = new $file($user, $servers);
|
|
|
|
if (strpos($flag, $class->flag) !== false) {
|
|
|
|
die($class->handle());
|
|
|
|
}
|
2020-11-19 13:05:49 +08:00
|
|
|
}
|
2020-03-28 10:10:30 +08:00
|
|
|
}
|
2023-03-09 20:36:35 +08:00
|
|
|
$class = new General($user, $servers);
|
|
|
|
die($class->handle());
|
2020-06-20 22:50:43 +08:00
|
|
|
}
|
|
|
|
}
|
2022-06-07 22:11:13 +08:00
|
|
|
|
|
|
|
private function setSubscribeInfoToServers(&$servers, $user)
|
|
|
|
{
|
2023-01-19 15:43:46 +08:00
|
|
|
if (!isset($servers[0])) return;
|
2022-06-07 22:11:13 +08:00
|
|
|
if (!(int)config('v2board.show_info_to_server_enable', 0)) return;
|
2023-05-22 00:34:24 +08:00
|
|
|
$useTraffic = $user['u'] + $user['d'];
|
|
|
|
$totalTraffic = $user['transfer_enable'];
|
|
|
|
$remainingTraffic = Helper::trafficConvert($totalTraffic - $useTraffic);
|
2022-06-07 22:11:13 +08:00
|
|
|
$expiredDate = $user['expired_at'] ? date('Y-m-d', $user['expired_at']) : '长期有效';
|
|
|
|
$userService = new UserService();
|
|
|
|
$resetDay = $userService->getResetDay($user);
|
|
|
|
array_unshift($servers, array_merge($servers[0], [
|
|
|
|
'name' => "套餐到期:{$expiredDate}",
|
|
|
|
]));
|
|
|
|
if ($resetDay) {
|
|
|
|
array_unshift($servers, array_merge($servers[0], [
|
|
|
|
'name' => "距离下次重置剩余:{$resetDay} 天",
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
array_unshift($servers, array_merge($servers[0], [
|
2023-05-22 00:34:24 +08:00
|
|
|
'name' => "剩余流量:{$remainingTraffic}",
|
2022-06-07 22:11:13 +08:00
|
|
|
]));
|
|
|
|
}
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|