Spaces:
Sleeping
Sleeping
File size: 2,356 Bytes
bb9df9e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | package node
import (
"encoding/json"
"fmt"
"log"
"strings"
)
type Vmess struct {
Add string `json:"add,omitempty"` // 服务器地址
Aid interface{} `json:"aid,omitempty"`
Alpn string `json:"alpn,omitempty"`
Fp string `json:"fp,omitempty"`
Host string `json:"host,omitempty"`
Id string `json:"id,omitempty"`
Net string `json:"net,omitempty"`
Path string `json:"path,omitempty"`
Port interface{} `json:"port,omitempty"`
Ps string `json:"ps,omitempty"`
Scy string `json:"scy,omitempty"`
Sni string `json:"sni,omitempty"`
Tls string `json:"tls,omitempty"`
Type string `json:"type,omitempty"`
V string `json:"v,omitempty"`
}
// 开发者测试
func CallVmessURL() {
vmess := Vmess{
Add: "xx.xxx.ru",
Port: "2095",
Aid: 0,
Scy: "auto",
Net: "ws",
Type: "none",
Id: "7a737f41-b792-4260-94ff-3d864da67380",
Host: "xx.xxx.ru",
Path: "/",
Tls: "",
}
fmt.Println(EncodeVmessURL(vmess))
}
// vmess 编码
func EncodeVmessURL(v Vmess) string {
// 如果备注为空,则使用服务器地址+端口
if v.Ps == "" {
v.Ps = v.Add + ":" + v.Port.(string)
}
// 如果版本为空,则默认为2
if v.V == "" {
v.V = "2"
}
param, _ := json.Marshal(v)
return "vmess://" + Base64Encode(string(param))
}
// vmess 解码
func DecodeVMESSURL(s string) (Vmess, error) {
if !strings.Contains(s, "vmess://") {
return Vmess{}, fmt.Errorf("非vmess协议:%s", s)
}
param := strings.Split(s, "://")[1]
param = Base64Decode(strings.TrimSpace(param))
// fmt.Println(param)
var vmess Vmess
err := json.Unmarshal([]byte(param), &vmess)
if err != nil {
log.Println(err)
return Vmess{}, fmt.Errorf("json格式化失败:%s", param)
}
if vmess.Scy == "" {
vmess.Scy = "auto"
}
// 如果备注为空,则使用服务器地址+端口
if vmess.Ps == "" {
vmess.Ps = vmess.Add + ":" + vmess.Port.(string)
}
if CheckEnvironment() {
fmt.Println("服务器地址", vmess.Add)
fmt.Println("端口", vmess.Port)
fmt.Println("path", vmess.Path)
fmt.Println("uuid", vmess.Id)
fmt.Println("alterId", vmess.Aid)
fmt.Println("cipher", vmess.Scy)
fmt.Println("client-fingerprint", vmess.Fp)
fmt.Println("network", vmess.Net)
fmt.Println("tls", vmess.Tls)
fmt.Println("备注", vmess.Ps)
}
return vmess, nil
}
|