From 02498f7744e6fdc413e518f96b25f3635540dc6b Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 15 十一月 2022 11:27:38 +0800
Subject: [PATCH] 金茂科技系统更新

---
 HDL_ON/DAL/Mqtt/MqttClient.cs |  116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 111 insertions(+), 5 deletions(-)

diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index c16fd6f..ea5e472 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -205,6 +205,7 @@
                         QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                     };
 
+
                     #region 鏁版嵁鏇存柊鎺ㄩ�佷富棰�
                     //appHomeRefresh锛氫綇瀹呮暟鎹埛鏂伴�氱煡--鏉ㄦ稕
                     var appHomeRefresh = new MqttTopicFilter()
@@ -216,6 +217,12 @@
                     var residenceChange = new MqttTopicFilter()
                     {
                         Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up",
+                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
+                    };
+                    //璁惧鍦ㄧ嚎绂荤嚎鐘舵�佹帹閫�
+                    var deviceOnlinePush = new MqttTopicFilter()
+                    {
+                        Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/son/session/online",
                         QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                     };
                     //appRoomRefresh锛氭埧闂存暟鎹埛鏂伴�氱煡
@@ -253,6 +260,7 @@
                         pirStatus,pirStudy,
                         appDeviceRefresh,appHomeRefresh,appRoomRefresh,residenceChange,
                         topicFilterPush2, topicAlinkStatus ,mqttkeyChange,
+                        deviceOnlinePush,
                         securityStatusChange});
                     if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0)
                     {
@@ -266,6 +274,49 @@
                 }
             }
         }
+
+        /// <summary>
+        /// 璁㈤槄缁戝畾绗笁鏂筰ot璐﹀彿缁撴灉
+        /// </summary>
+        /// <returns></returns>
+        public static async Task<bool> SubscribeAsync3tyIotbind()
+        {
+            var topicFilter = new MqttTopicFilter()
+            {
+                Topic = $"/user/{UserInfo.Current.ID}/app/third/bind/send",
+                QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
+            };
+            var result = await RemoteMqttClient.SubscribeAsync(topicFilter);
+            if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0)
+            {
+                Utlis.WriteLine("璁㈤槄缁戝畾绗笁鏂筰ot璐﹀彿缁撴灉鎴愬姛锛�");
+                return true;
+            }
+            return false;
+        }
+        /// <summary>
+        /// 鍙栨秷璁㈤槄缁戝畾绗笁鏂筰ot璐﹀彿缁撴灉
+        /// </summary>
+        /// <returns></returns>
+        public static async Task<bool> UnsubscribeAsync3tyIotbind()
+        {
+            string[] strs = new string[] {
+                $"/user/{UserInfo.Current.ID}/app/third/bind/send"
+            };
+
+            var result = await RemoteMqttClient.UnsubscribeAsync(strs);
+            
+            if (result.Items[0].ReasonCode == MQTTnet.Client.Unsubscribing.MqttClientUnsubscribeResultCode.Success)
+            {
+                Utlis.WriteLine("鍙栨秷璁㈤槄缁戝畾绗笁鏂筰ot璐﹀彿缁撴灉鎴愬姛锛�");
+                return true;
+            }
+            return false;
+        }
+        /// <summary>
+        /// 缁戝畾绗笁鏂瑰钩鍙版帴鏀跺洖璋冧簨浠�
+        /// </summary>
+        public static Action Bind3tyIotAction;
 
         /// <summary>
         /// 鍚姩杩滅▼Mqtt
@@ -344,6 +395,38 @@
                                     var mMes = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
                                     //鏂版尋涓嬬嚎涓婚鏂规 鏀跺埌鎸や笅绾夸富棰�
                                     ReceiveNotifySqueezeAsync(mMes);
+                                }
+                                //缁戝畾绗笁鏂瑰钩鍙扮粨鏋滈�氱煡
+                                else if(topic == $"/user/{UserInfo.Current.ID}/app/third/bind/send")
+                                {
+                                    var revString = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
+                                    Bind3tyIotAction?.Invoke();
+                                }
+                                //璁惧鍦ㄧ嚎绂荤嚎鐘舵�佹帹閫�
+                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/son/session/online")
+                                {
+                                    try
+                                    {
+                                        //var mMes = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
+                                        //Newtonsoft.Json.Linq.JObject pairs = Newtonsoft.Json.Linq.JObject.Parse(mMes);
+                                        //var pairSid = pairs.GetValue("sid").ToString();
+                                        //var pairOnline = pairs.GetValue("online");
+                                        //if (!string.IsNullOrEmpty(pairSid.ToString()))
+                                        //{
+                                        //    var function_online = FunctionList.List.Functions.Find((obj) => obj.sid == pairSid);
+                                        //    if (function_online != null){
+                                        //        function_online.online = (bool)pairOnline;
+                                        //        HomePage.LoadEvent_RefreshDevcieOnline(function_online);
+                                        //        FunctionPage.UpdataOnline(function_online);
+                                        //        RoomPage.UpdataOnline(function_online);
+                                        //    }
+                                        //}
+
+                                    }
+                                    catch (Exception ex)
+                                    {
+
+                                    }
                                 }
                                 //App璁㈤槄绾㈠瀹�/缃戝叧閬ユ帶鍣ㄦ坊鍔犳垚鍔熼�氱煡
                                 else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/topo/found")
@@ -450,7 +533,8 @@
                                     {
                                         try
                                         {
-                                            var securityBytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.Instance.HomeGateway.aesKey);
+                                            var securityBytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload,
+                                                DB_ResidenceData.Instance.HomeGateway.aesKey);
                                             var securityString = Encoding.UTF8.GetString(securityBytes);
                                             var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityStatusObj>(securityString);
                                             MainPage.Log($"瀹夐槻鐘舵�佸彉鍖栵細{securityString}");
@@ -458,7 +542,6 @@
 
                                             if (temp != null)
                                             {
-                                                Control_Udp.ReceiveRepeatManager(temp.id, null);
                                                 foreach (var updataSecurity in temp.objects)
                                                 {
                                                     var updataLocalSecurity = FunctionList.List.securities.Find((obj) => obj.sid == updataSecurity.sid);
@@ -471,7 +554,8 @@
                                                 }
                                                 HomePage.LoadEvent_RefreshSecurityStatus();
                                             }
-                                        }catch(Exception ex)
+                                        }
+                                        catch (Exception ex)
                                         {
                                             MainPage.Log($"瀹夐槻杩滅▼淇℃伅寮傚父:{ex.Message}");
                                         }
@@ -479,13 +563,20 @@
                                 }
                                 #endregion
                                 //A缃戝叧璁惧鐘舵��-鍖呭惈娑傞甫璁惧
+                                //Tag 缃戠粶鐘舵�佽В鏋�
                                 else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/property/send")
                                 {
+
                                     var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey);
                                     var revString = Encoding.UTF8.GetString(bytes);
                                     MainPage.Log($"mqtt 鐘舵�佹洿鏂�:{revString}");
                                     Control.Ins.UpdataFunctionStatus(revString, null, true);
+                                    //Control.Ins.MsgInfoList.Add($"mqtt 鐘舵�佹洿鏂�:{revString}");
                                     //Control.Ins.MsgInfoList.Add(revString + "\r\n");
+                                    //if (FunctionList.List.OtherBrandFunction.Find((obj) => obj.sid == updateTemp.sid) == null)
+                                    //{
+                                    //    return;
+                                    //}
                                 }
                                 //涓�绔彛鏁版嵁瑙f瀽
                                 else
@@ -497,7 +588,8 @@
 
                                     if (!string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.aesKey))
                                     {
-                                        packet.Bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.Instance.HomeGateway.aesKey);
+                                        packet.Bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload,
+                                            DB_ResidenceData.Instance.HomeGateway.aesKey);
                                     }
                                     else
                                     {
@@ -754,6 +846,9 @@
         /// </summary>
         static void ReceiveNotifySqueezeAsync(string mMes)
         {
+#if DEBUG
+            return;
+#endif
             if (mMes == PushSignStr) return;//鏄嚜宸辩殑鐧诲綍鎺ㄩ�佷笉澶勭悊//鎴栬�呭綋鍓嶄笉鏄繙绋嬮摼鎺ョ姸鎬�
             //娴嬭瘯璐﹀彿锛屼笉鎸や笅绾�
             switch (UserInfo.Current.userMobileInfo)
@@ -810,7 +905,9 @@
         static void SendPushSignOut()
         {
             byte[] message = Encoding.UTF8.GetBytes(PushSignStr);
+#if DEBUG
             MqttRemoteSend(message, 4);
+#endif
         }
 
         /// <summary>
@@ -1057,8 +1154,17 @@
             //鍒涘缓AES瑙e瘑鍣ㄥ璞�
             var cTransform = rm.CreateDecryptor();
 
+            byte[] reData = null;
             //浣跨敤AES灏嗗瘑鏂囨祦杞垚鏄庢枃鐨勫瓧鑺傛暟缁�
-            return cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
+            try
+            {
+                reData = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+            }
+            return reData;
         }
         #endregion
 

--
Gitblit v1.8.0