From a3313818a548d51777ae4e6cc006e9d1e2c1036e Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期五, 07 四月 2023 09:15:37 +0800
Subject: [PATCH] 群控备份

---
 HDL_ON/DAL/Mqtt/MqttClient.cs |   91 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 85 insertions(+), 6 deletions(-)

diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index f5abbf2..12026aa 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -204,6 +204,13 @@
                         Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/irCodeStudyDone/up",
                         QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                     };
+                    //App璁㈤槄缇ゆ帶鐘舵�佷富棰�
+                    var groupControlStatus = new MqttTopicFilter()
+                    {
+                        Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/device/group/control/property/send",
+                        QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
+                    };
+
 
                     #region 鏁版嵁鏇存柊鎺ㄩ�佷富棰�
                     //appHomeRefresh锛氫綇瀹呮暟鎹埛鏂伴�氱煡--鏉ㄦ稕
@@ -261,6 +268,11 @@
                         topicFilterPush2, topicAlinkStatus ,mqttkeyChange,
                         deviceOnlinePush,
                         securityStatusChange});
+                    //璁㈤槄缇ゆ帶鐘舵��
+                    if (DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl)
+                    {
+                        await RemoteMqttClient.SubscribeAsync(groupControlStatus);
+                    }
                     if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0)
                     {
                         isSubscribeSuccess = true;
@@ -275,14 +287,59 @@
         }
 
         /// <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
         /// </summary>
         public static async Task StartCloudMqtt()
         {
-            if (MainPage.InternetStatus == 0)
+            //娌℃湁缃戠粶鐨勭姸鎬佷笅灏濊瘯涓�涓嬭繛鎺qtt 锛屽畨鍗撶殑缃戠粶鐘舵�佸彉鍖栫洃鍚湁寮傚父锛屼慨鏀瑰簳灞傞夯鐑�
+            if (MainPage.InternetStatus == 0 && MainPage.LinkHdlMqttCount > 1)
             {
                 return;
             }
+            MainPage.LinkHdlMqttCount++;
 
             if (!UserInfo.Current.IsLogin)
             {
@@ -352,8 +409,14 @@
                                     //鏂版尋涓嬬嚎涓婚鏂规 鏀跺埌鎸や笅绾夸富棰�
                                     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")
+                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/son/session/online")
                                 {
                                     try
                                     {
@@ -373,7 +436,7 @@
                                         //}
 
                                     }
-                                    catch(Exception ex)
+                                    catch (Exception ex)
                                     {
 
                                     }
@@ -394,8 +457,7 @@
                                 }
                                 #region 鏁版嵁鏇存柊鎺ㄩ�佷富棰�
                                 //appHomeRefresh锛氫綇瀹呮暟鎹埛鏂伴�氱煡
-                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appHomeRefresh/up"
-                                        || topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up")
+                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appHomeRefresh/up")
                                 {
                                     MainPage.Log("浣忓畢鏁版嵁鍒锋柊閫氱煡");
                                     new HttpServerRequest().GetHomePager();
@@ -504,13 +566,22 @@
                                                 }
                                                 HomePage.LoadEvent_RefreshSecurityStatus();
                                             }
-                                        }catch(Exception ex)
+                                        }
+                                        catch (Exception ex)
                                         {
                                             MainPage.Log($"瀹夐槻杩滅▼淇℃伅寮傚父:{ex.Message}");
                                         }
                                     }
                                 }
                                 #endregion
+                                //缇ゆ帶鐘舵��
+                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/device/group/control/property/send")
+                                {
+                                    var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey);
+                                    var revString = Encoding.UTF8.GetString(bytes);
+                                    MainPage.Log($"mqtt 缇ゆ帶鐘舵�佹洿鏂�:{revString}");
+                                    Control.Ins.UpdataGroupControlStatus(revString, null, true);
+                                }
                                 //A缃戝叧璁惧鐘舵��-鍖呭惈娑傞甫璁惧
                                 //Tag 缃戠粶鐘舵�佽В鏋�
                                 else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/property/send")
@@ -521,6 +592,10 @@
                                     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
@@ -562,6 +637,10 @@
                         {
                             IfNeedReadAllDeviceStatus = true;
                             Control.Ins.GatewayOnline_Cloud = true;
+                            if(MainPage.InternetStatus == 0)
+                            {
+                                MainPage.InternetStatus = 1;
+                            }
                             Utlis.WriteLine($"============>Mqtt杩滅▼杩炴帴鎴愬姛");
                             SendPushSignOut();
                         });

--
Gitblit v1.8.0