From 5a5a2b696866f947b6025d26c3302e8ffef46435 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期一, 11 一月 2021 16:11:20 +0800 Subject: [PATCH] 2021-01-11 1.更新MQTT连接和本地搜索网关方法。2.子账号相关接口完善 --- Crabtree/SmartHome/HDL/Operation/Packet.cs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Crabtree/SmartHome/HDL/Operation/Packet.cs b/Crabtree/SmartHome/HDL/Operation/Packet.cs old mode 100755 new mode 100644 index e52dc8a..0779834 --- a/Crabtree/SmartHome/HDL/Operation/Packet.cs +++ b/Crabtree/SmartHome/HDL/Operation/Packet.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Text; - namespace Shared { public class Packet @@ -58,14 +57,19 @@ /// </summary> public virtual void Manager () { - //瀵逛簬鎿嶄綔鏁版嵁搴撶殑鏃堕棿姣旇緝闀跨殑锛屽彲浠ュ垱寤哄彟涓�涓嚎绋嬪鐞� - if (!"HDLMIRACLE".Equals (System.Text.Encoding.ASCII.GetString (Bytes, 4, 10))) { + //鍔犲瘑妫�娴� + EncryptionDetection (); + + //var mes2 = System.Text.Encoding.ASCII.GetString (Bytes, 0, Bytes.Length); + //Utlis.WriteLine ($"============>GetBytes 锛歿mes2}"); + + //瀵逛簬鎿嶄綔鏁版嵁搴撶殑鏃堕棿姣旇緝闀跨殑锛屽彲浠ュ垱寤哄彟涓�涓嚎绋嬪鐞� + if (!"HDLMIRACLE".Equals (System.Text.Encoding.ASCII.GetString (Bytes, 4, 10))) { return; } byte subnetID = this.Bytes [17]; //婧愬瓙缃戝彿 byte deviceID = this.Bytes [18]; //婧愯澶囧彿 - //婧愯澶囩被鍨� int deviceType = this.Bytes [19] * 256 + this.Bytes [20]; @@ -77,7 +81,8 @@ //涓嶆槸瑕佹帴鏀剁殑鎸囦护灏辫繑鍥� if (!((targetSubnetID == Global.LocalSubnetID && targetDeviceID == Global.LocalDeviceID) || (targetSubnetID == 0xff && targetDeviceID == 0xff))) { - return; + //Utlis.WriteLine ($"============>targetSubnetID return"); + return; } byte [] usefulBytes = null; if (this.Bytes [16] == 0xFF) { @@ -93,7 +98,7 @@ try { ReceiveEvent (subnetID, deviceID, command, usefulBytes); } catch (Exception ex) { - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } } @@ -113,5 +118,44 @@ } return s;// } + + /// <summary> + /// 鏄惁鏈湴 + /// </summary> + public bool IsLocal = true; + + /// <summary> + /// 鏈湴閫氳鏃� 鍔犲瘑妫�娴� + /// </summary> + void EncryptionDetection () { + if (IsLocal) {//鏈湴閫氳 + + if (UserConfig.Instance.IsLocalEncrypt) { + if (Bytes.Length == 28) { + var mes = System.Text.Encoding.ASCII.GetString (Bytes, 14, 14); + if ("Password error" == mes) { + //缃戝叧杩斿洖锛屽姞瀵嗗瘑鐮乲ey涓嶅 + UserConfig.Instance.EncryptedPasswordCorrect = false; + return; + } + } + var messageGet = Shared.Securitys.EncryptionService.AesDecryptPayload (Bytes, UserConfig.Instance.LocalEncryptKey); + Bytes = messageGet; + + + } else { + if (Bytes.Length == 20) { + var mes = System.Text.Encoding.ASCII.GetString (Bytes, 14, 6); + if ("Locked" == mes) { + //缃戝叧宸插姞瀵嗭紝鑷姩鍒囨崲涓哄姞瀵� + UserConfig.Instance.IsLocalEncrypt = true; + } + } + } + + } + } + + } -} \ No newline at end of file +} -- Gitblit v1.8.0