diff --git a/app/Http/Controllers/V1/Server/UniProxyController.php b/app/Http/Controllers/V1/Server/UniProxyController.php index 031a9e50..21b831a5 100644 --- a/app/Http/Controllers/V1/Server/UniProxyController.php +++ b/app/Http/Controllers/V1/Server/UniProxyController.php @@ -124,6 +124,8 @@ class UniProxyController extends Controller if ($this->nodeInfo->version == 1) { $response['obfs'] = $this->nodeInfo->obfs_password ?? null; } elseif ($this->nodeInfo->version == 2) { + //TODO 处理hy2客户端上下行宽带设置 + $response['ignore_client_bandwidth'] = true; $response['obfs'] = $this->nodeInfo->obfs ?? null; $response['obfs-password'] = $this->nodeInfo->obfs_password ?? null; } diff --git a/app/Protocols/ClashVerge.php b/app/Protocols/ClashVerge.php index 7bd04b6a..94a87053 100644 --- a/app/Protocols/ClashVerge.php +++ b/app/Protocols/ClashVerge.php @@ -52,6 +52,10 @@ class ClashVerge array_push($proxy, self::buildTrojan($user['uuid'], $item)); array_push($proxies, $item['name']); } + if ($item['type'] === 'hysteria') { + array_push($proxy, self::buildHysteria($user['uuid'], $item)); + array_push($proxies, $item['name']); + } } $config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy); @@ -243,6 +247,38 @@ class ClashVerge return $array; } + public static function buildHysteria($password, $server) + { + $array = []; + $array['name'] = $server['name']; + $array['server'] = $server['host']; + $array['port'] = $server['port']; + $array['udp'] = true; + + if (isset($server['server_name'])) $array['sni'] = $server['server_name']; + + if ($server['version'] === 2) { + $array['type'] = 'hysteria2'; + $array['password'] = $password; + if (isset($server['obfs'])){ + $array['obfs'] = $server['obfs']; + $array['obfs-password'] = $server['obfs_password']; + } + } else { + $array['type'] = 'hysteria'; + $array['auth_str'] = $password; + if (isset($server['obfs']) && isset($server['obfs_password'])){ + $array['obfs'] = $server['obfs_password']; + } + //Todo:完善客户端上下行 + $array['up'] = $user->speed_limit ? min($server['down_mbps'], $user->speed_limit) : $server['down_mbps']; + $array['down'] = $user->speed_limit ? min($server['up_mbps'], $user->speed_limit) : $server['up_mbps']; + $array['protocol'] = 'udp'; + } + + return $array; + } + private function isMatch($exp, $str) { return @preg_match($exp, $str);