Skip to content

Commit

Permalink
Merge pull request #52 from ishkong/patch-1
Browse files Browse the repository at this point in the history
feat: 为v2rayn的订阅添加hysteria2支持
  • Loading branch information
cedar2025 authored Jan 13, 2024
2 parents 03267b2 + 0b5baa7 commit e67d0f7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/Protocols/V2rayN.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function handle()
if ($item['type'] === 'trojan') {
$uri .= self::buildTrojan($user['uuid'], $item);
}
if ($item['type'] === 'hysteria') {
$uri .= self::buildHysteria($user['uuid'], $item);
}

}
return base64_encode($uri);
Expand Down Expand Up @@ -199,4 +202,21 @@ public static function buildTrojan($password, $server)
return $uri;
}

public static function buildHysteria($password, $server)
{
$name = rawurlencode($server['name']);
$params = [];
if ($server['server_name']) $params['sni'] = $server['server_name'];
$params['insecure'] = $server['insecure'] ? 1 : 0;
$query = http_build_query($params);
if ($server['version'] == 2) {
$uri = "hysteria2://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
$uri .= "\r\n";
} else {
// V2rayN似乎不支持v1, 返回空
$uri = "";
}
return $uri;
}

}

0 comments on commit e67d0f7

Please sign in to comment.