From 2f26de2196154822c6f3cce8ea51143b8e6f3108 Mon Sep 17 00:00:00 2001 From: xu Date: Wed, 26 Feb 2020 00:49:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=8A=A0=E5=AF=86=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=20=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87ini=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8C=E9=BB=98=E8=AE=A4=E5=86=99=E5=85=A5=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formation/CopterManager.cs | 31 +++++--- Plane.FormationCreator/Util/VersionControl.cs | 77 ++++++++++++++++++- 2 files changed, 94 insertions(+), 14 deletions(-) diff --git a/Plane.FormationCreator/Formation/CopterManager.cs b/Plane.FormationCreator/Formation/CopterManager.cs index 707ff08..f06c4e5 100644 --- a/Plane.FormationCreator/Formation/CopterManager.cs +++ b/Plane.FormationCreator/Formation/CopterManager.cs @@ -15,6 +15,7 @@ using Plane.Communication; using Plane.Util; using System.Windows; using Plane.Windows.Messages; +using System.Reflection; namespace Plane.FormationCreator.Formation { @@ -34,7 +35,7 @@ namespace Plane.FormationCreator.Formation public int AddCopter(ICopter entityObject,bool sortbyid=true) { ////给第三方时候限制数量和时间用 - DateTime dateTime2019 = DateTime.Parse("2020-03-01"); + DateTime dateTime2019 = DateTime.Parse("2020-06-01"); //新增飞机区域限制:内蒙 // if (entityObject.Latitude < 37.4307185218 || entityObject.Latitude > 45.6754821756 @@ -128,10 +129,10 @@ namespace Plane.FormationCreator.Formation public class CopterManager : ObservableObject { + + const string LoginPage = "checkforapp.php"; const string supername = "admin"; const string superpass = "fxmf0622"; - //服务器地址 - const string strUrlPre = "http://111.229.174.37:81/login/checkforapp.php"; //用户级别 const int LEVEL_NORMAL = 1; const int LEVEL_ADMIN = 0; @@ -267,7 +268,7 @@ namespace Plane.FormationCreator.Formation { // 发送请求 StringBuilder sbUrl = new StringBuilder(); // 请求URL内容 - sbUrl.Append(strUrlPre); + sbUrl.Append(VersionControl.ServerURL+ LoginPage); sbUrl.Append("?"); sbUrl.Append("username=" + _UserName); sbUrl.Append("&type=Active"); @@ -280,13 +281,12 @@ namespace Plane.FormationCreator.Formation { // 发送请求 StringBuilder sbUrl = new StringBuilder(); // 请求URL内容 - sbUrl.Append(strUrlPre); + sbUrl.Append(VersionControl.ServerURL + LoginPage); sbUrl.Append("?"); sbUrl.Append("username=" + _UserName); - sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName()); sbUrl.Append("&type=Logout"); - + sbUrl.Append("&ver=" + Assembly.GetExecutingAssembly().GetName().Version.ToString()); String strUrl = sbUrl.ToString(); string errorstr; new AsynDataUtils().AsynGetData(strUrl, null, out errorstr); @@ -313,7 +313,7 @@ namespace Plane.FormationCreator.Formation // 发送请求 StringBuilder sbUrl = new StringBuilder(); // 请求URL内容 - sbUrl.Append(strUrlPre); + sbUrl.Append(VersionControl.ServerURL + LoginPage); sbUrl.Append("?"); sbUrl.Append("username=" + _UserName); sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName()); @@ -322,7 +322,7 @@ namespace Plane.FormationCreator.Formation sbUrl.Append("&orgLng="+ OriginLng.ToString()); sbUrl.Append("&orgLat="+ OriginLat.ToString()); sbUrl.Append("&coptercount=" + Copters.Count().ToString()); - + sbUrl.Append("&ver=" + Assembly.GetExecutingAssembly().GetName().Version.ToString()); String strUrl = sbUrl.ToString(); string errorstr; new AsynDataUtils().AsynGetData(strUrl, null, out errorstr); @@ -393,7 +393,11 @@ namespace Plane.FormationCreator.Formation { NetLogout(); Alert.Show("该账号已在其他地方登录!", "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning); - } + }else + { + NetLogout(); + Alert.Show("登录失败:"+ data, "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning); + } } public void NetLogoin(string username,string password,bool savepassword) { @@ -410,10 +414,12 @@ namespace Plane.FormationCreator.Formation tempSavePassword = savepassword; // 发送请求 StringBuilder sbUrl = new StringBuilder(); // 请求URL内容 - sbUrl.Append(strUrlPre); + sbUrl.Append(VersionControl.ServerURL + LoginPage); sbUrl.Append("?"); sbUrl.Append("username=" + username); sbUrl.Append("&" + "password=" + password); + sbUrl.Append("&type=Login"); + sbUrl.Append("&ver=" + Assembly.GetExecutingAssembly().GetName().Version.ToString()); sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName()); String strUrl = sbUrl.ToString(); string errorstr; @@ -463,12 +469,13 @@ namespace Plane.FormationCreator.Formation tempPassword = oldpassword; // 发送请求 StringBuilder sbUrl = new StringBuilder(); // 请求URL内容 - sbUrl.Append(strUrlPre); + sbUrl.Append(VersionControl.ServerURL + LoginPage); sbUrl.Append("?"); sbUrl.Append("username=" + username); sbUrl.Append("&password=" + oldpassword); sbUrl.Append("&clientname=" + System.Net.Dns.GetHostName()); sbUrl.Append("&type=Chpassword"); + sbUrl.Append("&ver=" + Assembly.GetExecutingAssembly().GetName().Version.ToString()); sbUrl.Append("&newpassword=" + newpassword); String strUrl = sbUrl.ToString(); string errorstr; diff --git a/Plane.FormationCreator/Util/VersionControl.cs b/Plane.FormationCreator/Util/VersionControl.cs index 2678fe3..f83f3bc 100644 --- a/Plane.FormationCreator/Util/VersionControl.cs +++ b/Plane.FormationCreator/Util/VersionControl.cs @@ -1,7 +1,9 @@ using Plane.Windows.IniHelper; using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; @@ -9,6 +11,7 @@ namespace Plane.FormationCreator.Util { public static class VersionControl { + private static string DefaultServrURL= "http://111.229.174.37:81/login/"; public static int Version = 0; /// /// 是否是完整版本 仅在Version = 255时为完整版本 @@ -24,6 +27,8 @@ namespace Plane.FormationCreator.Util public static string Password = ""; public static bool IssavePassword = false; + public static string ServerURL = ""; + public static void SetUserLever(int vuserlever) { if (vuserlever==0) @@ -58,7 +63,7 @@ namespace Plane.FormationCreator.Util if (readvalue != "") Username = readvalue; - readvalue = iniFiles.IniReadvalue("Login", "Password"); + readvalue = Decrypt(iniFiles.IniReadvalue("Login", "Password")); if (readvalue != "") Password = readvalue; @@ -67,6 +72,19 @@ namespace Plane.FormationCreator.Util if (readvalue != "" && bool.TryParse(readvalue, out boolTemp)) IssavePassword = bool.Parse(readvalue); + readvalue = iniFiles.IniReadvalue("Default", "Server"); + if (readvalue != "") + ServerURL = readvalue; + else + ServerURL = DefaultServrURL; + + + + + + + + } public static void SaveLogininfoToIni(string username,string password,bool issavepassword) @@ -77,7 +95,7 @@ namespace Plane.FormationCreator.Util IniFiles iniFiles = new IniFiles(); iniFiles.IniWritevalue("Login", "Username", username); if (issavepassword) - iniFiles.IniWritevalue("Login", "Password", password); + iniFiles.IniWritevalue("Login", "Password", Encrypt(password)); else iniFiles.IniWritevalue("Login", "Password", ""); @@ -87,7 +105,62 @@ namespace Plane.FormationCreator.Util } + static string encryptKey = "fxmf";//字符串加密密钥(注意:密钥只能是4位) + private static string Encrypt(string str) + {//加密字符串 + + try + { + byte[] key = Encoding.Unicode.GetBytes(encryptKey);//密钥 + byte[] data = Encoding.Unicode.GetBytes(str);//待加密字符串 + + DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();//加密、解密对象 + MemoryStream MStream = new MemoryStream();//内存流对象 + + //用内存流实例化加密流对象 + CryptoStream CStream = new CryptoStream(MStream, descsp.CreateEncryptor(key, key), CryptoStreamMode.Write); + CStream.Write(data, 0, data.Length);//向加密流中写入数据 + CStream.FlushFinalBlock();//将数据压入基础流 + byte[] temp = MStream.ToArray();//从内存流中获取字节序列 + CStream.Close();//关闭加密流 + MStream.Close();//关闭内存流 + + return Convert.ToBase64String(temp);//返回加密后的字符串 + } + catch + { + return str; + } + } + + + private static string Decrypt(string str) + {//解密字符串 + + try + { + byte[] key = Encoding.Unicode.GetBytes(encryptKey);//密钥 + byte[] data = Convert.FromBase64String(str);//待解密字符串 + + DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();//加密、解密对象 + MemoryStream MStream = new MemoryStream();//内存流对象 + + //用内存流实例化解密流对象 + CryptoStream CStream = new CryptoStream(MStream, descsp.CreateDecryptor(key, key), CryptoStreamMode.Write); + CStream.Write(data, 0, data.Length);//向加密流中写入数据 + CStream.FlushFinalBlock();//将数据压入基础流 + byte[] temp = MStream.ToArray();//从内存流中获取字节序列 + CStream.Close();//关闭加密流 + MStream.Close();//关闭内存流 + + return Encoding.Unicode.GetString(temp);//返回解密后的字符串 + } + catch + { + return str; + } + } } }