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
|
|
|
|
2021-07-07 18:54:31 +08:00
|
|
|
use App\Http\Controllers\Client\Protocols\V2rayN;
|
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;
|
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')
|
2020-10-24 23:43:45 +08:00
|
|
|
?? (isset($_SERVER['HTTP_USER_AGENT'])
|
2020-10-24 23:08:14 +08:00
|
|
|
? $_SERVER['HTTP_USER_AGENT']
|
2020-10-24 23:43:45 +08:00
|
|
|
: '');
|
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) {
|
2021-07-02 22:34:42 +08:00
|
|
|
foreach (glob(app_path('Http//Controllers//Client//Protocols') . '/*.php') as $file) {
|
|
|
|
$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
|
|
|
}
|
2021-07-07 18:54:31 +08:00
|
|
|
// todo 1.5.3 remove
|
|
|
|
$class = new V2rayN($user, $servers);
|
|
|
|
die($class->handle());
|
2021-07-02 21:24:39 +08:00
|
|
|
die('该客户端暂不支持进行订阅');
|
2020-06-20 22:50:43 +08:00
|
|
|
}
|
|
|
|
}
|
2022-06-07 22:11:13 +08:00
|
|
|
|
|
|
|
private function setSubscribeInfoToServers(&$servers, $user)
|
|
|
|
{
|
|
|
|
if (!(int)config('v2board.show_info_to_server_enable', 0)) return;
|
|
|
|
$useTraffic = round($user['u'] / (1024*1024*1024), 2) + round($user['d'] / (1024*1024*1024), 2);
|
|
|
|
$totalTraffic = round($user['transfer_enable'] / (1024*1024*1024), 2);
|
|
|
|
$remainingTraffic = $totalTraffic - $useTraffic;
|
|
|
|
$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], [
|
|
|
|
'name' => "剩余流量:{$remainingTraffic} GB",
|
|
|
|
]));
|
|
|
|
}
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|