From acc8caee31c4be90bd38d1af18136b0e84f6fe94 Mon Sep 17 00:00:00 2001
From: wxr <wxr@hdlchina.com.cn>
Date: 星期五, 27 九月 2024 14:01:19 +0800
Subject: [PATCH] Merge branch 'feature/v2.7_迭代' into feature/V2.7_Google

---
 HDL_ON/Common/ApiUtlis.cs |  332 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 253 insertions(+), 79 deletions(-)

diff --git a/HDL_ON/Common/ApiUtlis.cs b/HDL_ON/Common/ApiUtlis.cs
index 8ca313c..7d6dbd5 100644
--- a/HDL_ON/Common/ApiUtlis.cs
+++ b/HDL_ON/Common/ApiUtlis.cs
@@ -1,9 +1,10 @@
 锘縰sing System;
 using System.Collections.Generic;
-using HDL_ON;
-using HDL_ON.DAL;
+using System.Net.Http;
+using System.Threading.Tasks;
 using HDL_ON.DAL.Server;
 using HDL_ON.Entity;
+using HDL_ON.UI;
 using HDL_ON.UI.UI2.FuntionControlView.Video;
 using HDL_ON.UI.UI2.Intelligence.Automation;
 using Newtonsoft.Json;
@@ -73,6 +74,11 @@
         /// </summary>
         public bool DownloadDataComplete = false;
 
+        /// <summary>
+        /// token鏄惁鏈夋晥
+        /// </summary>
+        public bool IsValidToken = false;
+
         public bool hadInternet = true;
         /// <summary>
         /// 涓嬭浇鏁版嵁
@@ -104,7 +110,7 @@
                 try
                 {
                     //澧炲姞3绉掍簯鏈嶅姟鍣ㄨ繛鎺ユ娴嬶紝杩炰笉涓婃湇鍔″櫒鐨勬椂鍊欎笉鍒锋柊鏁版嵁
-                    hadInternet = true;
+                    //hadInternet = true;
                     var dataList = new List<GlobalRegionListRes>();
                     var requestJson = HttpUtil.GetSignRequestJson(new GetRegionListObj() { regionMark = HttpUtil.RegionMark });
                     var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GlobalRegionList, requestJson, HttpUtil.GlobalRequestHttpsHost, "", 3);
@@ -127,7 +133,7 @@
                         }
                         catch (Exception ex)
                         {
-                            MainPage.Log($"{this.GetType()}:鍔犺浇缂撳瓨鎴块棿鏁版嵁寮傚父:{ex.Message}");
+                            MainPage.Log("Error",$"{this.GetType()}:鍔犺浇缂撳瓨鎴块棿鏁版嵁寮傚父:{ex.StackTrace}");
                         }
 
                         try
@@ -141,10 +147,8 @@
                         }
                         catch (Exception ex)
                         {
-                            MainPage.Log($"{this.GetType()}:鍔犺浇缂撳瓨璁惧鏁版嵁寮傚父:{ex.Message}");
+                            MainPage.Log("Error", $"{this.GetType()}:鍔犺浇缂撳瓨璁惧鏁版嵁寮傚父:{ex.StackTrace}");
                         }
-
-
                         return;
                     }
                     else
@@ -154,12 +158,13 @@
                 }
                 catch (Exception ex)
                 {
-                    MainPage.Log($"Error锛氫笅杞芥暟鎹�1锛歿ex.Message}");
+                    MainPage.Log("Error", $"涓嬭浇鏁版嵁1锛歿ex.StackTrace}");
                     DownloadDataComplete = true;
                     return;
                 }
                 finally
                 {
+                    MainPage.Log("鏈嶅姟鍣ㄨ繛鎺ョ姸鎬�:" + hadInternet);
                     if (!hadInternet)
                     {
                         Application.RunOnMainThread(() =>
@@ -177,6 +182,42 @@
                 code = Ins.HttpRequest.RefreshToken();
                 if (code != StateCode.SUCCESS)
                 {
+                    DownloadDataComplete = true;
+                    IsValidToken= false;
+                    try
+                    {
+                        var spatialInfoDataBytes = FileUtlis.Files.ReadFile("SpatialInfoData");
+                        if (spatialInfoDataBytes != null)
+                        {
+                            var spatialInfoDataString = System.Text.Encoding.UTF8.GetString(spatialInfoDataBytes);
+                            if (spatialInfoDataString != null && !string.IsNullOrEmpty(spatialInfoDataString))
+                            {
+                                var spatialInfoDataList = JsonConvert.DeserializeObject<List<SpatialInfo>>(spatialInfoDataString);
+                                SpatialInfo.CurrentSpatial.UpdateSpatialList(spatialInfoDataList);
+                            }
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        MainPage.Log("Error", $"{this.GetType()}:鍔犺浇缂撳瓨鎴块棿鏁版嵁寮傚父:{ex.StackTrace}");
+                    }
+
+                    try
+                    {
+                        var fileList = Common.FileUtlis.Files.ReadFiles();
+                        foreach (var file in fileList)
+                        {
+                            FunctionList.List.IniFunctionList(file, true);
+                        }
+                        Room.CurrentSpatial.InitRoomListFunctions();
+                    }
+                    catch (Exception ex)
+                    {
+                        MainPage.Log("Error", $"{this.GetType()}:鍔犺浇缂撳瓨璁惧鏁版嵁寮傚父:{ex.StackTrace}");
+                    }
+                    MainPage.Log($"鍒锋柊token澶辫触");
+
+
                     if (waitPage != null)
                     {
                         Application.RunOnMainThread(() =>
@@ -190,8 +231,11 @@
                             catch { }
                         });
                     }
-                    MainPage.Log($"鍒锋柊token澶辫触");
                     return;
+                }
+                else
+                {
+                    hadInternet = true;
                 }
                 MainPage.Log($"鍒锋柊token鎴愬姛");
                 //===================鍒锋柊浣忓畢淇℃伅=======================
@@ -237,26 +281,6 @@
                 }
                 MainPage.Log($"鍒锋柊涓汉淇℃伅鎴愬姛");
 
-                //int count = 0;
-                //while (count < 10)
-                //{
-                //    if (DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull())
-                //    {
-                //        System.Threading.Thread.Sleep(200);
-                //    }
-                //    else
-                //    {
-                //        break;
-                //    }
-                //    count++;
-                //}
-                //if (DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull())
-                //{
-                //    return;
-                //}
-
-                //return;
-
                 try
                 {
                     //===================鎴块棿=======================
@@ -277,9 +301,10 @@
                                 {
                                     var ssd = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(revData.list));
                                     FileUtlis.Files.WriteFileByBytes("SpatialInfoData", ssd);
-                                }catch(Exception ex)
+                                }
+                                catch (Exception ex)
                                 {
-                                    MainPage.Log($"{this.GetType()}:淇濆瓨鎴块棿淇℃伅寮傚父锛歿ex.Message}");
+                                    MainPage.Log("Error", $"{this.GetType()}:淇濆瓨鎴块棿淇℃伅寮傚父锛歿ex.StackTrace}");
                                 }
                             })
                             { IsBackground = true }.Start();
@@ -301,7 +326,7 @@
                             {
                                 FunctionList.List.ClearDatas();
                                 MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛");
-                                MainPage.Log($"sid鍒楄〃鑾峰彇====\r\n" , deviceResult.Data.ToString());
+                                //MainPage.Log($"sid鍒楄〃鑾峰彇====\r\n", deviceResult.Data.ToString());
                                 var deviceList = JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
                                 if (deviceList == null)
                                 {
@@ -325,7 +350,7 @@
                                 }
                                 finally
                                 {
-                                    
+
                                 }
 
                                 string delFile = "";
@@ -356,8 +381,8 @@
                                 foreach (var newFunction in deviceList.list)
                                 {
                                     newFunction.AssembleStatus();
-                                    newFunction.SaveFunctionFile(); 
-                                    FunctionList.List.IniFunctionList(newFunction.savePath,true);
+                                    newFunction.SaveFunctionFile();
+                                    FunctionList.List.IniFunctionList(newFunction.savePath, true);
                                     //MainPage.Log($"============璁惧============{iiii++}");
                                 }
 
@@ -379,7 +404,7 @@
                                     string videoList = videoInfo.Data.ToString();
                                     FunctionList.List.videoIntercom = JsonConvert.DeserializeObject<List<UI.UI2.FuntionControlView.Video.Video>>(videoList);
 
-                                    for(int i =0;i< FunctionList.List.videoIntercom.Count;i++)
+                                    for (int i = 0; i < FunctionList.List.videoIntercom.Count; i++)
                                     {
                                         var video = FunctionList.List.videoIntercom[i];
 
@@ -387,7 +412,91 @@
                                         {
                                             UI.UI2.PersonalCenter.PirDevice.PirSend.LcSubAccessToken = video.subAccountToken;
                                         }
+                                        else if (video.interphoneType == InterphoneType.HDL.ToString())
+                                        {
+                                            isInterphoneType_HDL = true;
+                                            DB_ResidenceData.Instance.SupportFacePass = true;
+                                            DB_ResidenceData.Instance.SaveResidenceData();
+                                            DB_ResidenceData.Instance.SupportFVDevice = true;
+                                        }
+                                        else if (video.interphoneType == InterphoneType.FREEVIEW.ToString())
+                                        {
+#if __IOS__
+                                            try
+                                            {
+                                                FunctionList.List.videoIntercom.Remove(video);
+                                                --i;
+                                            }catch(Exception ex)
+                                            {
+                                                MainPage.Log("Error", $"ios 鍏ㄨ閫氬紓甯� : {ex.StackTrace}");
+                                            }
+
+#else
+                                            //涓哄叏瑙嗛�氬彲瑙嗗璁�
+                                            DB_ResidenceData.Instance.SupportFacePass = true;
+                                            Entity.DB_ResidenceData.Instance.SupportVisitorManage = true;
+                                            Entity.DB_ResidenceData.Instance.SupportFVDevice = true;
+                                            isInterphoneType_FREEVIEW = true;
+#endif
+                                        }
                                     }
+                                }
+
+
+                                //======================鑾峰彇Sip璐﹀彿骞朵笖鍒濆鍖朣DK鍙瀵硅璁惧鍒楄〃====================
+                                //濡傛灉妫�娴嬬嚎绋嬫病鍚姩锛屾墠缁х画涓嬮潰鎿嶄綔 鍥犱负App鏈夊彲鑳藉垰鍚姩椹笂鏀跺埌鎺ㄩ�佷簡锛岀劧鍚庢墠鎵ц鍒拌繖閲�
+                                if (HDLLinphone.Current.CheckIncomingCallThreadIsNull())
+                                {
+
+                                    //褰撳墠浣忓畢鏄疕DL鍙瀵硅绫诲瀷鐨勮澶�
+                                    if (isInterphoneType_HDL)
+                                    {
+                                        //HDLLinphone鍙瀵硅,鑾峰彇Sip璐﹀彿骞跺垵濮嬪寲SDK
+                                        HDLCallVideoInfo callVideoInfo = new HDLCallVideoInfo();
+                                        callVideoInfo.HomeId = DB_ResidenceData.Instance.CurrentRegion.id;
+                                        callVideoInfo.InterphoneType = InterphoneType.HDL.ToString();
+                                        HDLLinphone.Current.GetHDLSipInfoAndInitSDK(callVideoInfo);
+                                    }
+                                    else if (isInterphoneType_FREEVIEW)
+                                    {
+                                        //HDLLinphone鍙瀵硅,鑾峰彇Sip璐﹀彿骞跺垵濮嬪寲SDK
+                                        HDLCallVideoInfo callVideoInfo = new HDLCallVideoInfo();
+                                        callVideoInfo.HomeId = DB_ResidenceData.Instance.CurrentRegion.id;
+                                        callVideoInfo.InterphoneType = InterphoneType.FREEVIEW.ToString();
+                                        HDLLinphone.Current.GetHDLSipInfoAndInitSDK(callVideoInfo);
+                                    }
+                                    else
+                                    {
+                                        Utlis.WriteLine("褰撳墠浣忓畢涓嶆敮鎸丠DL鍙瀵硅,閫�鍑虹櫥褰曟墍鏈夎处鍙�");
+                                        //褰撳墠浣忓畢涓嶆敮鎸丠DL鍙瀵硅
+                                        HDLLinphone.Current.LogoutAllAccount();
+                                    }
+                                }
+
+
+
+                                //======================鐧诲綍鍏ㄨ閫�====================
+                                if (isInterphoneType_FREEVIEW)
+                                {
+
+#if __IOS__
+                                    //string systemVersion = UIKit.UIDevice.CurrentDevice.SystemVersion;
+                                    //string errorVersion = "16.2.0";
+                                    //if (systemVersion.CompareTo(errorVersion) < 0)///鍏ㄨ閫氫笉鍏煎ios16浠ヤ笂鐨勭郴缁燂紝涓嶈鍔犺浇杩欎釜鍏�
+                                    //{
+                                    //    List<VisitorTempPassword> dataList = new List<VisitorTempPassword>();
+                                    //    Dictionary<string, object> dictionary = new Dictionary<string, object>();
+                                    //    dictionary.Add("homeId", Entity.DB_ResidenceData.Instance.CurrentRegion.id);
+                                    //    var requestJson = HttpUtil.GetSignRequestJson(dictionary);
+                                    //    ResponsePackNew pack = HttpUtil.RequestHttpsPost(NewAPI.Api_Post_GetExtMemberInfo, requestJson);
+                                    //    if (pack != null)
+                                    //    {
+                                    //        var data = JsonConvert.DeserializeObject<FreeviewMemberInfo>(pack.Data.ToString());
+                                    //        //鐧诲綍鍏ㄨ閫�
+                                    //        Shared.IOS.HDLFVSDK.Video.Init("", data.extUserId, DB_ResidenceData.Instance.CurrentRegion.id, "78FF1E4D-FC0A-4E71-9B79-0448E4460BD7", "T0001", "120.77.53.170:9700", "120.77.53.170:21664");
+                                    //    }
+                                    //}
+#endif
                                 }
 
                             }
@@ -395,16 +504,16 @@
                             {
                                 MainPage.Log($"璇诲彇浜戠璁惧鏁版嵁澶辫触:Code:{deviceResult.Code};  Msg:{deviceResult.message}");
                             }
-                        }catch (Exception ex)
+                        }
+                        catch (Exception ex)
                         {
-                            MainPage.Log($"============璁惧============{ex.Message}");
+                            MainPage.Log("Error", $"============璁惧============{ex.StackTrace}");
                         }
                         finally
                         {
                             complateDevice = true;
                             MainPage.Log($"============璁惧============瀹屾垚" + FunctionList.List.Functions.Count);
                         }
-
 
                         //======================缇ゆ帶====================
                         if (DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl)
@@ -418,16 +527,16 @@
                                     {
                                         var groupControlList = JsonConvert.DeserializeObject<List<GroupControl>>(pack.Data.ToString());
                                         var readSidList = new List<string>();
-                                        foreach(var temp in groupControlList)
+                                        foreach (var temp in groupControlList)
                                         {
                                             FunctionList.List.groupControls.Clear();
                                             readSidList.Add(temp.userDeviceGroupControlId);
                                             if (readSidList.Count >= 20)
                                             {
                                                 var data = Ins.httpRequest.GetGroupControInfo(readSidList);
-                                                if(data != null)
+                                                if (data != null)
                                                 {
-                                                    if(data.Code == StateCode.SUCCESS)
+                                                    if (data.Code == StateCode.SUCCESS)
                                                     {
                                                         var groupControlInfoList = JsonConvert.DeserializeObject<List<GroupControl>>(data.Data.ToString());
                                                         FunctionList.List.groupControls.AddRange(groupControlInfoList);
@@ -461,7 +570,7 @@
                                     }
                                     catch (Exception ex)
                                     {
-                                        MainPage.Log($"璇诲彇缁勬帶鍒楄〃澶辫触:{ex.Message}");
+                                        MainPage.Log("Error", $"璇诲彇缁勬帶鍒楄〃澶辫触:{ex.StackTrace}");
                                     }
                                 }
                                 else
@@ -523,9 +632,10 @@
                             {
                                 MainPage.Log($"璇诲彇浜戠鍦烘櫙鏁版嵁澶辫触:Code:{pack.Code}; Msg:{pack.message}");
                             }
-                        }catch(Exception ex)
+                        }
+                        catch (Exception ex)
                         {
-                            MainPage.Log($"===鍦烘櫙==={ex.Message}");
+                            MainPage.Log("Error", $"===鍦烘櫙==={ex.StackTrace}");
                         }
                         finally
                         {
@@ -546,7 +656,7 @@
                 }
                 catch (Exception ex)
                 {
-                    MainPage.Log($"鏁版嵁鍒濆鍖栧け璐ワ細{ex.Message}");
+                    MainPage.Log("Error", $"鏁版嵁鍒濆鍖栧け璐ワ細{ex.StackTrace}");
                 }
                 finally
                 {
@@ -565,9 +675,10 @@
                     try
                     {
                         FunctionList.List.Read3tyFunctionStatus();
-                    }catch(Exception ex)
+                    }
+                    catch (Exception ex)
                     {
-                        MainPage.Log("璇诲彇绗笁鏂硅澶囩姸鎬佸け璐�:"+ex.Message);
+                        MainPage.Log("Error", "璇诲彇绗笁鏂硅澶囩姸鎬佸け璐�:" + ex.StackTrace);
                     }
                 }
             });
@@ -603,13 +714,46 @@
                 {
                     if (DB_ResidenceData.Instance.CurrentRegion != null)
                     {
-#region 璇诲彇鏈湴鏁版嵁
-                        //鎼滅储缃戝叧
-                        DriverLayer.Control.Ins.SearchLoaclGateway();
-                        //閲嶆柊杩炴帴mqtt
-                        DAL.Mqtt.MqttClient.DisConnectRemote("鍒锋柊鏁版嵁锛岄噸杩瀖qtt",false);
-#endregion
+                        try
+                        {
+                            #region 璇诲彇鏈湴鏁版嵁
+                            //鎼滅储缃戝叧
+                            DriverLayer.Control.Ins.SearchLoaclGateway();
+                            //閲嶆柊杩炴帴mqtt
+                            DAL.Mqtt.MqttClient.DisConnectRemote("鍒锋柊鏁版嵁锛岄噸杩瀖qtt", false);
+                            #endregion
+                        }
+                        catch (Exception ex){
+                            MainPage.Log("Error", $"璇诲彇鏈湴鏁版嵁寮傚父锛歿ex.StackTrace}");
+                        }
 
+                        try
+                        {
+                            HomePage.LoadEvent_CheckTokenValid();
+                            if (IsValidToken && !UserInfo.Current.IsTipedInvalidToken)
+                            {
+                                UserInfo.Current.IsTipedInvalidToken = true;
+                                UserInfo.Current.SaveUserInfo();
+                                Application.RunOnMainThread(() =>
+                                {
+                                    try
+                                    {
+                                        new PublicAssmebly().TipOptionMsg(StringId.Tip, StringId.TokenInvalidTipMsg, StringId.OfflineControl, StringId.GoLogin, () =>
+                                        {
+                                            HDLCommon.Current.Logout();
+                                        });
+                                    }
+                                    catch (Exception ex)
+                                    {
+                                        MainPage.Log("Error", $"鎻愮ず鐧诲綍鍑瘉绐楀彛鍔犺浇寮傚父:{ex.StackTrace}");
+                                    }
+                                });
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            MainPage.Log("Error", $"鏇存柊鐧诲綍鍑瘉鏂规硶璋冪敤寮傚父:{ex.StackTrace}");
+                        }
                     }
                 }
             })
@@ -642,39 +786,50 @@
         {
             lock (FunctionList.List.securities)
             {
-                var pack = Ins.HttpRequest.GetSecurityList();
-                if (pack.Code == StateCode.SUCCESS)
+                try
                 {
-                    var packList = JsonConvert.DeserializeObject<List<SecurityAlarm>>(pack.Data.ToString());
-                    Console.WriteLine("瀹夐槻鎬绘暟锛�" + packList.Count);
-                    var sidList = new List<string>();
-                    foreach (var function in packList)
+                    var pack = Ins.HttpRequest.GetSecurityList();
+                    if (pack.Code == StateCode.SUCCESS)
                     {
-                        sidList.Add(function.sid);
-                    }
-                    var infoListPack = Ins.httpRequest.GetSecurityInfo(sidList, new List<string>());
-                    var infoList = JsonConvert.DeserializeObject<List<SecurityAlarm>>(infoListPack.Data.ToString());
-                    if (infoList != null)
-                    {
-                        var filePathList = FileUtlis.Files.ReadFiles().FindAll((obj) => obj.StartsWith("SecurityData_"));
-                        if (filePathList != null)
+                        var packList = JsonConvert.DeserializeObject<List<SecurityAlarm>>(pack.Data.ToString());
+                        Console.WriteLine("瀹夐槻鎬绘暟锛�" + packList.Count);
+                        var sidList = new List<string>();
+                        foreach (var function in packList)
                         {
-                            foreach (var file in filePathList)
+                            sidList.Add(function.sid);
+                        }
+                        if (sidList.Count == 0)
+                        {
+                            return;
+                        }
+                        var infoListPack = Ins.httpRequest.GetSecurityInfo(sidList, new List<string>());
+                        var infoList = JsonConvert.DeserializeObject<List<SecurityAlarm>>(infoListPack.Data.ToString());
+                        if (infoList != null)
+                        {
+                            var filePathList = FileUtlis.Files.ReadFiles().FindAll((obj) => obj.StartsWith("SecurityData_"));
+                            if (filePathList != null)
                             {
-                                FileUtlis.Files.DeleteFile(file);
+                                foreach (var file in filePathList)
+                                {
+                                    FileUtlis.Files.DeleteFile(file);
+                                }
+                            }
+                            FunctionList.List.securities.Clear();
+                            foreach (var function in infoList)
+                            {
+                                function.SaveFile();
+                                FunctionList.List.IniFunctionList(function.savePath, true);
                             }
                         }
-                        FunctionList.List.securities.Clear();
-                        foreach (var function in infoList)
-                        {
-                            function.SaveFile();
-                            FunctionList.List.IniFunctionList(function.savePath, true);
-                        }
+                    }
+                    else
+                    {
+                        MainPage.Log($"璇诲彇瀹夐槻鍒楄〃澶辫触:Code:{pack.Code}; Msg:{pack.message}");
                     }
                 }
-                else
+                catch (Exception ex)
                 {
-                    MainPage.Log($"璇诲彇瀹夐槻鍒楄〃澶辫触:Code:{pack.Code}; Msg:{pack.message}");
+                    MainPage.Log("Error", $"璇诲彇瀹夐槻鍒楄〃澶辫触:Code:{ex.StackTrace}");
                 }
             }
         }
@@ -687,6 +842,25 @@
             var pack = Ins.HttpRequest.GetSecurityList();
         }
 
+        //public async Task<bool> CanConnectToHost()
+        //{
+        //    try
+        //    {
+        //        using (HttpClient client = new HttpClient())
+        //        {
+        //            client.Timeout = TimeSpan.FromSeconds(3); // 瓒呮椂鏃堕棿
+        //            HttpResponseMessage response = await client.GetAsync(HttpUtil.GlobalRequestHttpsHost);
+        //            return response.IsSuccessStatusCode;
+        //        }
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        MainPage.Log(ex.StackTrace);
+        //        return false;
+        //    }
+        //}
+
 
     }
-}
\ No newline at end of file
+}
+

--
Gitblit v1.8.0