1, 'remark' => $server['name'], 'alterId' => $server['alter_id'] ]; if ($server['tls']) { $config['tls'] = 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') { $config['obfs'] = "websocket"; 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']; } } if ($server['network'] === 'grpc') { $config['obfs'] = "grpc"; if (isset($server['networkSettings'])) { $grpcObject = json_decode($server['networkSettings'], true); if (isset($grpcObject['serviceName'])) { $config['obfsParam'] = json_encode([ 'Host' => $grpcObject['serviceName'] ]); $config['path'] = '/'; } } } $query = http_build_query($config, '', '&', PHP_QUERY_RFC3986); $uri = "vmess://{$userinfo}?{$query}"; $uri .= "\r\n"; return $uri; } public static function buildTrojan($password, $server) { $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#{$name}"; $uri .= "\r\n"; return $uri; } }