diff --git a/客户端/齐越慧眼/齐越慧眼/ApiHelper.cs b/客户端/齐越慧眼/齐越慧眼/ApiHelper.cs index adf7071..767e77e 100644 --- a/客户端/齐越慧眼/齐越慧眼/ApiHelper.cs +++ b/客户端/齐越慧眼/齐越慧眼/ApiHelper.cs @@ -35,75 +35,15 @@ namespace 齐越慧眼 return "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNjAxODUxNDAyMDAxMzIxOTg0IiwidGVhbUlkIjoiMTU2NzA0ODk5MjgwODc2NzQ4OCIsInNvblRlYW1JZHMiOiIxNTY3MDQ4OTkyODA4NzY3NDg4IiwiZXhwIjoxNzAyMjgyMjUwfQ.nd11fJb99Ous6YuS10oodyFwVOVstEJ87JE6z-NGswU"; #endif - - if (string.IsNullOrEmpty(jwtToken)) - { - - jwtToken = GetMemoryToken().Replace("\r\n", ""); - - } - return jwtToken; } + set { jwtToken = value; } } static int getTokentCount = 0; - public static string GetMemoryToken() - { - lock (lockToken) - { - if (NoLogin) - { - return string.Empty; - } - string memoryName = string.Empty; - string[] args = Environment.GetCommandLineArgs(); - foreach (var arg in args) - { - if (arg.StartsWith("uid:")) - { - memoryName = arg; - } - } - - var result = MemoryHelper.ReadMMF(memoryName); - - if (result.isOk) - { - if (string.IsNullOrEmpty(result.content)) - { - getTokentCount = getTokentCount + 1; - if (getTokentCount <= 3) - { - Thread.Sleep(300); - if (!NoLogin) - return GetMemoryToken(); - } - } - - return result.content; - } - else - { - getTokentCount = getTokentCount + 1; - if (getTokentCount <= 3) - { - Thread.Sleep(300); - if (!NoLogin) - return GetMemoryToken(); - } - MessageBox.Show("登录失败,请稍后重试!"); - NoLogin = true; - // WpfNoticeMsg.NoticeMessage.Show("小程序登录失败!"); - - System.Environment.Exit(0); - return string.Empty; - } - } - } /// /// 登录 diff --git a/客户端/齐越慧眼/齐越慧眼/App.xaml.cs b/客户端/齐越慧眼/齐越慧眼/App.xaml.cs index 8aa9288..03b8963 100644 --- a/客户端/齐越慧眼/齐越慧眼/App.xaml.cs +++ b/客户端/齐越慧眼/齐越慧眼/App.xaml.cs @@ -9,6 +9,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Xaml; +using Utils; using 齐越慧眼.cefhelper; namespace 齐越慧眼 @@ -31,7 +33,12 @@ namespace 齐越慧眼 public App() { - + ApiHelper.JwtToken = MemoryHelper.GetMemoryToken(); + if (string.IsNullOrEmpty(ApiHelper.JwtToken)) + { + MessageBox.Show("登录失败!"); + System.Environment.Exit(0); + } Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var settings = new CefSettings() { diff --git a/客户端/齐越慧眼/齐越慧眼/MemoryHelper.cs b/客户端/齐越慧眼/齐越慧眼/MemoryHelper.cs index 4a15503..4a9198c 100644 --- a/客户端/齐越慧眼/齐越慧眼/MemoryHelper.cs +++ b/客户端/齐越慧眼/齐越慧眼/MemoryHelper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.IO.MemoryMappedFiles; +using System.IO.Pipes; using System.Text; using System.Windows; @@ -9,79 +10,41 @@ namespace Utils { public class MemoryHelper { - public static object lockToken=new object(); public static string GetMemoryToken() { - lock (lockToken) + try { - string memoryName = string.Empty; - string[] args = Environment.GetCommandLineArgs(); - foreach (var arg in args) + string pipeId = Environment.GetCommandLineArgs()[1]; + //创建输入类型匿名管道 + using (PipeStream pipeClient = new AnonymousPipeClientStream(PipeDirection.In, pipeId)) { - if (arg.StartsWith("uid:")) + using (StreamReader sr = new StreamReader(pipeClient)) { - memoryName = arg; - } - } + string temp; - var result = MemoryHelper.ReadMMF(memoryName); + do + { + temp = sr.ReadLine(); + } + while (!temp.StartsWith("SYNC")); - if (result.isOk) - { - return result.content; - } - else - { - System.Environment.Exit(0); - return string.Empty; - } - } - } - /// - /// 写入映射文件 - /// - /// - /// - public static bool WriteMMF(string mapname, string content) - { - MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen(mapname, 1000, MemoryMappedFileAccess.ReadWrite); - if (!string.IsNullOrEmpty(content)) - { - using (var mmfStream = mmf.CreateViewStream()) - { - using (var sw = new System.IO.StreamWriter(mmfStream)) - { - sw.Write(content.Trim()); + while ((temp = sr.ReadLine()) != null) + { + return temp; + } } } - return true; - } - return false; - } - - /// - /// 读取映射文件 - /// - /// - public static (bool isOk, string content) ReadMMF(string mapname) - { - try - { - MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(mapname); - using (var mmfStream = mmf.CreateViewStream(0, 1000, MemoryMappedFileAccess.ReadWrite)) - { - StreamReader reader = new StreamReader(mmfStream); - string jwt = reader.ReadToEnd().Replace("\0","").TrimEnd(); - return (true, jwt); - } + return string.Empty; } catch (Exception ex) { - return (false, null); + return string.Empty; } + } + } }