From 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期五, 31 三月 2023 11:36:45 +0800 Subject: [PATCH] 1 --- Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs | 1982 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 995 insertions(+), 987 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs b/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs index 41c2b3f..f9793d5 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs @@ -1,1092 +1,1100 @@ -锘�/* -鏇存柊浜咵MQ杩炴帴鏂瑰紡 -*/ -using System.Collections.Generic; -using System; -using MQTTnet.Client; -using System.Threading.Tasks; -using Shared; -using Shared.SimpleControl; -using MQTTnet; -using System.Text; -using System.Security.Cryptography; -using System.IO; -using Shared.SimpleControl.Phone; +锘�///* +//鏇存柊浜咵MQ杩炴帴鏂瑰紡 +//*/ +//using System.Collections.Generic; +//using System; +//using MQTTnet.Client; +//using System.Threading.Tasks; +//using Shared; +//using Shared.SimpleControl; +//using MQTTnet; +//using System.Text; +//using System.Security.Cryptography; +//using System.IO; +//using Shared.SimpleControl.Phone; -namespace SmartHome -{ - public static class MqttCommon - { - static string mqttEncryptKey = ""; - static string checkGatewayTopicBase64 = ""; - static RemoteMACInfo CurRemoteMACInfo = null; +//namespace SmartHome +//{ +// public static class MqttCommon +// { +// static string mqttEncryptKey = ""; +// static string checkGatewayTopicBase64 = ""; +// static RemoteMACInfo CurRemoteMACInfo = null; - /// <summary> - /// 鎵嬫満鏍囪瘑 - /// </summary> - static Guid currentGuid = Guid.NewGuid (); +// /// <summary> +// /// 鎵嬫満鏍囪瘑 +// /// </summary> +// static Guid currentGuid = Guid.NewGuid (); - /// <summary> - /// 澶栫綉鐨凪QTT鏄惁姝e湪杩炴帴 - /// </summary> - /// <summary> - /// 杩滅▼MqttClient - /// </summary> - /// <summary> - /// 杩滅▼MqttClient - /// </summary> - public static IMqttClient RemoteMqttClient = new MqttFactory ().CreateMqttClient (); +// /// <summary> +// /// 澶栫綉鐨凪QTT鏄惁姝e湪杩炴帴 +// /// </summary> +// /// <summary> +// /// 杩滅▼MqttClient +// /// </summary> +// /// <summary> +// /// 杩滅▼MqttClient +// /// </summary> +// public static IMqttClient RemoteMqttClient = new MqttFactory ().CreateMqttClient (); - static bool thisShowTip = true; - static string mqttRequestParToken=""; +// static bool thisShowTip = true; +// static string mqttRequestParToken=""; - /// <summary> - /// 鏂紑杩滅▼Mqtt鐨勯摼鎺� - /// </summary> - public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient (string s = "") - { - try { - if (remoteIsConnected) { - remoteIsConnected = false; - System.Console.WriteLine ($"Remote涓诲姩鏂紑_{s}"); - //await RemoteMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None); - await RemoteMqttClient.DisconnectAsync (); - } - } catch (Exception e) { - System.Console.WriteLine ($"Remote鏂紑閫氳杩炴帴鍑哄紓甯�:{e.Message}"); - } - } - static DateTime dateTime = DateTime.MinValue; - /// <summary> - /// 澶栫綉鐨凪QTT鏄惁姝e湪杩炴帴 - /// </summary> - static bool remoteMqttIsConnecting; - static bool remoteIsConnected; - /// <summary> - /// 鍚姩杩滅▼Mqtt - /// </summary> - public static async System.Threading.Tasks.Task StartCloudMqtt () - { +// /// <summary> +// /// 鏂紑杩滅▼Mqtt鐨勯摼鎺� +// /// </summary> +// public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient (string s = "") +// { +// try { +// if (remoteIsConnected) { +// remoteIsConnected = false; +// System.Console.WriteLine ($"Remote涓诲姩鏂紑_{s}"); +// //await RemoteMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None); +// await RemoteMqttClient.DisconnectAsync (); +// } +// } catch (Exception e) { +// System.Console.WriteLine ($"Remote鏂紑閫氳杩炴帴鍑哄紓甯�:{e.Message}"); +// } +// } +// static DateTime dateTime = DateTime.MinValue; +// /// <summary> +// /// 澶栫綉鐨凪QTT鏄惁姝e湪杩炴帴 +// /// </summary> +// static bool remoteMqttIsConnecting; +// static bool remoteIsConnected; +// /// <summary> +// /// 鍚姩杩滅▼Mqtt +// /// </summary> +// public static async System.Threading.Tasks.Task StartCloudMqtt () +// { - Application.RunOnMainThread (() => { - if (5 < (DateTime.Now - dateTime).TotalSeconds) { - return; - } - //MainPage.Loading.Start (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.Connecting)); - dateTime = DateTime.Now; - }); - if (!MainPage.LoginUser.IsLogin) { - return; - } - //杩藉姞锛氭病鏈夎繙绋嬭繛鎺ョ殑鏉冮檺 - if (remoteMqttIsConnecting - || remoteIsConnected) { - return; - } +// Application.RunOnMainThread (() => { +// if (5 < (DateTime.Now - dateTime).TotalSeconds) { +// return; +// } +// //MainPage.Loading.Start (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.Connecting)); +// dateTime = DateTime.Now; +// }); +// if (!MainPage.LoginUser.IsLogin) { +// return; +// } +// //杩藉姞锛氭病鏈夎繙绋嬭繛鎺ョ殑鏉冮檺 +// if (remoteMqttIsConnecting +// || remoteIsConnected) { +// return; +// } - await System.Threading.Tasks.Task.Factory.StartNew (async () => - { - try { - lock (RemoteMqttClient) { - //琛ㄧず鍚庨潰灏嗚繘琛岃繛鎺� - remoteMqttIsConnecting = true; +// await System.Threading.Tasks.Task.Factory.StartNew (async () => +// { +// try { +// lock (RemoteMqttClient) { +// //琛ㄧず鍚庨潰灏嗚繘琛岃繛鎺� +// remoteMqttIsConnecting = true; - #region 鍒濆鍖栬繙绋婱qtt - //(3)褰揫杩炴帴浜戠鐨凪qtt鎴愬姛鍚嶿鎴栬�匸浠ュ強鍚庨潰App閫氳繃浜戠Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒颁簯绔暟鎹寘鍝嶅簲鏃跺湪mqttServerClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊 - if (RemoteMqttClient.ApplicationMessageReceivedHandler == null) { - RemoteMqttClient.UseApplicationMessageReceivedHandler ((e) => { - try { - if (!RemoteMqttClient.IsConnected || !CommonPage.IsRemote) { - return; - } - var aesDecryptTopic = e.ApplicationMessage.Topic; - var aesDecryptPayload = e.ApplicationMessage.Payload; - //Console.WriteLine ("Topic={0}", aesDecryptTopic); +// #region 鍒濆鍖栬繙绋婱qtt +// //(3)褰揫杩炴帴浜戠鐨凪qtt鎴愬姛鍚嶿鎴栬�匸浠ュ強鍚庨潰App閫氳繃浜戠Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒颁簯绔暟鎹寘鍝嶅簲鏃跺湪mqttServerClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊 +// if (RemoteMqttClient.ApplicationMessageReceivedHandler == null) { +// RemoteMqttClient.UseApplicationMessageReceivedHandler ((e) => { +// try { +// if (!RemoteMqttClient.IsConnected || !CommonPage.IsRemote) { +// return; +// } +// var aesDecryptTopic = e.ApplicationMessage.Topic; +// var aesDecryptPayload = e.ApplicationMessage.Payload; +// //Console.WriteLine ("Topic={0}", aesDecryptTopic); - if (aesDecryptTopic == $"NotifyBusGateWayInfoChagne/{CurRemoteMACInfo.md5_mac_string}") {//缃戝叧涓婄嚎锛岄渶瑕佹洿鏂癮eskey - //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛� - var gatewayListUrl = @"https://developer.hdlcontrol.com/Center/Center/GetGatewayPagger"; //App銆丅uspro杞欢鐧诲綍鍚庤幏鍙栫綉鍏冲垪琛� http 璇锋眰 - var gatewayListRequestPar = new RemoteRequestParameters () { Mac = CurRemoteMACInfo.mac, LoginAccessToken = mqttRequestParToken, RequestVersion = "RequestVersion1", RequestProtocolType = 0, RequestSource = 1 }; - var gatewayListRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (gatewayListRequestPar), false, false, gatewayListUrl); - var gatewayListRequestResult_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttRemoteInfo> (gatewayListRequestResult.ResponseData.ToString ()); - if (gatewayListRequestResult_Obj != null && gatewayListRequestResult_Obj.pageData.Count > 0) { - CurRemoteMACInfo.aesKey = gatewayListRequestResult_Obj.pageData [0].aesKey; - mqttEncryptKey = CurRemoteMACInfo.aesKey; - } - } +// if (aesDecryptTopic == $"NotifyBusGateWayInfoChagne/{CurRemoteMACInfo.md5_mac_string}") {//缃戝叧涓婄嚎锛岄渶瑕佹洿鏂癮eskey +// //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛� +// var gatewayListUrl = @"https://developer.hdlcontrol.com/Center/Center/GetGatewayPagger"; //App銆丅uspro杞欢鐧诲綍鍚庤幏鍙栫綉鍏冲垪琛� http 璇锋眰 +// var gatewayListRequestPar = new RemoteRequestParameters () { Mac = CurRemoteMACInfo.mac, LoginAccessToken = mqttRequestParToken, RequestVersion = "RequestVersion1", RequestProtocolType = 0, RequestSource = 1 }; +// var gatewayListRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (gatewayListRequestPar), false, false, gatewayListUrl); +// var gatewayListRequestResult_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttRemoteInfo> (gatewayListRequestResult.ResponseData.ToString ()); +// if (gatewayListRequestResult_Obj != null && gatewayListRequestResult_Obj.pageData.Count > 0) { +// CurRemoteMACInfo.aesKey = gatewayListRequestResult_Obj.pageData [0].aesKey; +// mqttEncryptKey = CurRemoteMACInfo.aesKey; +// } +// } - if (aesDecryptTopic == $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/Common/CheckGateway") { - // = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/OldON"; - var ss = CommonPage.MyEncodingUTF8.GetString (aesDecryptPayload); - var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (ss); - if (obj == null) { - return; - } - switch (obj.StateCode) { - case "HDLUdpDataForwardServerMqttClientNoOnLine": - case "NoOnline": - case "NetworkAnomaly"://涓嶅湪绾� - MainPage.AddTip ("Gateway offline"); - Application.RunOnMainThread (() => { - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - break; - case "NoRecord"://MAC涓嶆纭� - MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.MACError)); - Application.RunOnMainThread (() => { - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - break; - case "Success": - MainPage.AddTip (UserConfig.Instance.CurrentRegion.RegionName + ":" + Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkSuccess)); - break; - default: - MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkLoser)); - Application.RunOnMainThread (() => { - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - break; - } - } else { - if (!string.IsNullOrEmpty (mqttEncryptKey)) { - aesDecryptTopic = Shared.Securitys.EncryptionService.AesDecryptTopic (e.ApplicationMessage.Topic, mqttEncryptKey); - aesDecryptPayload = Shared.Securitys.EncryptionService.AesDecryptPayload (e.ApplicationMessage.Payload, mqttEncryptKey); - } else { - aesDecryptTopic = e.ApplicationMessage.Topic; - aesDecryptPayload = e.ApplicationMessage.Payload; - } - } - var packet = new Packet (); - packet.Bytes = aesDecryptPayload; - packet.Manager (); - } catch { } - }); - } +// if (aesDecryptTopic == $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/Common/CheckGateway") { +// MainPage.WiFiStatus = "CrabtreeAdd/CloudUnlink.png"; +// // = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/OldON"; +// var ss = CommonPage.MyEncodingUTF8.GetString (aesDecryptPayload); +// var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (ss); +// if (obj == null) { +// return; +// } +// switch (obj.StateCode) { +// case "HDLUdpDataForwardServerMqttClientNoOnLine": +// case "NoOnline": +// case "NetworkAnomaly"://涓嶅湪绾� +// MainPage.AddTip ("Gateway offline"); +// //Application.RunOnMainThread (() => { +// // Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// //}); +// break; +// case "NoRecord"://MAC涓嶆纭� +// MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.MACError)); +// //Application.RunOnMainThread (() => { +// // Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// //}); +// break; +// case "Success": +// MainPage.AddTip (UserConfig.Instance.CurrentRegion.RegionName + ":" + Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkSuccess)); +// MainPage.WiFiStatus = "CrabtreeAdd/CloudLink.png"; +// break; +// default: +// MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkLoser)); +// //Application.RunOnMainThread (() => { +// // Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// //}); +// break; +// } +// Application.RunOnMainThread (() => { +// UserMiddle.btnLinkStatus.UnSelectedImagePath = MainPage.WiFiStatus; +// }); +// } else { +// if (!string.IsNullOrEmpty (mqttEncryptKey)) { +// aesDecryptTopic = Shared.Securitys.EncryptionService.AesDecryptTopic (e.ApplicationMessage.Topic, mqttEncryptKey); +// aesDecryptPayload = Shared.Securitys.EncryptionService.AesDecryptPayload (e.ApplicationMessage.Payload, mqttEncryptKey); +// } else { +// aesDecryptTopic = e.ApplicationMessage.Topic; +// aesDecryptPayload = e.ApplicationMessage.Payload; +// } +// } +// var packet = new Packet (); +// packet.Bytes = aesDecryptPayload; +// packet.Manager (); +// } catch { } +// }); +// } - if (RemoteMqttClient.DisconnectedHandler == null) { - RemoteMqttClient.UseDisconnectedHandler (async (e) => { - System.Console.WriteLine ($"杩滅▼杩炴帴鏂紑"); - await DisConnectRemoteMqttClient ("StartRemoteMqtt.DisconnectedHandler"); - //await StartRemoteMqtt(); - if (thisShowTip) { - if (CommonPage.IsRemote) { - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - } - } else { - thisShowTip = true; - } - }); - } - if (RemoteMqttClient.ConnectedHandler == null) { - RemoteMqttClient.UseConnectedHandler (async (e) => { - Shared.Application.RunOnMainThread (() => { - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = 0xAA69E64A; - }); - Shared.SimpleControl.Phone.UserMiddle.ReadAllDeviceStatus (); - System.Console.WriteLine ($"杩滅▼杩炴帴鎴愬姛"); - MainPage.WiFiStatus = "CrabtreeAdd/CloudLink.png"; - UserMiddle.btnLinkStatus.UnSelectedImagePath = MainPage.WiFiStatus; - if (CurRemoteMACInfo != null) { - if (CurRemoteMACInfo.isValid == "InValid") { - MainPage.AddTip ("Remote failed,gateway offline"); - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - } else { - MqttRemoteSend (new byte [] { 0 }, 3); - //Application.RunOnMainThread (() => { - // MainPage.Loading.Hide (); - // Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = 0xAA69E64A; - // Shared.SimpleControl.Phone.UserMiddle.ReadAllDeviceStatus (); - //}); - //MainPage.AddTip (UserConfig.Instance.CurrentRegion.RegionName + ":" + Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkSuccess)); - } - } +// if (RemoteMqttClient.DisconnectedHandler == null) { +// RemoteMqttClient.UseDisconnectedHandler (async (e) => { +// System.Console.WriteLine ($"杩滅▼杩炴帴鏂紑"); +// await DisConnectRemoteMqttClient ("StartRemoteMqtt.DisconnectedHandler"); +// //await StartRemoteMqtt(); +// if (thisShowTip) { +// if (CommonPage.IsRemote) { +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// //Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// }); +// } +// } else { +// thisShowTip = true; +// } +// }); +// } +// if (RemoteMqttClient.ConnectedHandler == null) { +// RemoteMqttClient.UseConnectedHandler (async (e) => { +// //Shared.Application.RunOnMainThread (() => { +// // Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = 0xAA69E64A; +// //}); +// Shared.SimpleControl.Phone.UserMiddle.ReadAllDeviceStatus (); +// System.Console.WriteLine ($"杩滅▼杩炴帴鎴愬姛"); +// MainPage.WiFiStatus = "CrabtreeAdd/CloudLink.png"; +// UserMiddle.btnLinkStatus.UnSelectedImagePath = MainPage.WiFiStatus; +// if (CurRemoteMACInfo != null) { +// if (CurRemoteMACInfo.isValid == "InValid") { +// MainPage.AddTip ("Remote failed,gateway offline"); +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// //Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// }); +// } else { +// MqttRemoteSend (new byte [] { 0 }, 3); +// //Application.RunOnMainThread (() => { +// // MainPage.Loading.Hide (); +// // Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = 0xAA69E64A; +// // Shared.SimpleControl.Phone.UserMiddle.ReadAllDeviceStatus (); +// //}); +// //MainPage.AddTip (UserConfig.Instance.CurrentRegion.RegionName + ":" + Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkSuccess)); +// } +// } - }); - } - #endregion - } +// }); +// } +// #endregion +// } - try { - try { - //鏂紑鍚庨噸鏂伴摼鎺ラ渶瑕侀噸鏂扮櫥褰曡幏鍙栬繛鎺ョ殑瀵嗙爜 - var requestObj = new LoginObj () { Account = MainPage.LoginUser.AccountString.ToLower (), Password = MainPage.LoginUser.Password, Company = MainPage.SoftSmsType }; - var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); - var tempResult = MainPage.RequestHttps ("Login", requestJson, false); - if (tempResult == null) { - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - return; - } - var responsePack = tempResult.ResponseData; - var dictrionaryResult = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (tempResult.ResponseData.ToString ()); - var mqttRequestPar = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes> (tempResult.ResponseData.ToString ()); - mqttRequestParToken = mqttRequestPar.Token; - //杩樻湁绉嶆儏鍐垫槸鍚屼竴涓狪D 鏈夊涓澶囩敤杩欎釜id杩炴帴锛堜細瀵艰嚧涓柇锛� - //mqttEncryptKey = dictrionaryResult ["HdlOnMqttKey"]?.ToString (); - var url = dictrionaryResult ["ConnectMqttBrokerLoadSubDomain"]?.ToString (); - var clientId = dictrionaryResult ["ConnectMqttClientId"]?.ToString (); - var username = dictrionaryResult ["ConnectMqttBrokerUserName"]?.ToString (); - var passwordRemote = dictrionaryResult ["ConnectMqttBrokerPwd"]?.ToString (); +// try { +// try { +// //鏂紑鍚庨噸鏂伴摼鎺ラ渶瑕侀噸鏂扮櫥褰曡幏鍙栬繛鎺ョ殑瀵嗙爜 +// var requestObj = new LoginObj () { Account = MainPage.LoginUser.AccountString.ToLower (), Password = MainPage.LoginUser.Password, Company = MainPage.SoftSmsType }; +// var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); +// var tempResult = MainPage.RequestHttps ("Login", requestJson, false); +// if (tempResult == null) { +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// //Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// }); +// return; +// } +// var responsePack = tempResult.ResponseData; +// var dictrionaryResult = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (tempResult.ResponseData.ToString ()); +// var mqttRequestPar = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes> (tempResult.ResponseData.ToString ()); +// mqttRequestParToken = mqttRequestPar.Token; +// //杩樻湁绉嶆儏鍐垫槸鍚屼竴涓狪D 鏈夊涓澶囩敤杩欎釜id杩炴帴锛堜細瀵艰嚧涓柇锛� +// //mqttEncryptKey = dictrionaryResult ["HdlOnMqttKey"]?.ToString (); +// var url = dictrionaryResult ["ConnectMqttBrokerLoadSubDomain"]?.ToString (); +// var clientId = dictrionaryResult ["ConnectMqttClientId"]?.ToString (); +// var username = dictrionaryResult ["ConnectMqttBrokerUserName"]?.ToString (); +// var passwordRemote = dictrionaryResult ["ConnectMqttBrokerPwd"]?.ToString (); - if (clientId == null || username == null || passwordRemote == null) { - return; - } +// if (clientId == null || username == null || passwordRemote == null) { +// return; +// } - var requestObj3 = new GatewayByRegionListObj () { RegionID = UserConfig.Instance.CurrentRegion.RegionID }; - var requestJson3 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj3); - var revertObj3 = MainPage.RequestHttps ("GatewayByRegionList", requestJson3, true, false); - if (revertObj3.StateCode == "SUCCESS") { - var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GatewayRes>> (revertObj3.ResponseData.ToString ()); - var gatewayList = responseDataObj; - if (gatewayList != null && gatewayList.Count > 0) { - UserConfig.Instance.CurrentRegion.MAC = gatewayList [0].MAC; - UserConfig.Instance.SaveUserConfig (); - Console.WriteLine ("Remote mqtt get Region MAC : " + gatewayList [0].MAC); - } - } +// var requestObj3 = new GatewayByRegionListObj () { RegionID = UserConfig.Instance.CurrentRegion.RegionID }; +// var requestJson3 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj3); +// var revertObj3 = MainPage.RequestHttps ("GatewayByRegionList", requestJson3, true, false); +// if (revertObj3.StateCode == "SUCCESS") { +// var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GatewayRes>> (revertObj3.ResponseData.ToString ()); +// var gatewayList = responseDataObj; +// if (gatewayList != null && gatewayList.Count > 0) { +// UserConfig.Instance.CurrentRegion.MAC = gatewayList [0].MAC; +// UserConfig.Instance.SaveUserConfig (); +// Console.WriteLine ("Remote mqtt get Region MAC : " + gatewayList [0].MAC); +// } +// } - if (tempResult == null) { - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - return; - } - //--绗竴姝ワ細鑾峰彇mqtt閾炬帴鍙傛暟 - var mqttInfoUrl = @"https://developer.hdlcontrol.com/Center/Center/GetConnMqttInfo";//鑾峰彇杩炴帴杩滅▼浜戠Emq Mqtt 鏈嶅姟鍣ㄨ繛鎺ヤ俊鎭� - var mqttInfoRequestPar = new RemoteRequestParameters () { LoginAccessToken = mqttRequestParToken, RequestVersion = MainPage.CodeIDString, RequestProtocolType = 0, RequestSource = 1 }; - var mqttInfoRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (mqttInfoRequestPar), false, false, mqttInfoUrl); +// if (tempResult == null) { +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// //Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// }); +// return; +// } +// try { +// //--绗竴姝ワ細鑾峰彇mqtt閾炬帴鍙傛暟 +// var mqttInfoUrl = @"https://developer.hdlcontrol.com/Center/Center/GetConnMqttInfo";//鑾峰彇杩炴帴杩滅▼浜戠Emq Mqtt 鏈嶅姟鍣ㄨ繛鎺ヤ俊鎭� +// var mqttInfoRequestPar = new RemoteRequestParameters () { LoginAccessToken = mqttRequestParToken, RequestVersion = MainPage.CodeIDString, RequestProtocolType = 0, RequestSource = 1 }; +// var mqttInfoRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (mqttInfoRequestPar), false, false, mqttInfoUrl); +// if (mqttInfoRequestResult != null && mqttInfoRequestResult.ResponseData != null) { +// var mqttInfoRequestResult_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttInfo> (mqttInfoRequestResult.ResponseData.ToString ()); +// if (mqttInfoRequestResult_Obj != null) { +// url = mqttInfoRequestResult_Obj.connEmqDomainPort; +// clientId = mqttInfoRequestResult_Obj.connEmqClientId; +// username = mqttInfoRequestResult_Obj.connEmqUserName; +// passwordRemote = mqttInfoRequestResult_Obj.connEmqPwd; +// //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛� +// var gatewayListUrl = @"https://developer.hdlcontrol.com/Center/Center/GetGatewayPagger"; //App銆丅uspro杞欢鐧诲綍鍚庤幏鍙栫綉鍏冲垪琛� http 璇锋眰 +// var gatewayListRequestPar = new RemoteRequestParameters () { LoginAccessToken = mqttRequestParToken, RequestVersion = "RequestVersion1", RequestProtocolType = 0, RequestSource = 1 }; +// var gatewayListRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (gatewayListRequestPar), false, false, gatewayListUrl); +// var gatewayListRequestResult_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttRemoteInfo> (gatewayListRequestResult.ResponseData.ToString ()); +// //--鎵惧嚭鏄惁瀛樺湪鍖归厤褰撳墠浣忓畢鐨刴ac锛屽瓨鍦ㄥ啀杩涜杩滅▼銆� +// CurRemoteMACInfo = gatewayListRequestResult_Obj.pageData.Find ((obj) => obj.mac == UserConfig.Instance.CurrentRegion.MAC); +// CurRemoteMACInfo = gatewayListRequestResult_Obj.pageData [0]; +// if (CurRemoteMACInfo != null) { +// CurRemoteMACInfo.LoginAccessToken = mqttRequestPar.Token; +// mqttEncryptKey = CurRemoteMACInfo.aesKey; +// var options1 = new MQTTnet.Client.Options.MqttClientOptionsBuilder () +// .WithClientId (clientId) +// .WithTcpServer (url.Split (':') [1].Substring ("//".Length), int.Parse (url.Split (':') [2])) +// .WithCredentials (username, passwordRemote) +// .WithCleanSession () +// .WithCommunicationTimeout (new TimeSpan (0, 0, 20)) +// .Build (); - if (mqttInfoRequestResult != null && mqttInfoRequestResult.ResponseData != null) { - try { - var mqttInfoRequestResult_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttInfo> (mqttInfoRequestResult.ResponseData.ToString ()); - if (mqttInfoRequestResult_Obj != null) { - url = mqttInfoRequestResult_Obj.connEmqDomainPort; - clientId = mqttInfoRequestResult_Obj.connEmqClientId; - username = mqttInfoRequestResult_Obj.connEmqUserName; - passwordRemote = mqttInfoRequestResult_Obj.connEmqPwd; - //----绗簩姝ワ細璇诲彇璐﹀彿涓嬮潰鐨勭綉鍏冲垪琛� - var gatewayListUrl = @"https://developer.hdlcontrol.com/Center/Center/GetGatewayPagger"; //App銆丅uspro杞欢鐧诲綍鍚庤幏鍙栫綉鍏冲垪琛� http 璇锋眰 - var gatewayListRequestPar = new RemoteRequestParameters () { LoginAccessToken = mqttRequestParToken, RequestVersion = "RequestVersion1", RequestProtocolType = 0, RequestSource = 1 }; - var gatewayListRequestResult = MainPage.RequestHttps ("", Newtonsoft.Json.JsonConvert.SerializeObject (gatewayListRequestPar), false, false, gatewayListUrl); - var gatewayListRequestResult_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<MqttRemoteInfo> (gatewayListRequestResult.ResponseData.ToString ()); - //--鎵惧嚭鏄惁瀛樺湪鍖归厤褰撳墠浣忓畢鐨刴ac锛屽瓨鍦ㄥ啀杩涜杩滅▼銆� - CurRemoteMACInfo = gatewayListRequestResult_Obj.pageData.Find ((obj) => obj.mac == UserConfig.Instance.CurrentRegion.MAC); - if (CurRemoteMACInfo != null) { - CurRemoteMACInfo.LoginAccessToken = mqttRequestPar.Token; - mqttEncryptKey = CurRemoteMACInfo.aesKey; - var options1 = new MQTTnet.Client.Options.MqttClientOptionsBuilder () - .WithClientId (clientId) - .WithTcpServer (url.Split (':') [1].Substring ("//".Length), int.Parse (url.Split (':') [2])) - .WithCredentials (username, passwordRemote) - .WithCleanSession () - .WithCommunicationTimeout (new TimeSpan (0, 0, 20)) - .Build (); +// await DisConnectRemoteMqttClient ("StartRemoteMqtt"); +// await RemoteMqttClient.ConnectAsync (options1); +// remoteIsConnected = true; +// await MqttRemoteSend (new byte [] { 0 }, 1); +// await MqttRemoteSend (new byte [] { 0 }, 2); +// } +// } - await DisConnectRemoteMqttClient ("StartRemoteMqtt"); - await RemoteMqttClient.ConnectAsync (options1); - remoteIsConnected = true; - await MqttRemoteSend (new byte [] { 0 }, 1); - await MqttRemoteSend (new byte [] { 0 }, 2); - } - } - } catch { } - } - } catch (Exception ex) { - System.Console.WriteLine ("============>" + ex.Message); - Application.RunOnMainThread (() => { - //MainPage.Loading.Hide (); - //isConnecting = false.ToString (); +// } +// } catch (Exception ex) { +// Console.WriteLine (ex.Message); +// } +// } catch (Exception ex) { +// System.Console.WriteLine ("============>" + ex.Message); +// Application.RunOnMainThread (() => { +// //MainPage.Loading.Hide (); +// //isConnecting = false.ToString (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; -#if DEBUG - Alert a = new Alert (remoteMqttIsConnecting.ToString (), ex.Message, "Close"); - a.Show (); -#endif - }); - } finally { - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - }); - } - } catch { } finally { - //鏈�缁堣閲婃斁杩炴帴鐘舵�� - remoteMqttIsConnecting = false; - } - } catch (Exception ex) { - System.Console.WriteLine ($"杩滅▼杩炴帴閫氳杩炴帴鍑哄紓甯�:{ex.Message}"); - } - }); - } +// //Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +//#if DEBUG +// Alert a = new Alert (remoteMqttIsConnecting.ToString (), ex.Message, "Close"); +// a.Show (); +//#endif +// }); +// } finally { +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// }); +// } +// } catch { } finally { +// //鏈�缁堣閲婃斁杩炴帴鐘舵�� +// remoteMqttIsConnecting = false; +// } +// } catch (Exception ex) { +// System.Console.WriteLine ($"杩滅▼杩炴帴閫氳杩炴帴鍑哄紓甯�:{ex.Message}"); +// } +// }); +// } - /// <summary> - /// - /// </summary> - /// <param name="message">闄勫姞鏁版嵁鍖�</param> - /// <param name="optionType">鎿嶄綔绫诲瀷锛�0=缃戝叧鎺у埗锛�1=璁㈤槄缃戝叧鏁版嵁;2=璁㈤槄缃戝叧涓婄嚎鏁版嵁</param> - /// <returns></returns> - public static async Task MqttRemoteSend (byte [] message, int optionType = 0) - { - try { - var topicName = @"/" + MainPage.LoginUser.AccountString.ToLower () + @"/" + UserConfig.Instance.GatewayMAC.Replace (".", "") + @"/" + currentGuid; - switch (optionType) { - case 0: - var messageSend = message; - if (string.IsNullOrEmpty (mqttEncryptKey)) { - topicName = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/OldON"; - } else { - topicName = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/NewON"; - messageSend = Shared.Securitys.EncryptionService.AesEncryptPayload (message, mqttEncryptKey); - } - //base64鍔犲瘑 - var m = new MqttApplicationMessage { Topic = topicName, Payload = messageSend, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; - if (remoteIsConnected) { - try { - await RemoteMqttClient.PublishAsync (m); - } catch (Exception e) { - await DisConnectRemoteMqttClient (e.Message); - await StartCloudMqtt (); - if (remoteIsConnected) { - await RemoteMqttClient.PublishAsync (m); - } - } - } - break; - case 1: - topicName = $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/Common/#"; - if (remoteIsConnected) { - try { - await RemoteMqttClient.SubscribeAsync (topicName); - } catch (Exception e) { - await DisConnectRemoteMqttClient (e.Message); - await StartCloudMqtt (); - if (remoteIsConnected) { - await RemoteMqttClient.SubscribeAsync (topicName); - } - } - } - break; - case 2: - var macStr = CurRemoteMACInfo.mac.ToUpper (); - char [] cArrs = macStr.ToCharArray (); - Array.Reverse (cArrs); - var sss = string.Join (string.Empty, cArrs); +// /// <summary> +// /// +// /// </summary> +// /// <param name="message">闄勫姞鏁版嵁鍖�</param> +// /// <param name="optionType">鎿嶄綔绫诲瀷锛�0=缃戝叧鎺у埗锛�1=璁㈤槄缃戝叧鏁版嵁;2=璁㈤槄缃戝叧涓婄嚎鏁版嵁</param> +// /// <returns></returns> +// public static async Task MqttRemoteSend (byte [] message, int optionType = 0) +// { +// try { +// var topicName = @"/" + MainPage.LoginUser.AccountString.ToLower () + @"/" + UserConfig.Instance.GatewayMAC.Replace (".", "") + @"/" + currentGuid; +// switch (optionType) { +// case 0: +// var messageSend = message; +// if (string.IsNullOrEmpty (mqttEncryptKey)) { +// topicName = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/OldON"; +// } else { +// topicName = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/NewON"; +// messageSend = Shared.Securitys.EncryptionService.AesEncryptPayload (message, mqttEncryptKey); +// } +// //base64鍔犲瘑 +// var m = new MqttApplicationMessage { Topic = topicName, Payload = messageSend, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; +// if (remoteIsConnected) { +// try { +// await RemoteMqttClient.PublishAsync (m); +// } catch (Exception e) { +// await DisConnectRemoteMqttClient (e.Message); +// await StartCloudMqtt (); +// if (remoteIsConnected) { +// await RemoteMqttClient.PublishAsync (m); +// } +// } +// } +// break; +// case 1: +// topicName = $"/BusGateWayToClient/{CurRemoteMACInfo.macMark}/Common/#"; +// if (remoteIsConnected) { +// try { +// await RemoteMqttClient.SubscribeAsync (topicName); +// } catch (Exception e) { +// await DisConnectRemoteMqttClient (e.Message); +// await StartCloudMqtt (); +// if (remoteIsConnected) { +// await RemoteMqttClient.SubscribeAsync (topicName); +// } +// } +// } +// break; +// case 2: +// var macStr = CurRemoteMACInfo.mac.ToUpper (); +// char [] cArrs = macStr.ToCharArray (); +// Array.Reverse (cArrs); +// var sss = string.Join (string.Empty, cArrs); - using (var provider = new MD5CryptoServiceProvider ()) { - byte [] buffer = provider.ComputeHash (Encoding.Default.GetBytes (sss)); - StringBuilder builder = new StringBuilder (); - for (int i = 0; i < buffer.Length; i++) { - builder.Append (buffer [i].ToString ("x2")); - } - CurRemoteMACInfo.md5_mac_string = builder.ToString ().ToUpper (); - } +// using (var provider = new MD5CryptoServiceProvider ()) { +// byte [] buffer = provider.ComputeHash (Encoding.Default.GetBytes (sss)); +// StringBuilder builder = new StringBuilder (); +// for (int i = 0; i < buffer.Length; i++) { +// builder.Append (buffer [i].ToString ("x2")); +// } +// CurRemoteMACInfo.md5_mac_string = builder.ToString ().ToUpper (); +// } - topicName = $"/NotifyBusGateWayInfoChagne/{CurRemoteMACInfo.md5_mac_string}"; - if (remoteIsConnected) { - try { - await RemoteMqttClient.SubscribeAsync (topicName); - } catch (Exception e) { - await DisConnectRemoteMqttClient (e.Message); - await StartCloudMqtt (); - if (remoteIsConnected) { - await RemoteMqttClient.SubscribeAsync (topicName); - } - } - } - break; +// topicName = $"/NotifyBusGateWayInfoChagne/{CurRemoteMACInfo.md5_mac_string}"; +// if (remoteIsConnected) { +// try { +// await RemoteMqttClient.SubscribeAsync (topicName); +// } catch (Exception e) { +// await DisConnectRemoteMqttClient (e.Message); +// await StartCloudMqtt (); +// if (remoteIsConnected) { +// await RemoteMqttClient.SubscribeAsync (topicName); +// } +// } +// } +// break; - case 3: - topicName = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/CheckGateway"; +// case 3: +// topicName = $"/ClientToBusGateWay/{CurRemoteMACInfo.macMark}/Common/CheckGateway"; - var m1 = new MqttApplicationMessage { Topic = topicName, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; +// var m1 = new MqttApplicationMessage { Topic = topicName, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; - try { - Console.WriteLine ("CheckGateway"); - await RemoteMqttClient.PublishAsync (m1); - } catch (Exception e) { - Console.WriteLine ($"CheckGateway Fail:{e.Message}"); - await DisConnectRemoteMqttClient (e.Message); - await StartCloudMqtt (); - } - break; - } - } catch (Exception e) { +// try { +// Console.WriteLine ("CheckGateway"); +// await RemoteMqttClient.PublishAsync (m1); +// } catch (Exception e) { +// Console.WriteLine ($"CheckGateway Fail:{e.Message}"); +// await DisConnectRemoteMqttClient (e.Message); +// await StartCloudMqtt (); +// } +// break; +// } +// } catch (Exception e) { - } - } - } -} +// } +// } +// } +//} -public class RemoteRequestParameters -{ - public string RequestVersion; - public int RequestSource; - public string LoginAccessToken; - public int RequestProtocolType; +//public class RemoteRequestParameters +//{ +// public string RequestVersion; +// public int RequestSource; +// public string LoginAccessToken; +// public int RequestProtocolType; - public string Mac = ""; - public string GroupName = ""; -} +// public string Mac = ""; +// public string GroupName = ""; +//} -public class MqttRemoteInfo -{ - public List<RemoteMACInfo> pageData; +//public class MqttRemoteInfo +//{ +// public List<RemoteMACInfo> pageData; - public int pageIndex = 0; - public int pageSize = 10; - public int totalCount = 3; - public int totalPages = 1; - public bool hasPreviousPage = false; - public bool hasNextPage = false; -} +// public int pageIndex = 0; +// public int pageSize = 10; +// public int totalCount = 3; +// public int totalPages = 1; +// public bool hasPreviousPage = false; +// public bool hasNextPage = false; +//} -public class MqttInfo -{ - public string connEmqDomainPort; - public string connEmqClientId; - public string connEmqUserName; - public string connEmqPwd; -} +//public class MqttInfo +//{ +// public string connEmqDomainPort; +// public string connEmqClientId; +// public string connEmqUserName; +// public string connEmqPwd; +//} -public class RemoteMACInfo -{ - public string mac; - public string macMark; - public string isValid; - public string aesKey; - public bool isNewBusproGateway; - public string groupName; - public string projectName; - public string userName; +//public class RemoteMACInfo +//{ +// public string mac; +// public string macMark; +// public string isValid; +// public string aesKey; +// public bool isNewBusproGateway; +// public string groupName; +// public string projectName; +// public string userName; - //app鑷畾涔夋暟鎹� - public string md5_mac_string; - public string LoginAccessToken; -} +// //app鑷畾涔夋暟鎹� +// public string md5_mac_string; +// public string LoginAccessToken; +//} -namespace Shared.Securitys -{ - public partial class EncryptionService - { +//namespace Shared.Securitys +//{ +// public partial class EncryptionService +// { - #region 鍔犲瘑 - /// <summary> - /// 鍔犲瘑涓婚涓築ase64 - /// </summary> - /// <param name="pToEncrypt"></param> - /// <param name="key"></param> - /// <returns></returns> - public static string AesEncryptTopic (string pToEncrypt, string key) - { - if (string.IsNullOrEmpty (pToEncrypt)) return null; - if (string.IsNullOrEmpty (key)) return pToEncrypt; - //闇�瑕佸姞瀵嗗唴瀹圭殑鏄庢枃娴� - Byte [] toEncryptArray = Encoding.UTF8.GetBytes (pToEncrypt); +// #region 鍔犲瘑 +// /// <summary> +// /// 鍔犲瘑涓婚涓築ase64 +// /// </summary> +// /// <param name="pToEncrypt"></param> +// /// <param name="key"></param> +// /// <returns></returns> +// public static string AesEncryptTopic (string pToEncrypt, string key) +// { +// if (string.IsNullOrEmpty (pToEncrypt)) return null; +// if (string.IsNullOrEmpty (key)) return pToEncrypt; +// //闇�瑕佸姞瀵嗗唴瀹圭殑鏄庢枃娴� +// Byte [] toEncryptArray = Encoding.UTF8.GetBytes (pToEncrypt); - //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) - RijndaelManaged rm = new RijndaelManaged { - Key = Encoding.UTF8.GetBytes (key), - IV = Encoding.UTF8.GetBytes (key), - Mode = CipherMode.CBC, - Padding = PaddingMode.PKCS7 - }; +// //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) +// RijndaelManaged rm = new RijndaelManaged { +// Key = Encoding.UTF8.GetBytes (key), +// IV = Encoding.UTF8.GetBytes (key), +// Mode = CipherMode.CBC, +// Padding = PaddingMode.PKCS7 +// }; - //鍒涘缓AES鍔犲瘑鍣ㄥ璞� - ICryptoTransform cTransform = rm.CreateEncryptor (); +// //鍒涘缓AES鍔犲瘑鍣ㄥ璞� +// ICryptoTransform cTransform = rm.CreateEncryptor (); - //浣跨敤AES灏嗘槑鏂囨祦杞垚瀵嗘枃瀛楄妭鏁扮粍 - Byte [] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); +// //浣跨敤AES灏嗘槑鏂囨祦杞垚瀵嗘枃瀛楄妭鏁扮粍 +// Byte [] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); - //灏咥ES鐢熸垚鐨勫瘑鏂囧瓧鑺傛暟缁勮浆鎴怋ase64瀛楃涓� - return Convert.ToBase64String (resultArray, 0, resultArray.Length); - } +// //灏咥ES鐢熸垚鐨勫瘑鏂囧瓧鑺傛暟缁勮浆鎴怋ase64瀛楃涓� +// return Convert.ToBase64String (resultArray, 0, resultArray.Length); +// } - /// <summary> - /// 鍔犲瘑璐熻浇涓轰簩杩涘埗娴� - /// </summary> - /// <param name="toEncryptArray"></param> - /// <param name="key"></param> - /// <returns></returns> - public static byte [] AesEncryptPayload (byte [] toEncryptArray, string key) - { - if (string.IsNullOrEmpty (key)) return toEncryptArray; - //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) - var rm = new RijndaelManaged { - Key = Encoding.UTF8.GetBytes (key), - IV = Encoding.UTF8.GetBytes (key), - Mode = CipherMode.CBC, - Padding = PaddingMode.PKCS7 - }; +// /// <summary> +// /// 鍔犲瘑璐熻浇涓轰簩杩涘埗娴� +// /// </summary> +// /// <param name="toEncryptArray"></param> +// /// <param name="key"></param> +// /// <returns></returns> +// public static byte [] AesEncryptPayload (byte [] toEncryptArray, string key) +// { +// if (string.IsNullOrEmpty (key)) return toEncryptArray; +// //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) +// var rm = new RijndaelManaged { +// Key = Encoding.UTF8.GetBytes (key), +// IV = Encoding.UTF8.GetBytes (key), +// Mode = CipherMode.CBC, +// Padding = PaddingMode.PKCS7 +// }; - //鍒涘缓AES鍔犲瘑鍣ㄥ璞� - var cTransform = rm.CreateEncryptor (); - //浣跨敤AES灏嗘槑鏂囨祦杞垚瀵嗘枃瀛楄妭鏁扮粍 - return cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); - } - #endregion +// //鍒涘缓AES鍔犲瘑鍣ㄥ璞� +// var cTransform = rm.CreateEncryptor (); +// //浣跨敤AES灏嗘槑鏂囨祦杞垚瀵嗘枃瀛楄妭鏁扮粍 +// return cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); +// } +// #endregion - #region 瑙e瘑 - /// <summary> - /// 瑙e瘑涓婚鏁版嵁 - /// </summary> - /// <param name="pToDecrypt"></param> - /// <param name="key"></param> - /// <returns></returns> - public static string AesDecryptTopic (string pToDecrypt, string key) - { - //AES瀵嗘枃Base64杞垚瀛楃涓� - Byte [] toEncryptArray = Convert.FromBase64String (pToDecrypt); +// #region 瑙e瘑 +// /// <summary> +// /// 瑙e瘑涓婚鏁版嵁 +// /// </summary> +// /// <param name="pToDecrypt"></param> +// /// <param name="key"></param> +// /// <returns></returns> +// public static string AesDecryptTopic (string pToDecrypt, string key) +// { +// //AES瀵嗘枃Base64杞垚瀛楃涓� +// Byte [] toEncryptArray = Convert.FromBase64String (pToDecrypt); - //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) - RijndaelManaged rm = new RijndaelManaged { - Key = Encoding.UTF8.GetBytes (key), - IV = Encoding.UTF8.GetBytes (key), - Mode = CipherMode.CBC, - Padding = PaddingMode.PKCS7 - }; +// //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) +// RijndaelManaged rm = new RijndaelManaged { +// Key = Encoding.UTF8.GetBytes (key), +// IV = Encoding.UTF8.GetBytes (key), +// Mode = CipherMode.CBC, +// Padding = PaddingMode.PKCS7 +// }; - //鍒涘缓AES瑙e瘑鍣ㄥ璞� - ICryptoTransform cTransform = rm.CreateDecryptor (); +// //鍒涘缓AES瑙e瘑鍣ㄥ璞� +// ICryptoTransform cTransform = rm.CreateDecryptor (); - //浣跨敤AES灏嗗瘑鏂囨祦杞垚鏄庢枃鐨勫瓧鑺傛暟缁� - Byte [] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); +// //浣跨敤AES灏嗗瘑鏂囨祦杞垚鏄庢枃鐨勫瓧鑺傛暟缁� +// Byte [] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); - //杞垚瀛楃涓� - return Encoding.UTF8.GetString (resultArray); - } +// //杞垚瀛楃涓� +// return Encoding.UTF8.GetString (resultArray); +// } - /// <summary> - /// 閲囩敤Aes瑙e瘑璐熻浇鏁版嵁 - /// </summary> - /// <param name="toEncryptArray"></param> - /// <param name="key"></param> - /// <returns></returns> - public static byte [] AesDecryptPayload (byte [] toEncryptArray, string key) - { - //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) - var rm = new RijndaelManaged { - Key = Encoding.UTF8.GetBytes (key), - IV = Encoding.UTF8.GetBytes (key), - Mode = CipherMode.CBC, - Padding = PaddingMode.PKCS7 - }; +// /// <summary> +// /// 閲囩敤Aes瑙e瘑璐熻浇鏁版嵁 +// /// </summary> +// /// <param name="toEncryptArray"></param> +// /// <param name="key"></param> +// /// <returns></returns> +// public static byte [] AesDecryptPayload (byte [] toEncryptArray, string key) +// { +// //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) +// var rm = new RijndaelManaged { +// Key = Encoding.UTF8.GetBytes (key), +// IV = Encoding.UTF8.GetBytes (key), +// Mode = CipherMode.CBC, +// Padding = PaddingMode.PKCS7 +// }; - //鍒涘缓AES瑙e瘑鍣ㄥ璞� - var cTransform = rm.CreateDecryptor (); +// //鍒涘缓AES瑙e瘑鍣ㄥ璞� +// var cTransform = rm.CreateDecryptor (); - //浣跨敤AES灏嗗瘑鏂囨祦杞垚鏄庢枃鐨勫瓧鑺傛暟缁� - return cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); - } - #endregion +// //浣跨敤AES灏嗗瘑鏂囨祦杞垚鏄庢枃鐨勫瓧鑺傛暟缁� +// return cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); +// } +// #endregion - } -} +// } +//} -/* -using System.Collections.Generic; -using System; -using MQTTnet.Client; -using System.Threading.Tasks; -using Shared; -using Shared.SimpleControl; -using MQTTnet; -using System.Text; -using System.Security.Cryptography; +///* +//using System.Collections.Generic; +//using System; +//using MQTTnet.Client; +//using System.Threading.Tasks; +//using Shared; +//using Shared.SimpleControl; +//using MQTTnet; +//using System.Text; +//using System.Security.Cryptography; -namespace SmartHome -{ - public static class MqttCommon - { - static string mqttEncryptKey = ""; - static string checkGatewayTopicBase64 = ""; +//namespace SmartHome +//{ +// public static class MqttCommon +// { +// static string mqttEncryptKey = ""; +// static string checkGatewayTopicBase64 = ""; - /// <summary> - /// 鎵嬫満鏍囪瘑 - /// </summary> - static Guid currentGuid = Guid.NewGuid (); +// /// <summary> +// /// 鎵嬫満鏍囪瘑 +// /// </summary> +// static Guid currentGuid = Guid.NewGuid (); - /// <summary> - /// 澶栫綉鐨凪QTT鏄惁姝e湪杩炴帴 - /// </summary> - static object isConnecting = false.ToString (); - /// <summary> - /// 杩滅▼MqttClient - /// </summary> - public static IMqttClient RemoteMqttClient; +// /// <summary> +// /// 澶栫綉鐨凪QTT鏄惁姝e湪杩炴帴 +// /// </summary> +// static object isConnecting = false.ToString (); +// /// <summary> +// /// 杩滅▼MqttClient +// /// </summary> +// public static IMqttClient RemoteMqttClient; - static bool thisShowTip = true; +// static bool thisShowTip = true; - public static async Task Close (bool RemoveRemoteMqttClient = false) - { - try { - if (RemoteMqttClient != null) { - //thisShowTip = true; - await RemoteMqttClient.DisconnectAsync (); - } - if (RemoveRemoteMqttClient) { - RemoteMqttClient = null; - } - CommonPage.IsRemote = false; - Console.WriteLine ("Close Mqtt!!!"); - } catch { } - } +// public static async Task Close (bool RemoveRemoteMqttClient = false) +// { +// try { +// if (RemoteMqttClient != null) { +// //thisShowTip = true; +// await RemoteMqttClient.DisconnectAsync (); +// } +// if (RemoveRemoteMqttClient) { +// RemoteMqttClient = null; +// } +// CommonPage.IsRemote = false; +// Console.WriteLine ("Close Mqtt!!!"); +// } catch { } +// } - static DateTime dateTime = DateTime.MinValue; - static int startCount = 0; +// static DateTime dateTime = DateTime.MinValue; +// static int startCount = 0; - //public static async Task ReSatart () - //{ - // await Close (); - // await RemoteMqttClient.ConnectAsync (options); - //} +// //public static async Task ReSatart () +// //{ +// // await Close (); +// // await RemoteMqttClient.ConnectAsync (options); +// //} - /// <summary> - /// 鍚姩杩滅▼Mqtt - /// </summary> - public static async System.Threading.Tasks.Task StartCloudMqtt () - { +// /// <summary> +// /// 鍚姩杩滅▼Mqtt +// /// </summary> +// public static async System.Threading.Tasks.Task StartCloudMqtt () +// { - Application.RunOnMainThread (() => { - if (5 < (DateTime.Now - dateTime).TotalSeconds) { - return; - } - dateTime = DateTime.Now; - }); - if (!MainPage.LoginUser.IsLogin) { - isConnecting = false.ToString (); - return; - } - while (isConnecting.ToString () == true.ToString ()) { - if (5 < (DateTime.Now - dateTime).TotalSeconds) { - break; - } - await System.Threading.Tasks.Task.Delay (500); - } - lock (isConnecting) { - if (isConnecting.ToString () == true.ToString ()) { - return; - } - isConnecting = true.ToString (); - if (RemoteMqttClient != null && RemoteMqttClient.IsConnected) { - MqttCheckGateway (); - return; - } - } - new System.Threading.Thread (async () => { - try { - if (RemoteMqttClient == null) { - var requestObj3 = new GatewayByRegionListObj () { RegionID = UserConfig.Instance.CurrentRegion.RegionID }; - var requestJson3 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj3); - var revertObj3 = MainPage.RequestHttps ("GatewayByRegionList", requestJson3, true, false); - if (revertObj3.StateCode == "SUCCESS") { - var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GatewayRes>> (revertObj3.ResponseData.ToString ()); - var gatewayList = responseDataObj; - if (gatewayList != null && gatewayList.Count > 0) { - UserConfig.Instance.CurrentRegion.MAC = gatewayList [0].MAC; - UserConfig.Instance.SaveUserConfig (); - } - } else { - } +// Application.RunOnMainThread (() => { +// if (5 < (DateTime.Now - dateTime).TotalSeconds) { +// return; +// } +// dateTime = DateTime.Now; +// }); +// if (!MainPage.LoginUser.IsLogin) { +// isConnecting = false.ToString (); +// return; +// } +// while (isConnecting.ToString () == true.ToString ()) { +// if (5 < (DateTime.Now - dateTime).TotalSeconds) { +// break; +// } +// await System.Threading.Tasks.Task.Delay (500); +// } +// lock (isConnecting) { +// if (isConnecting.ToString () == true.ToString ()) { +// return; +// } +// isConnecting = true.ToString (); +// if (RemoteMqttClient != null && RemoteMqttClient.IsConnected) { +// MqttCheckGateway (); +// return; +// } +// } +// new System.Threading.Thread (async () => { +// try { +// if (RemoteMqttClient == null) { +// var requestObj3 = new GatewayByRegionListObj () { RegionID = UserConfig.Instance.CurrentRegion.RegionID }; +// var requestJson3 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj3); +// var revertObj3 = MainPage.RequestHttps ("GatewayByRegionList", requestJson3, true, false); +// if (revertObj3.StateCode == "SUCCESS") { +// var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GatewayRes>> (revertObj3.ResponseData.ToString ()); +// var gatewayList = responseDataObj; +// if (gatewayList != null && gatewayList.Count > 0) { +// UserConfig.Instance.CurrentRegion.MAC = gatewayList [0].MAC; +// UserConfig.Instance.SaveUserConfig (); +// } +// } else { +// } - //(2)鍒涘缓Mqtt瀹㈡埛绔� - RemoteMqttClient = new MqttFactory ().CreateMqttClient (); - //(3)褰揫杩炴帴浜戠鐨凪qtt鎴愬姛鍚嶿鎴栬�匸浠ュ強鍚庨潰App閫氳繃浜戠Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒颁簯绔暟鎹寘鍝嶅簲鏃跺湪mqttServerClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊 - RemoteMqttClient.UseApplicationMessageReceivedHandler (async e => { - if (isConnecting.ToString () == true.ToString ()) - isConnecting = false.ToString (); - var aesDecryptTopic = e.ApplicationMessage.Topic; - var aesDecryptPayload = e.ApplicationMessage.Payload; - if (aesDecryptTopic == "YouIpAndPortNoRecord" || aesDecryptTopic == "DecryptFail") {// --> 浣犲綋鍓嶇殑IP鍙婄鍙e湪浜戠涓嶅瓨鍦�,璇烽噸鏂扮櫥褰曡繛鎺ヤ笅! - await Close (true); - await MqttCheckGateway (); - } else if (aesDecryptTopic == @"/BeingSqueezedOffline") { - try { - Application.RunOnMainThread (() => { - MainPage.Loading.Start (""); - MainPage.LoginUser.LastTime = DateTime.MinValue; - MainPage.LoginUser.SaveUserInfo (); - Room.Lists.Clear (); - new Shared.SimpleControl.Phone.AccountLogin (MainPage.LoginUser.AccountString.ToLower (), "").Show (); - MainPage.LoginUser.LastTime = System.DateTime.MinValue; - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor; - if (CommonPage.IsRemote) { - SmartHome.MqttCommon.Close (true); - } - var webPush = new service.hdlcontrol.com_push.WebServicePush (); - webPush.DeleteToken_Push (UserConfig.Instance.tokenID); - }); - } catch (Exception ex) { - Console.WriteLine (ex.Message); - } finally { - Application.RunOnMainThread (() => { - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor; - MainPage.Loading.Hide (); - new Alert (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.Tip), Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LoggedOnOtherDevices), - Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.Close)).Show (); - }); - } -#if HDL - if (!String.IsNullOrEmpty (MainPage.LoginUser.AllVisionRegisterDevUserNameGuid)) { - com.freeview.global.Video.Logout (); - } -#endif - } else { - aesDecryptTopic = Shared.Securitys.EncryptionService.AesDecryptTopic (e.ApplicationMessage.Topic, mqttEncryptKey); - aesDecryptPayload = Shared.Securitys.EncryptionService.AesDecryptPayload (e.ApplicationMessage.Payload, mqttEncryptKey); - } - if (aesDecryptTopic == @"/" + MainPage.LoginUser.AccountString.ToLower () + @"/CheckGateway/" + UserConfig.Instance.GatewayMAC.Replace (".", "")) { - var ss = CommonPage.MyEncodingUTF8.GetString (aesDecryptPayload); - var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (ss); - if (obj == null) { - return; - } - switch (obj.StateCode) { - case "HDLUdpDataForwardServerMqttClientNoOnLine": - case "NoOnline": - case "NetworkAnomaly"://涓嶅湪绾� - MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.RemoteFailedGatewayOffline)); - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - break; - case "NoRecord"://MAC涓嶆纭� - MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.MACError)); - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - break; - case "Success": - CommonPage.IsRemote = true; - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = 0xAA69E64A; - Shared.SimpleControl.Phone.UserMiddle.ReadAllDeviceStatus (); - }); - MainPage.AddTip (UserConfig.Instance.CurrentRegion.RegionName + ":" + Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkSuccess)); - break; - default: - MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkLoser)); - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - break; - } - } else { - var packet = new Packet (); - packet.Bytes = aesDecryptPayload; - packet.Manager (); - } - }); +// //(2)鍒涘缓Mqtt瀹㈡埛绔� +// RemoteMqttClient = new MqttFactory ().CreateMqttClient (); +// //(3)褰揫杩炴帴浜戠鐨凪qtt鎴愬姛鍚嶿鎴栬�匸浠ュ強鍚庨潰App閫氳繃浜戠Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒颁簯绔暟鎹寘鍝嶅簲鏃跺湪mqttServerClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊 +// RemoteMqttClient.UseApplicationMessageReceivedHandler (async e => { +// if (isConnecting.ToString () == true.ToString ()) +// isConnecting = false.ToString (); +// var aesDecryptTopic = e.ApplicationMessage.Topic; +// var aesDecryptPayload = e.ApplicationMessage.Payload; +// if (aesDecryptTopic == "YouIpAndPortNoRecord" || aesDecryptTopic == "DecryptFail") {// --> 浣犲綋鍓嶇殑IP鍙婄鍙e湪浜戠涓嶅瓨鍦�,璇烽噸鏂扮櫥褰曡繛鎺ヤ笅! +// await Close (true); +// await MqttCheckGateway (); +// } else if (aesDecryptTopic == @"/BeingSqueezedOffline") { +// try { +// Application.RunOnMainThread (() => { +// MainPage.Loading.Start (""); +// MainPage.LoginUser.LastTime = DateTime.MinValue; +// MainPage.LoginUser.SaveUserInfo (); +// Room.Lists.Clear (); +// new Shared.SimpleControl.Phone.AccountLogin (MainPage.LoginUser.AccountString.ToLower (), "").Show (); +// MainPage.LoginUser.LastTime = System.DateTime.MinValue; +// Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor; +// if (CommonPage.IsRemote) { +// SmartHome.MqttCommon.Close (true); +// } +// var webPush = new service.hdlcontrol.com_push.WebServicePush (); +// webPush.DeleteToken_Push (UserConfig.Instance.tokenID); +// }); +// } catch (Exception ex) { +// Console.WriteLine (ex.Message); +// } finally { +// Application.RunOnMainThread (() => { +// Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor; +// MainPage.Loading.Hide (); +// new Alert (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.Tip), Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LoggedOnOtherDevices), +// Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.Close)).Show (); +// }); +// } +//#if HDL +// if (!String.IsNullOrEmpty (MainPage.LoginUser.AllVisionRegisterDevUserNameGuid)) { +// com.freeview.global.Video.Logout (); +// } +//#endif +// } else { +// aesDecryptTopic = Shared.Securitys.EncryptionService.AesDecryptTopic (e.ApplicationMessage.Topic, mqttEncryptKey); +// aesDecryptPayload = Shared.Securitys.EncryptionService.AesDecryptPayload (e.ApplicationMessage.Payload, mqttEncryptKey); +// } +// if (aesDecryptTopic == @"/" + MainPage.LoginUser.AccountString.ToLower () + @"/CheckGateway/" + UserConfig.Instance.GatewayMAC.Replace (".", "")) { +// var ss = CommonPage.MyEncodingUTF8.GetString (aesDecryptPayload); +// var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (ss); +// if (obj == null) { +// return; +// } +// switch (obj.StateCode) { +// case "HDLUdpDataForwardServerMqttClientNoOnLine": +// case "NoOnline": +// case "NetworkAnomaly"://涓嶅湪绾� +// MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.RemoteFailedGatewayOffline)); +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// }); +// break; +// case "NoRecord"://MAC涓嶆纭� +// MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.MACError)); +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// }); +// break; +// case "Success": +// CommonPage.IsRemote = true; +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = 0xAA69E64A; +// Shared.SimpleControl.Phone.UserMiddle.ReadAllDeviceStatus (); +// }); +// MainPage.AddTip (UserConfig.Instance.CurrentRegion.RegionName + ":" + Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkSuccess)); +// break; +// default: +// MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.LinkLoser)); +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// }); +// break; +// } +// } else { +// var packet = new Packet (); +// packet.Bytes = aesDecryptPayload; +// packet.Manager (); +// } +// }); - RemoteMqttClient.UseDisconnectedHandler (e => { - //Console.WriteLine ("RemoteMqttClient UseDisconnectedHandler"); - if (thisShowTip) { - if (CommonPage.IsRemote) { - //MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.RemoteConnectionDisconnected)); - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - } - } else { - thisShowTip = true; - } - }); - RemoteMqttClient.UseConnectedHandler (async e => { - //Console.WriteLine ("RemoteMqttClient IsRemote"); - await MqttCheckGateway (); - }); - } +// RemoteMqttClient.UseDisconnectedHandler (e => { +// //Console.WriteLine ("RemoteMqttClient UseDisconnectedHandler"); +// if (thisShowTip) { +// if (CommonPage.IsRemote) { +// //MainPage.AddTip (Language.StringByID (Shared.SimpleControl.R.MyInternationalizationString.RemoteConnectionDisconnected)); +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// }); +// } +// } else { +// thisShowTip = true; +// } +// }); +// RemoteMqttClient.UseConnectedHandler (async e => { +// //Console.WriteLine ("RemoteMqttClient IsRemote"); +// await MqttCheckGateway (); +// }); +// } - var requestObj = new LoginObj () { Account = MainPage.LoginUser.AccountString.ToLower (), Password = MainPage.LoginUser.Password, Company = MainPage.SoftSmsType }; - var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); - var tempResult = MainPage.RequestHttps ("Login", requestJson, false); - if (tempResult == null) { - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; - }); - System.Console.WriteLine ($"閲嶆柊杩炴帴杩滅▼閫氳澶辫触锛屽洜涓鸿幏鍙栨柊鐨凨EY澶辫触"); - return; - } - //var messgae = System.Text.Encoding.UTF8.GetString (tempResult); +// var requestObj = new LoginObj () { Account = MainPage.LoginUser.AccountString.ToLower (), Password = MainPage.LoginUser.Password, Company = MainPage.SoftSmsType }; +// var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); +// var tempResult = MainPage.RequestHttps ("Login", requestJson, false); +// if (tempResult == null) { +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +// }); +// System.Console.WriteLine ($"閲嶆柊杩炴帴杩滅▼閫氳澶辫触锛屽洜涓鸿幏鍙栨柊鐨凨EY澶辫触"); +// return; +// } +// //var messgae = System.Text.Encoding.UTF8.GetString (tempResult); - var responsePack = tempResult.ResponseData;// Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (messgae); - //if (responsePack == null || responsePack ["ResponseData"] == null) { - // Console.WriteLine ("鏂紑鍚庨噸鏂伴摼鎺ラ渶瑕侀噸鏂扮櫥褰曡幏鍙栬繛鎺ョ殑瀵嗙爜澶辫触"); - // return; - //} - var dictrionaryResult = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (tempResult.ResponseData.ToString ()); - //var dictrionaryResult = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (responsePack ["ResponseData"].ToString ()); - //////杩樻湁绉嶆儏鍐垫槸鍚屼竴涓狪D 鏈夊涓澶囩敤杩欎釜id杩炴帴锛堜細瀵艰嚧涓柇锛� - mqttEncryptKey = dictrionaryResult ["HdlOnMqttKey"]?.ToString (); - var url = dictrionaryResult ["ConnectMqttBrokerLoadSubDomain"]?.ToString (); - var clientId = dictrionaryResult ["ConnectMqttClientId"]?.ToString (); - var username = dictrionaryResult ["ConnectMqttBrokerUserName"]?.ToString (); - var passwordRemote = dictrionaryResult ["ConnectMqttBrokerPwd"]?.ToString (); +// var responsePack = tempResult.ResponseData;// Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (messgae); +// //if (responsePack == null || responsePack ["ResponseData"] == null) { +// // Console.WriteLine ("鏂紑鍚庨噸鏂伴摼鎺ラ渶瑕侀噸鏂扮櫥褰曡幏鍙栬繛鎺ョ殑瀵嗙爜澶辫触"); +// // return; +// //} +// var dictrionaryResult = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (tempResult.ResponseData.ToString ()); +// //var dictrionaryResult = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (responsePack ["ResponseData"].ToString ()); +// //////杩樻湁绉嶆儏鍐垫槸鍚屼竴涓狪D 鏈夊涓澶囩敤杩欎釜id杩炴帴锛堜細瀵艰嚧涓柇锛� +// mqttEncryptKey = dictrionaryResult ["HdlOnMqttKey"]?.ToString (); +// var url = dictrionaryResult ["ConnectMqttBrokerLoadSubDomain"]?.ToString (); +// var clientId = dictrionaryResult ["ConnectMqttClientId"]?.ToString (); +// var username = dictrionaryResult ["ConnectMqttBrokerUserName"]?.ToString (); +// var passwordRemote = dictrionaryResult ["ConnectMqttBrokerPwd"]?.ToString (); - if (clientId == null || username == null || passwordRemote == null) { - return; - } +// if (clientId == null || username == null || passwordRemote == null) { +// return; +// } - ////(1)杩炴帴鍒颁簯绔殑Mqtt瀹㈡埛绔繛鎺ュ弬鏁� - var options = new MQTTnet.Client.Options.MqttClientOptionsBuilder () - .WithClientId (clientId) - .WithTcpServer (url.Split (':') [1].Substring ("//".Length), int.Parse (url.Split (':') [2]))// - .WithCredentials (username, passwordRemote) - .WithCleanSession () - .WithCommunicationTimeout (new TimeSpan (0, 0, 10)) - .Build (); +// ////(1)杩炴帴鍒颁簯绔殑Mqtt瀹㈡埛绔繛鎺ュ弬鏁� +// var options = new MQTTnet.Client.Options.MqttClientOptionsBuilder () +// .WithClientId (clientId) +// .WithTcpServer (url.Split (':') [1].Substring ("//".Length), int.Parse (url.Split (':') [2]))// +// .WithCredentials (username, passwordRemote) +// .WithCleanSession () +// .WithCommunicationTimeout (new TimeSpan (0, 0, 10)) +// .Build (); - await Close (); - await RemoteMqttClient.ConnectAsync (options); - } catch (Exception ex) { - System.Console.WriteLine ("============>" + ex.Message); - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - isConnecting = false.ToString (); +// await Close (); +// await RemoteMqttClient.ConnectAsync (options); +// } catch (Exception ex) { +// System.Console.WriteLine ("============>" + ex.Message); +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// isConnecting = false.ToString (); - Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; -#if DEBUG - Alert a = new Alert (isConnecting.ToString (), ex.Message, "Close"); - a.Show (); -#endif - if (MqttCommon.RemoteMqttClient != null) { - MqttCommon.RemoteMqttClient.Dispose (); - } - if (MqttCommon.RemoteMqttClient != null) { - MqttCommon.RemoteMqttClient = null; - } - }); - } finally { - isConnecting = false.ToString (); - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - }); - } - }) { IsBackground = true }.Start (); - } +// Shared.SimpleControl.Phone.UserMiddle.LinkStatusTip.BackgroundColor = SkinStyle.Current.DelColor; +//#if DEBUG +// Alert a = new Alert (isConnecting.ToString (), ex.Message, "Close"); +// a.Show (); +//#endif +// if (MqttCommon.RemoteMqttClient != null) { +// MqttCommon.RemoteMqttClient.Dispose (); +// } +// if (MqttCommon.RemoteMqttClient != null) { +// MqttCommon.RemoteMqttClient = null; +// } +// }); +// } finally { +// isConnecting = false.ToString (); +// Application.RunOnMainThread (() => { +// MainPage.Loading.Hide (); +// }); +// } +// }) { IsBackground = true }.Start (); +// } - /// <summary> - /// Logins the by PWDA sync. - /// </summary> - public static async System.Threading.Tasks.Task<byte []> LoginByPWDAsync (string account, string password, string source = "", int company = 0) - { - try { - var result = await MainPage.RequestHttpsResultAsync ("Login", - System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new Dictionary<string, object> { - ["Account"] = account, - ["Password"] = password, - ["Source"] = source, - ["Company"] = company - }))); - return result; - } catch { - return null; - } - } +// /// <summary> +// /// Logins the by PWDA sync. +// /// </summary> +// public static async System.Threading.Tasks.Task<byte []> LoginByPWDAsync (string account, string password, string source = "", int company = 0) +// { +// try { +// var result = await MainPage.RequestHttpsResultAsync ("Login", +// System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new Dictionary<string, object> { +// ["Account"] = account, +// ["Password"] = password, +// ["Source"] = source, +// ["Company"] = company +// }))); +// return result; +// } catch { +// return null; +// } +// } - /// <summary> - /// 灏咮ase64瀛楃涓诧紝杞崲鎴愬悎娉曠殑Mqtt涓婚 - /// </summary> - /// <param name="baseSexFourEncStr"></param> - /// <returns></returns> - public static string BaseSexFourStrToMqttTopic (string baseSexFourEncStr) - { - baseSexFourEncStr = baseSexFourEncStr.Replace ("+", "[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]"); - baseSexFourEncStr = baseSexFourEncStr.Replace ("/", "[[$-MQTT_TILT_SYMBOL_REPLACE-$]]"); - return baseSexFourEncStr; - } +// /// <summary> +// /// 灏咮ase64瀛楃涓诧紝杞崲鎴愬悎娉曠殑Mqtt涓婚 +// /// </summary> +// /// <param name="baseSexFourEncStr"></param> +// /// <returns></returns> +// public static string BaseSexFourStrToMqttTopic (string baseSexFourEncStr) +// { +// baseSexFourEncStr = baseSexFourEncStr.Replace ("+", "[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]"); +// baseSexFourEncStr = baseSexFourEncStr.Replace ("/", "[[$-MQTT_TILT_SYMBOL_REPLACE-$]]"); +// return baseSexFourEncStr; +// } - public static async System.Threading.Tasks.Task MqttRemoteSend (byte [] message) - { - try { - if (RemoteMqttClient == null || !RemoteMqttClient.IsConnected) { - await StartCloudMqtt (); - } - if (!RemoteMqttClient.IsConnected) { - return; - } - var topicName = @"/" + MainPage.LoginUser.AccountString.ToLower () + @"/" + UserConfig.Instance.GatewayMAC.Replace (".", "") + @"/" + currentGuid; +// public static async System.Threading.Tasks.Task MqttRemoteSend (byte [] message) +// { +// try { +// if (RemoteMqttClient == null || !RemoteMqttClient.IsConnected) { +// await StartCloudMqtt (); +// } +// if (!RemoteMqttClient.IsConnected) { +// return; +// } +// var topicName = @"/" + MainPage.LoginUser.AccountString.ToLower () + @"/" + UserConfig.Instance.GatewayMAC.Replace (".", "") + @"/" + currentGuid; - //base64鍔犲瘑涓婚 - checkGatewayTopicBase64 = Shared.Securitys.EncryptionService.AesEncryptTopic (topicName, mqttEncryptKey); +// //base64鍔犲瘑涓婚 +// checkGatewayTopicBase64 = Shared.Securitys.EncryptionService.AesEncryptTopic (topicName, mqttEncryptKey); - //BaseSexFourStrToMqttTopic - var topicNameSend = BaseSexFourStrToMqttTopic (checkGatewayTopicBase64); +// //BaseSexFourStrToMqttTopic +// var topicNameSend = BaseSexFourStrToMqttTopic (checkGatewayTopicBase64); - //base64鍔犲瘑涓讳綋 - var messageSend = Shared.Securitys.EncryptionService.AesEncryptPayload (message, mqttEncryptKey); +// //base64鍔犲瘑涓讳綋 +// var messageSend = Shared.Securitys.EncryptionService.AesEncryptPayload (message, mqttEncryptKey); - var m = new MqttApplicationMessage { Topic = topicNameSend, Payload = messageSend, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; - await RemoteMqttClient?.PublishAsync (m); - } catch (Exception e) { - isConnecting = false.ToString (); - } - } +// var m = new MqttApplicationMessage { Topic = topicNameSend, Payload = messageSend, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; +// await RemoteMqttClient?.PublishAsync (m); +// } catch (Exception e) { +// isConnecting = false.ToString (); +// } +// } - public static async Task MqttCheckGateway () - { - try { - if (RemoteMqttClient == null || !RemoteMqttClient.IsConnected) { - await StartCloudMqtt (); - } - if (!RemoteMqttClient.IsConnected) { - return; - } - var topicName = @"/" + MainPage.LoginUser.AccountString.ToLower () + @"/CheckGateway/" + UserConfig.Instance.GatewayMAC.Replace (".", ""); - Console.WriteLine ("MqttCheckGateway : " + topicName); - //base64鍔犲瘑涓婚 - var topicNameBase64 = Shared.Securitys.EncryptionService.AesEncryptTopic (topicName, mqttEncryptKey); +// public static async Task MqttCheckGateway () +// { +// try { +// if (RemoteMqttClient == null || !RemoteMqttClient.IsConnected) { +// await StartCloudMqtt (); +// } +// if (!RemoteMqttClient.IsConnected) { +// return; +// } +// var topicName = @"/" + MainPage.LoginUser.AccountString.ToLower () + @"/CheckGateway/" + UserConfig.Instance.GatewayMAC.Replace (".", ""); +// Console.WriteLine ("MqttCheckGateway : " + topicName); +// //base64鍔犲瘑涓婚 +// var topicNameBase64 = Shared.Securitys.EncryptionService.AesEncryptTopic (topicName, mqttEncryptKey); - //BaseSexFourStrToMqttTopic - var topicNameSend = BaseSexFourStrToMqttTopic (topicNameBase64); +// //BaseSexFourStrToMqttTopic +// var topicNameSend = BaseSexFourStrToMqttTopic (topicNameBase64); - //base64鍔犲瘑涓婚 - var messageSend = Shared.Securitys.EncryptionService.AesEncryptPayload (new byte [] { 2, 1 }, mqttEncryptKey); +// //base64鍔犲瘑涓婚 +// var messageSend = Shared.Securitys.EncryptionService.AesEncryptPayload (new byte [] { 2, 1 }, mqttEncryptKey); - var m = new MqttApplicationMessage { Topic = topicNameSend, Payload = messageSend, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; - await RemoteMqttClient?.PublishAsync (m); - } catch (Exception e) { - isConnecting = false.ToString (); - } - } - } -} +// var m = new MqttApplicationMessage { Topic = topicNameSend, Payload = messageSend, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce }; +// await RemoteMqttClient?.PublishAsync (m); +// } catch (Exception e) { +// isConnecting = false.ToString (); +// } +// } +// } +//} -namespace Shared.Securitys -{ - public partial class EncryptionService - { +//namespace Shared.Securitys +//{ +// public partial class EncryptionService +// { - #region 鍔犲瘑 - /// <summary> - /// 鍔犲瘑涓婚涓築ase64 - /// </summary> - /// <param name="pToEncrypt"></param> - /// <param name="key"></param> - /// <returns></returns> - public static string AesEncryptTopic (string pToEncrypt, string key) - { - if (string.IsNullOrEmpty (pToEncrypt)) return null; - //闇�瑕佸姞瀵嗗唴瀹圭殑鏄庢枃娴� - Byte [] toEncryptArray = Encoding.UTF8.GetBytes (pToEncrypt); +// #region 鍔犲瘑 +// /// <summary> +// /// 鍔犲瘑涓婚涓築ase64 +// /// </summary> +// /// <param name="pToEncrypt"></param> +// /// <param name="key"></param> +// /// <returns></returns> +// public static string AesEncryptTopic (string pToEncrypt, string key) +// { +// if (string.IsNullOrEmpty (pToEncrypt)) return null; +// //闇�瑕佸姞瀵嗗唴瀹圭殑鏄庢枃娴� +// Byte [] toEncryptArray = Encoding.UTF8.GetBytes (pToEncrypt); - //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) - RijndaelManaged rm = new RijndaelManaged { - Key = Encoding.UTF8.GetBytes (key), - IV = Encoding.UTF8.GetBytes (key), - Mode = CipherMode.CBC, - Padding = PaddingMode.PKCS7 - }; +// //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) +// RijndaelManaged rm = new RijndaelManaged { +// Key = Encoding.UTF8.GetBytes (key), +// IV = Encoding.UTF8.GetBytes (key), +// Mode = CipherMode.CBC, +// Padding = PaddingMode.PKCS7 +// }; - //鍒涘缓AES鍔犲瘑鍣ㄥ璞� - ICryptoTransform cTransform = rm.CreateEncryptor (); +// //鍒涘缓AES鍔犲瘑鍣ㄥ璞� +// ICryptoTransform cTransform = rm.CreateEncryptor (); - //浣跨敤AES灏嗘槑鏂囨祦杞垚瀵嗘枃瀛楄妭鏁扮粍 - Byte [] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); +// //浣跨敤AES灏嗘槑鏂囨祦杞垚瀵嗘枃瀛楄妭鏁扮粍 +// Byte [] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); - //灏咥ES鐢熸垚鐨勫瘑鏂囧瓧鑺傛暟缁勮浆鎴怋ase64瀛楃涓� - return Convert.ToBase64String (resultArray, 0, resultArray.Length); - } +// //灏咥ES鐢熸垚鐨勫瘑鏂囧瓧鑺傛暟缁勮浆鎴怋ase64瀛楃涓� +// return Convert.ToBase64String (resultArray, 0, resultArray.Length); +// } - /// <summary> - /// 鍔犲瘑璐熻浇涓轰簩杩涘埗娴� - /// </summary> - /// <param name="toEncryptArray"></param> - /// <param name="key"></param> - /// <returns></returns> - public static byte [] AesEncryptPayload (byte [] toEncryptArray, string key) - { - //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) - var rm = new RijndaelManaged { - Key = Encoding.UTF8.GetBytes (key), - IV = Encoding.UTF8.GetBytes (key), - Mode = CipherMode.CBC, - Padding = PaddingMode.PKCS7 - }; +// /// <summary> +// /// 鍔犲瘑璐熻浇涓轰簩杩涘埗娴� +// /// </summary> +// /// <param name="toEncryptArray"></param> +// /// <param name="key"></param> +// /// <returns></returns> +// public static byte [] AesEncryptPayload (byte [] toEncryptArray, string key) +// { +// //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) +// var rm = new RijndaelManaged { +// Key = Encoding.UTF8.GetBytes (key), +// IV = Encoding.UTF8.GetBytes (key), +// Mode = CipherMode.CBC, +// Padding = PaddingMode.PKCS7 +// }; - //鍒涘缓AES鍔犲瘑鍣ㄥ璞� - var cTransform = rm.CreateEncryptor (); - //浣跨敤AES灏嗘槑鏂囨祦杞垚瀵嗘枃瀛楄妭鏁扮粍 - return cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); - } - #endregion +// //鍒涘缓AES鍔犲瘑鍣ㄥ璞� +// var cTransform = rm.CreateEncryptor (); +// //浣跨敤AES灏嗘槑鏂囨祦杞垚瀵嗘枃瀛楄妭鏁扮粍 +// return cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); +// } +// #endregion - #region 瑙e瘑 - /// <summary> - /// 瑙e瘑涓婚鏁版嵁 - /// </summary> - /// <param name="pToDecrypt"></param> - /// <param name="key"></param> - /// <returns></returns> - public static string AesDecryptTopic (string pToDecrypt, string key) - { - //AES瀵嗘枃Base64杞垚瀛楃涓� - Byte [] toEncryptArray = Convert.FromBase64String (pToDecrypt); +// #region 瑙e瘑 +// /// <summary> +// /// 瑙e瘑涓婚鏁版嵁 +// /// </summary> +// /// <param name="pToDecrypt"></param> +// /// <param name="key"></param> +// /// <returns></returns> +// public static string AesDecryptTopic (string pToDecrypt, string key) +// { +// //AES瀵嗘枃Base64杞垚瀛楃涓� +// Byte [] toEncryptArray = Convert.FromBase64String (pToDecrypt); - //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) - RijndaelManaged rm = new RijndaelManaged { - Key = Encoding.UTF8.GetBytes (key), - IV = Encoding.UTF8.GetBytes (key), - Mode = CipherMode.CBC, - Padding = PaddingMode.PKCS7 - }; +// //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) +// RijndaelManaged rm = new RijndaelManaged { +// Key = Encoding.UTF8.GetBytes (key), +// IV = Encoding.UTF8.GetBytes (key), +// Mode = CipherMode.CBC, +// Padding = PaddingMode.PKCS7 +// }; - //鍒涘缓AES瑙e瘑鍣ㄥ璞� - ICryptoTransform cTransform = rm.CreateDecryptor (); +// //鍒涘缓AES瑙e瘑鍣ㄥ璞� +// ICryptoTransform cTransform = rm.CreateDecryptor (); - //浣跨敤AES灏嗗瘑鏂囨祦杞垚鏄庢枃鐨勫瓧鑺傛暟缁� - Byte [] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); +// //浣跨敤AES灏嗗瘑鏂囨祦杞垚鏄庢枃鐨勫瓧鑺傛暟缁� +// Byte [] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); - //杞垚瀛楃涓� - return Encoding.UTF8.GetString (resultArray); - } +// //杞垚瀛楃涓� +// return Encoding.UTF8.GetString (resultArray); +// } - /// <summary> - /// 閲囩敤Aes瑙e瘑璐熻浇鏁版嵁 - /// </summary> - /// <param name="toEncryptArray"></param> - /// <param name="key"></param> - /// <returns></returns> - public static byte [] AesDecryptPayload (byte [] toEncryptArray, string key) - { - //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) - var rm = new RijndaelManaged { - Key = Encoding.UTF8.GetBytes (key), - IV = Encoding.UTF8.GetBytes (key), - Mode = CipherMode.CBC, - Padding = PaddingMode.PKCS7 - }; +// /// <summary> +// /// 閲囩敤Aes瑙e瘑璐熻浇鏁版嵁 +// /// </summary> +// /// <param name="toEncryptArray"></param> +// /// <param name="key"></param> +// /// <returns></returns> +// public static byte [] AesDecryptPayload (byte [] toEncryptArray, string key) +// { +// //閰嶇疆AES鍔犲瘑Key(瀵嗛挜銆佸悜閲忋�佹ā寮忋�佸~鍏�) +// var rm = new RijndaelManaged { +// Key = Encoding.UTF8.GetBytes (key), +// IV = Encoding.UTF8.GetBytes (key), +// Mode = CipherMode.CBC, +// Padding = PaddingMode.PKCS7 +// }; - //鍒涘缓AES瑙e瘑鍣ㄥ璞� - var cTransform = rm.CreateDecryptor (); +// //鍒涘缓AES瑙e瘑鍣ㄥ璞� +// var cTransform = rm.CreateDecryptor (); - //浣跨敤AES灏嗗瘑鏂囨祦杞垚鏄庢枃鐨勫瓧鑺傛暟缁� - return cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); - } - #endregion +// //浣跨敤AES灏嗗瘑鏂囨祦杞垚鏄庢枃鐨勫瓧鑺傛暟缁� +// return cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length); +// } +// #endregion - } -} -*/ \ No newline at end of file +// } +//} +//*/ \ No newline at end of file -- Gitblit v1.8.0