From 737deb7ca5455c9ef0e2aa20803800cc919e9eba Mon Sep 17 00:00:00 2001 From: next-autumn Date: Tue, 16 Mar 2021 17:22:00 +0800 Subject: [PATCH] update vmess share link --- ProxySU_Core/Common/Base64.cs | 23 ++++++++ ProxySU_Core/ProxySU_Core.csproj | 1 + .../ViewModels/XraySettingsViewModel.cs | 56 ++++++++++++++++++- 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 ProxySU_Core/Common/Base64.cs diff --git a/ProxySU_Core/Common/Base64.cs b/ProxySU_Core/Common/Base64.cs new file mode 100644 index 0000000..0a61841 --- /dev/null +++ b/ProxySU_Core/Common/Base64.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySU_Core.Common +{ + public class Base64 + { + public static string Encode(string plainText) + { + var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); + return System.Convert.ToBase64String(plainTextBytes); + } + + public static string Decode(string base64EncodedData) + { + var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); + return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); + } + } +} diff --git a/ProxySU_Core/ProxySU_Core.csproj b/ProxySU_Core/ProxySU_Core.csproj index 71ca95f..abc4170 100644 --- a/ProxySU_Core/ProxySU_Core.csproj +++ b/ProxySU_Core/ProxySU_Core.csproj @@ -117,6 +117,7 @@ App.xaml Code + diff --git a/ProxySU_Core/ViewModels/XraySettingsViewModel.cs b/ProxySU_Core/ViewModels/XraySettingsViewModel.cs index 9da6e85..9f00785 100644 --- a/ProxySU_Core/ViewModels/XraySettingsViewModel.cs +++ b/ProxySU_Core/ViewModels/XraySettingsViewModel.cs @@ -1,4 +1,6 @@ -using ProxySU_Core.Models; +using Newtonsoft.Json; +using ProxySU_Core.Common; +using ProxySU_Core.Models; using ProxySU_Core.ViewModels.Developers; using System; using System.Collections.Generic; @@ -262,7 +264,42 @@ namespace ProxySU_Core.ViewModels public string BuildVmessShareLink(XrayType xrayType) { - return "vmess://xxxxxx"; + var vmess = new Vmess + { + v = "2", + add = settings.Domain, + port = settings.Port.ToString(), + id = settings.UUID, + aid = "0", + net = "", + type = "none", + host = settings.Domain, + path = "", + tls = "tls", + ps = "", + }; + + + switch (xrayType) + { + case XrayType.VMESS_TCP_TLS: + vmess.ps = "vmess-tcp-tls"; + vmess.net = "tcp"; + vmess.type = "http"; + vmess.path = VMESS_TCP_Path; + break; + case XrayType.VMESS_WS_TLS: + vmess.ps = "vmess-ws-tls"; + vmess.net = "ws"; + vmess.type = "none"; + vmess.path = VMESS_WS_Path; + break; + default: + return string.Empty; + } + + var base64Url = Base64.Encode(JsonConvert.SerializeObject(vmess)); + return $"vmess://" + base64Url; } public string BuildVlessShareLink(XrayType xrayType) @@ -347,4 +384,19 @@ namespace ProxySU_Core.ViewModels } + + public class Vmess + { + public string v { get; set; } + public string ps { get; set; } + public string add { get; set; } + public string port { get; set; } + public string id { get; set; } + public string aid { get; set; } + public string net { get; set; } + public string type { get; set; } + public string host { get; set; } + public string path { get; set; } + public string tls { get; set; } + } }