@@ -9,20 +9,21 @@ import (
99)
1010
1111type HY2 struct {
12- Password string
13- Host string
14- Port interface {}
15- MPort string
16- Insecure int
17- Peer string
18- Auth string
19- UpMbps int
20- DownMbps int
21- ALPN []string
22- Name string
23- Sni string
24- Obfs string
25- ObfsPassword string
12+ Password string
13+ Host string
14+ Port interface {}
15+ MPort string
16+ Insecure int
17+ Peer string
18+ Auth string
19+ UpMbps int
20+ DownMbps int
21+ ALPN []string
22+ Name string
23+ Sni string
24+ Obfs string
25+ ObfsPassword string
26+ ClientFingerprint string // 客户端指纹
2627}
2728
2829// 开发者测试 CallHy 调用
@@ -63,6 +64,12 @@ func EncodeHY2URL(hy2 HY2) string {
6364 q .Set ("sni" , hy2 .Sni )
6465 q .Set ("obfs" , hy2 .Obfs )
6566 q .Set ("obfs-password" , hy2 .ObfsPassword )
67+ // 客户端指纹参数
68+ q .Set ("fp" , hy2 .ClientFingerprint )
69+ // alpn 参数支持
70+ if len (hy2 .ALPN ) > 0 {
71+ q .Set ("alpn" , strings .Join (hy2 .ALPN , "," ))
72+ }
6673 // 检查query是否有空值,有的话删除
6774 for k , v := range q {
6875 if v [0 ] == "" || v [0 ] == "0" {
@@ -105,6 +112,7 @@ func DecodeHY2URL(s string) (HY2, error) {
105112 sni := u .Query ().Get ("sni" )
106113 obfs := u .Query ().Get ("obfs" )
107114 obfsPassword := u .Query ().Get ("obfs-password" )
115+ clientFingerprint := u .Query ().Get ("fp" )
108116 name := u .Fragment
109117 // 如果没有设置 Name,则使用 Host:Port 作为 Fragment
110118 if name == "" {
@@ -123,21 +131,56 @@ func DecodeHY2URL(s string) (HY2, error) {
123131 fmt .Println ("sni:" , sni )
124132 fmt .Println ("obfs:" , obfs )
125133 fmt .Println ("obfsPassword:" , obfsPassword )
134+ fmt .Println ("fp:" , clientFingerprint )
126135 fmt .Println ("name:" , name )
127136 }
128137 return HY2 {
129- Password : password ,
130- Host : server ,
131- Port : port ,
132- MPort : mport ,
133- Insecure : insecure ,
134- Auth : auth ,
135- UpMbps : upMbps ,
136- DownMbps : downMbps ,
137- ALPN : alpn ,
138- Name : name ,
139- Sni : sni ,
140- Obfs : obfs ,
141- ObfsPassword : obfsPassword ,
138+ Password : password ,
139+ Host : server ,
140+ Port : port ,
141+ MPort : mport ,
142+ Insecure : insecure ,
143+ Auth : auth ,
144+ UpMbps : upMbps ,
145+ DownMbps : downMbps ,
146+ ALPN : alpn ,
147+ Name : name ,
148+ Sni : sni ,
149+ Obfs : obfs ,
150+ ObfsPassword : obfsPassword ,
151+ ClientFingerprint : clientFingerprint ,
142152 }, nil
143153}
154+
155+ // ConvertProxyToHy2 将 Proxy 结构体转换为 HY2 结构体
156+ // 用于从 Clash 格式的代理配置生成 Hysteria2 链接
157+ func ConvertProxyToHy2 (proxy Proxy ) HY2 {
158+ hy2 := HY2 {
159+ Password : proxy .Password ,
160+ Host : proxy .Server ,
161+ Port : int (proxy .Port ),
162+ MPort : proxy .Ports ,
163+ Auth : proxy .Auth_str ,
164+ UpMbps : proxy .Up ,
165+ DownMbps : proxy .Down ,
166+ ALPN : proxy .Alpn ,
167+ Name : proxy .Name ,
168+ Sni : proxy .Sni ,
169+ Obfs : proxy .Obfs ,
170+ ObfsPassword : proxy .Obfs_password ,
171+ ClientFingerprint : proxy .Client_fingerprint ,
172+ Peer : proxy .Peer ,
173+ }
174+
175+ // 处理跳过证书验证
176+ if proxy .Skip_cert_verify {
177+ hy2 .Insecure = 1
178+ }
179+
180+ // 如果SNI为空,尝试使用Servername
181+ if hy2 .Sni == "" && proxy .Servername != "" {
182+ hy2 .Sni = proxy .Servername
183+ }
184+
185+ return hy2
186+ }
0 commit comments