fix(qr): Use raw VLESS URI in last_config->config

Instead of generating a JSON config for X-Ray, pass the raw VLESS URI string
wrapped in a JSON object  inside .
This matches the behavior of WireGuard config handling in the master branch
and is likely the expected format for Amnezia Android X-Ray import.
This commit is contained in:
infosave2007
2026-01-24 13:48:57 +03:00
parent 174a2fb1e8
commit dde0ff9ea1
2 changed files with 25 additions and 46 deletions
+24 -45
View File
@@ -409,59 +409,38 @@ class QrUtil
return json_encode($decoded, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); return json_encode($decoded, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
} }
public static function encodeXrayPayload(string $host, int $port, string $clientId, string $description = '', ?array $reality = null): string public static function encodeXrayPayload(string $host, int $port, string $clientId, string $description = '', ?array $reality = null, string $rawConfig = ''): string
{ {
$desc = $description !== '' ? $description : self::resolveServerDescription($host); $desc = $description !== '' ? $description : self::resolveServerDescription($host);
$clientCfg = [
'log' => ['loglevel' => 'error'], // Instead of generating a JSON config, we wrap the raw VLESS URI in a "config" field.
'inbounds' => [ // This matches how WireGuard configs are handled in master branch and is likely what Amnezia expects.
[ // If rawConfig is not provided, we reconstruct a basic VLESS URI (fallback)
'listen' => '127.0.0.1', if (empty($rawConfig)) {
'port' => 10808, // Basic reconstruction if needed, but we should pass valid rawConfig from VpnClient
'protocol' => 'socks', $security = ($reality && isset($reality['publicKey']) && $reality['publicKey'] !== '') ? 'reality' : 'none';
'settings' => ['udp' => true] $type = 'tcp';
] $flow = ($security === 'reality') ? 'xtls-rprx-vision' : '';
],
'outbounds' => [ $query = http_build_query([
[ 'security' => $security,
'protocol' => 'vless', 'type' => $type,
'settings' => [ 'flow' => $flow,
'vnext' => [ 'sni' => $reality['serverName'] ?? '',
[ 'pbk' => $reality['publicKey'] ?? '',
'address' => $host, 'fp' => $reality['fingerprint'] ?? 'chrome',
'port' => $port, 'sid' => $reality['shortId'] ?? ''
'users' => [ ]);
[ $rawConfig = "vless://$clientId@$host:$port?$query";
'id' => $clientId, }
'flow' => ($reality && isset($reality['publicKey']) && $reality['publicKey'] !== '') ? 'xtls-rprx-vision' : null,
'encryption' => 'none'
]
]
]
]
],
'streamSettings' => [
'network' => 'tcp',
'security' => ($reality && isset($reality['publicKey']) && $reality['publicKey'] !== '') ? 'reality' : 'none',
'realitySettings' => ($reality && isset($reality['publicKey']) && $reality['publicKey'] !== '') ? [
'fingerprint' => 'chrome',
'serverName' => (string) ($reality['serverName'] ?? $host),
'publicKey' => (string) $reality['publicKey'],
'shortId' => (string) ($reality['shortId'] ?? ''),
'spiderX' => ''
] : null
]
]
]
];
$envelope = [ $envelope = [
'containers' => [ 'containers' => [
[ [
'xray' => [ 'xray' => [
'isThirdPartyConfig' => true, 'isThirdPartyConfig' => true,
// X-Ray config must be wrapped in a "config" field inside the last_config JSON // Wrap the raw VLESS URI in a "config" field inside last_config
'last_config' => json_encode(['config' => json_encode($clientCfg, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), 'last_config' => json_encode(['config' => $rawConfig], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'port' => (string) $port, 'port' => (string) $port,
'transport_proto' => 'tcp' 'transport_proto' => 'tcp'
], ],
+1 -1
View File
@@ -960,7 +960,7 @@ class VpnClient
} }
// Use QrUtil to encode correct X-Ray payload // Use QrUtil to encode correct X-Ray payload
$payloadXray = QrUtil::encodeXrayPayload($host, $port, $clientId, $fragment, $reality); $payloadXray = QrUtil::encodeXrayPayload($host, $port, $clientId, $fragment, $reality, $config);
return QrUtil::pngBase64($payloadXray); return QrUtil::pngBase64($payloadXray);
} }
} }