mirror of
https://github.com/v2board/v2board.git
synced 2025-02-11 16:00:27 +08:00
restore: origin subscribe method
This commit is contained in:
parent
e01e951f7f
commit
cd85fba9c7
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Client;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Services\ServerService;
|
use App\Services\ServerService;
|
||||||
use App\Utils\Clash;
|
use App\Utils\Clash;
|
||||||
|
use App\Utils\Origin;
|
||||||
use App\Utils\QuantumultX;
|
use App\Utils\QuantumultX;
|
||||||
use App\Utils\Shadowrocket;
|
use App\Utils\Shadowrocket;
|
||||||
use App\Utils\Shadowsocks;
|
use App\Utils\Shadowsocks;
|
||||||
@ -49,10 +50,27 @@ class ClientController extends Controller
|
|||||||
die($this->shaodowsocksSIP008($user, $servers));
|
die($this->shaodowsocksSIP008($user, $servers));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
die('当前客户端不支持获取配置');
|
die($this->origin($user, $servers));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function origin($user, $servers = [])
|
||||||
|
{
|
||||||
|
$uri = '';
|
||||||
|
foreach ($servers as $item) {
|
||||||
|
if ($item['type'] === 'shadowsocks') {
|
||||||
|
$uri .= Origin::buildShadowsocks($item, $user);
|
||||||
|
}
|
||||||
|
if ($item['type'] === 'v2ray') {
|
||||||
|
$uri .= Origin::buildVmess($item, $user);
|
||||||
|
}
|
||||||
|
if ($item['type'] === 'trojan') {
|
||||||
|
$uri .= Origin::buildTrojan($item, $user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return base64_encode($uri);
|
||||||
|
}
|
||||||
|
|
||||||
private function shadowrocket($user, $servers = [])
|
private function shadowrocket($user, $servers = [])
|
||||||
{
|
{
|
||||||
$uri = '';
|
$uri = '';
|
||||||
|
59
app/Utils/Origin.php
Normal file
59
app/Utils/Origin.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Utils;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class Origin
|
||||||
|
{
|
||||||
|
public static function buildShadowsocks($server, User $user)
|
||||||
|
{
|
||||||
|
$name = rawurlencode($server['name']);
|
||||||
|
$str = str_replace(
|
||||||
|
['+', '/', '='],
|
||||||
|
['-', '_', ''],
|
||||||
|
base64_encode("{$server['cipher']}:{$user['uuid']}")
|
||||||
|
);
|
||||||
|
return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function buildVmess($server, User $user)
|
||||||
|
{
|
||||||
|
$config = [
|
||||||
|
"v" => "2",
|
||||||
|
"ps" => $server['name'],
|
||||||
|
"add" => $server['host'],
|
||||||
|
"port" => (string)$server['port'],
|
||||||
|
"id" => $user['uuid'],
|
||||||
|
"aid" => (string)$server['alter_id'],
|
||||||
|
"net" => $server['network'],
|
||||||
|
"type" => "none",
|
||||||
|
"host" => "",
|
||||||
|
"path" => "",
|
||||||
|
"tls" => $server['tls'] ? "tls" : "",
|
||||||
|
"sni" => $server['tls'] ? json_decode($server['tlsSettings'], true)['serverName'] : ""
|
||||||
|
];
|
||||||
|
if ((string)$server['network'] === 'ws') {
|
||||||
|
$wsSettings = json_decode($server['networkSettings'], true);
|
||||||
|
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];
|
||||||
|
if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host'];
|
||||||
|
}
|
||||||
|
if ((string)$server['network'] === 'grpc') {
|
||||||
|
$grpcSettings = json_decode($server['networkSettings'], true);
|
||||||
|
if (isset($grpcSettings['path'])) $config['path'] = $grpcSettings['serviceName'];
|
||||||
|
}
|
||||||
|
return "vmess://" . base64_encode(json_encode($config)) . "\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function buildTrojan($server, User $user)
|
||||||
|
{
|
||||||
|
$name = rawurlencode($server['name']);
|
||||||
|
$query = http_build_query([
|
||||||
|
'allowInsecure' => $server['allow_insecure'],
|
||||||
|
'peer' => $server['server_name'],
|
||||||
|
'sni' => $server['server_name']
|
||||||
|
]);
|
||||||
|
$uri = "trojan://{$user['uuid']}@{$server['host']}:{$server['port']}?{$query}#{$name}";
|
||||||
|
$uri .= "\r\n";
|
||||||
|
return $uri;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user