clean up buildvmess()

This commit is contained in:
Julian Liu
2020-11-20 00:26:39 +08:00
parent cada8ae9e8
commit 589eec9392
5 changed files with 77 additions and 75 deletions

View File

@ -20,23 +20,32 @@ class Shadowrocket
{
$userinfo = base64_encode('auto:' . $uuid . '@' . $server['host'] . ':' . $server['port']);
$config = [
'tfo' => 1,
'remark' => $server['name'],
'alterId' => $server['alter_id']
];
if ($server['tls']) {
$tlsSettings = json_decode($server['tlsSettings'], true);
$config['tls'] = 1;
if (isset($tlsSettings['serverName'])) $config['peer'] = $tlsSettings['serverName'];
if (isset($tlsSettings['allowInsecure'])) $config['allowInsecure'] = 1;
if ($server['tlsSettings']) {
$tlsSettings = json_decode($server['tlsSettings'], true);
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
$config['allowInsecure'] = (int)$tlsSettings['allowInsecure'];
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
$config['peer'] = $tlsSettings['serverName'];
}
}
if ($server['network'] === 'ws') {
$wsSettings = json_decode($server['networkSettings'], true);
$config['obfs'] = "websocket";
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];
if (isset($wsSettings['headers']['Host'])) $config['obfsParam'] = $wsSettings['headers']['Host'];
if ($server['networkSettings']) {
$wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
$config['path'] = $wsSettings['path'];
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
$config['obfsParam'] = $wsSettings['headers']['Host'];
}
}
$query = http_build_query($config, null, '&', PHP_QUERY_RFC3986);
$uri = "vmess://{$userinfo}?{$query}&tfo=1";
$query = http_build_query($config, '', '&', PHP_QUERY_RFC3986);
$uri = "vmess://{$userinfo}?{$query}";
$uri .= "\r\n";
return $uri;
}