From e1cadc878ab749bc73a79c5ae50609b9d09e36c7 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 2 Feb 2024 10:21:13 +0800 Subject: [PATCH] Improve VmessQRCode json --- v2rayN/v2rayN/Handler/ShareHandler.cs | 6 +-- v2rayN/v2rayN/Mode/VmessQRCode.cs | 58 +++++---------------------- 2 files changed, 12 insertions(+), 52 deletions(-) diff --git a/v2rayN/v2rayN/Handler/ShareHandler.cs b/v2rayN/v2rayN/Handler/ShareHandler.cs index d68895d8..aa66eb5a 100644 --- a/v2rayN/v2rayN/Handler/ShareHandler.cs +++ b/v2rayN/v2rayN/Handler/ShareHandler.cs @@ -48,12 +48,12 @@ namespace v2rayN.Handler VmessQRCode vmessQRCode = new() { - v = item.configVersion.ToString(), + v = item.configVersion, ps = item.remarks.TrimEx(), add = item.address, - port = item.port.ToString(), + port = item.port, id = item.id, - aid = item.alterId.ToString(), + aid = item.alterId, scy = item.security, net = item.network, type = item.headerType, diff --git a/v2rayN/v2rayN/Mode/VmessQRCode.cs b/v2rayN/v2rayN/Mode/VmessQRCode.cs index fec376d9..89697b59 100644 --- a/v2rayN/v2rayN/Mode/VmessQRCode.cs +++ b/v2rayN/v2rayN/Mode/VmessQRCode.cs @@ -1,4 +1,6 @@ -namespace v2rayN.Mode +using System.Text.Json.Serialization; + +namespace v2rayN.Mode { /// /// https://github.com/2dust/v2rayN/wiki/ @@ -6,79 +8,37 @@ [Serializable] internal class VmessQRCode { - /// - /// - /// - public string v { get; set; } = string.Empty; + [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] + public int v { get; set; } = 2; - /// - /// - /// public string ps { get; set; } = string.Empty; - /// - /// - /// public string add { get; set; } = string.Empty; - /// - /// - /// - public string port { get; set; } = string.Empty; + [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] + public int port { get; set; } = 0; - /// - /// - /// public string id { get; set; } = string.Empty; - /// - /// - /// - public string aid { get; set; } = string.Empty; + [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] + public int aid { get; set; } = 0; - /// - /// - /// public string scy { get; set; } = string.Empty; - /// - /// - /// public string net { get; set; } = string.Empty; - /// - /// - /// public string type { get; set; } = string.Empty; - /// - /// - /// public string host { get; set; } = string.Empty; - /// - /// - /// public string path { get; set; } = string.Empty; - /// - /// TLS - /// public string tls { get; set; } = string.Empty; - /// - /// TLS SNI - /// public string sni { get; set; } = string.Empty; - /// - /// TLS alpn - /// public string alpn { get; set; } = string.Empty; - /// - /// TLS fingerprint - /// public string fp { get; set; } = string.Empty; } } \ No newline at end of file