2020-07-20 17:22:50 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Utils;
|
|
|
|
|
|
|
|
|
|
|
|
class Shadowrocket
|
|
|
|
{
|
2020-10-04 16:07:19 +08:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2020-07-20 17:22:50 +08:00
|
|
|
public static function buildVmess($uuid, $server)
|
|
|
|
{
|
|
|
|
$userinfo = base64_encode('auto:' . $uuid . '@' . $server->host . ':' . $server->port);
|
|
|
|
$config = [
|
|
|
|
'remark' => $server->name
|
|
|
|
];
|
|
|
|
if ($server->tls) {
|
|
|
|
$tlsSettings = json_decode($server->tlsSettings);
|
|
|
|
$config['tls'] = 1;
|
|
|
|
if (isset($tlsSettings->serverName)) $config['peer'] = $tlsSettings->serverName;
|
|
|
|
if (isset($tlsSettings->allowInsecure)) $config['allowInsecure'] = 1;
|
|
|
|
}
|
|
|
|
if ($server->network === 'ws') {
|
|
|
|
$wsSettings = json_decode($server->networkSettings);
|
|
|
|
$config['obfs'] = "websocket";
|
|
|
|
if (isset($wsSettings->path)) $config['path'] = $wsSettings->path;
|
|
|
|
if (isset($wsSettings->headers->Host)) $config['obfsParam'] = $wsSettings->headers->Host;
|
|
|
|
}
|
2020-07-23 09:59:17 +08:00
|
|
|
$query = http_build_query($config, null, '&', PHP_QUERY_RFC3986);
|
2020-07-20 17:22:50 +08:00
|
|
|
$uri = "vmess://{$userinfo}?{$query}&tfo=1";
|
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function buildTrojan($password, $server)
|
|
|
|
{
|
2020-10-04 16:07:19 +08:00
|
|
|
$name = rawurlencode($server->name);
|
2020-07-20 17:22:50 +08:00
|
|
|
$query = http_build_query([
|
|
|
|
'allowInsecure' => $server->allow_insecure,
|
|
|
|
'peer' => $server->server_name
|
|
|
|
]);
|
2020-10-04 16:07:19 +08:00
|
|
|
$uri = "trojan://{$password}@{$server->host}:{$server->port}?{$query}&tfo=1#{$name}";
|
2020-07-20 17:22:50 +08:00
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
}
|