update: support shadowsocks app subscribe

This commit is contained in:
Tokumeikoi
2020-10-04 16:07:19 +08:00
parent 63adb9c4a8
commit 6fd577d2c8
3 changed files with 22 additions and 6 deletions

View File

@ -5,6 +5,17 @@ namespace App\Utils;
class Shadowrocket
{
public static function buildShadowsocks($password, $server)
{
$name = rawurlencode($server->name);
$str = str_replace(
['+', '/', '='],
['-', '_', ''],
base64_encode("{$server->cipher}:{$password}")
);
return "ss://{$str}@{$server->host}:{$server->port}#{$name}\r\n";
}
public static function buildVmess($uuid, $server)
{
$userinfo = base64_encode('auto:' . $uuid . '@' . $server->host . ':' . $server->port);
@ -31,12 +42,12 @@ class Shadowrocket
public static function buildTrojan($password, $server)
{
$server->name = rawurlencode($server->name);
$name = rawurlencode($server->name);
$query = http_build_query([
'allowInsecure' => $server->allow_insecure,
'peer' => $server->server_name
]);
$uri = "trojan://{$password}@{$server->host}:{$server->port}?{$query}&tfo=1#{$server->name}";
$uri = "trojan://{$password}@{$server->host}:{$server->port}?{$query}&tfo=1#{$name}";
$uri .= "\r\n";
return $uri;
}

View File

@ -10,12 +10,13 @@ class URLSchemes
{
public static function buildShadowsocks(ServerShadowsocks $server, User $user)
{
$name = rawurlencode($server->name);
$str = str_replace(
['+', '/', '='],
['-', '_', ''],
base64_encode("{$server->cipher}:{$user->uuid}")
);
return "ss://{$str}@{$server->host}:{$server->port}#{$server->name}\r\n";
return "ss://{$str}@{$server->host}:{$server->port}#{$name}\r\n";
}
@ -44,12 +45,13 @@ class URLSchemes
public static function buildTrojan(ServerTrojan $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}#{$server->name}";
$uri = "trojan://{$user->uuid}@{$server->host}:{$server->port}?{$query}#{$name}";
$uri .= "\r\n";
return $uri;
}