2020-10-04 14:21:09 +08:00
|
|
|
<?php
|
|
|
|
namespace App\Utils;
|
|
|
|
|
|
|
|
use App\Models\Server;
|
|
|
|
use App\Models\User;
|
|
|
|
|
|
|
|
class URLSchemes
|
|
|
|
{
|
2020-11-15 17:10:32 +08:00
|
|
|
public static function buildShadowsocks($server, User $user)
|
2020-10-04 14:21:09 +08:00
|
|
|
{
|
2020-11-15 17:10:32 +08:00
|
|
|
$name = rawurlencode($server['name']);
|
2020-10-04 14:21:09 +08:00
|
|
|
$str = str_replace(
|
|
|
|
['+', '/', '='],
|
|
|
|
['-', '_', ''],
|
2020-11-15 17:10:32 +08:00
|
|
|
base64_encode("{$server['cipher']}:{$user['uuid']}")
|
2020-10-04 14:21:09 +08:00
|
|
|
);
|
2020-11-15 17:10:32 +08:00
|
|
|
return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
|
2020-10-04 14:21:09 +08:00
|
|
|
}
|
|
|
|
|
2020-11-19 13:05:49 +08:00
|
|
|
public static function buildShadowsocksSIP008($server, User $user)
|
|
|
|
{
|
|
|
|
$config = [
|
|
|
|
"id" => $server['id'],
|
2020-12-24 13:02:43 +08:00
|
|
|
"remarks" => $server['name'],
|
2020-11-19 13:05:49 +08:00
|
|
|
"server" => $server['host'],
|
|
|
|
"server_port" => $server['port'],
|
|
|
|
"password" => $user['uuid'],
|
|
|
|
"method" => $server['cipher']
|
|
|
|
];
|
|
|
|
return $config;
|
|
|
|
}
|
2020-10-04 14:21:09 +08:00
|
|
|
|
2020-11-15 17:10:32 +08:00
|
|
|
public static function buildVmess($server, User $user)
|
2020-10-04 14:21:09 +08:00
|
|
|
{
|
|
|
|
$config = [
|
|
|
|
"v" => "2",
|
2020-11-15 17:10:32 +08:00
|
|
|
"ps" => $server['name'],
|
|
|
|
"add" => $server['host'],
|
2021-03-08 19:12:25 +08:00
|
|
|
"port" => (string)$server['port'],
|
2020-11-15 17:10:32 +08:00
|
|
|
"id" => $user['uuid'],
|
2021-03-08 19:12:25 +08:00
|
|
|
"aid" => (string)$server['alter_id'],
|
2020-11-15 17:10:32 +08:00
|
|
|
"net" => $server['network'],
|
2020-10-04 14:21:09 +08:00
|
|
|
"type" => "none",
|
|
|
|
"host" => "",
|
|
|
|
"path" => "",
|
2020-11-15 17:10:32 +08:00
|
|
|
"tls" => $server['tls'] ? "tls" : ""
|
2020-10-04 14:21:09 +08:00
|
|
|
];
|
2020-11-15 17:10:32 +08:00
|
|
|
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'];
|
2020-10-04 14:21:09 +08:00
|
|
|
}
|
|
|
|
return "vmess://" . base64_encode(json_encode($config)) . "\r\n";
|
|
|
|
}
|
|
|
|
|
2020-11-15 17:10:32 +08:00
|
|
|
public static function buildTrojan($server, User $user)
|
2020-10-04 14:21:09 +08:00
|
|
|
{
|
2020-11-15 17:10:32 +08:00
|
|
|
$name = rawurlencode($server['name']);
|
2020-10-04 14:21:09 +08:00
|
|
|
$query = http_build_query([
|
2020-11-15 17:10:32 +08:00
|
|
|
'allowInsecure' => $server['allow_insecure'],
|
|
|
|
'peer' => $server['server_name'],
|
|
|
|
'sni' => $server['server_name']
|
2020-10-04 14:21:09 +08:00
|
|
|
]);
|
2020-11-15 17:10:32 +08:00
|
|
|
$uri = "trojan://{$user['uuid']}@{$server['host']}:{$server['port']}?{$query}#{$name}";
|
2020-10-04 14:21:09 +08:00
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
}
|