From b847c06d8617efb2cbbad6f11b0344b779138e92 Mon Sep 17 00:00:00 2001 From: wxr <wxr@hdlchina.com.cn> Date: 星期一, 14 十月 2024 18:03:45 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/wjc' into feature/v2.7_迭代 --- HDL_ON/DAL/Mqtt/MqttClient.cs | 162 +++++++++++++++++++---------------------------------- 1 files changed, 59 insertions(+), 103 deletions(-) diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs index a403e13..429c0a7 100644 --- a/HDL_ON/DAL/Mqtt/MqttClient.cs +++ b/HDL_ON/DAL/Mqtt/MqttClient.cs @@ -12,6 +12,9 @@ using HDL_ON.Entity; using HDL_ON.UI; using HDL_ON.DAL.Server; +using HDL_ON; +using Newtonsoft.Json; +using System.Collections.Generic; namespace HDL_ON.DAL.Mqtt { @@ -56,7 +59,7 @@ /// <summary> /// 鎺ㄩ�佹爣璇� /// </summary> - static string PushSignStr = DateTime.Now.Ticks.ToString(); + static string PushSignStr = OnAppConfig.Instance.PushSignStr; /// <summary> /// 鏂紑杩滅▼Mqtt鐨勯摼鎺� @@ -110,7 +113,7 @@ { MqttInfoConfig.Current.IfGetMqttInfoSuccess = false; } - Control.Ins.GatewayOnline_Cloud = Control.Ins.GatewayOnline_Local = false; + //Control.Ins.GatewayOnline_Cloud = Control.Ins.GatewayOnline_Local = false; await DisConnectRemoteMqttClient(s); } @@ -124,8 +127,6 @@ { InitMqtt(); } - - public static bool IsInitMqtt = false; static void InitMqtt() { @@ -144,6 +145,7 @@ await StartCloudMqtt(); await SubscribeTopics(); + } catch { } } @@ -157,10 +159,11 @@ public static void InitState() { IfNeedReadAllDeviceStatus = true; + Common.ApiUtlis.Ins.hadInternet = true; StartCloudMqtt(); } - static bool isSubscribeSuccess; + public static bool isSubscribeSuccess; /// <summary> /// 璁㈤槄涓婚 /// </summary> @@ -262,8 +265,8 @@ #endregion - Utlis.WriteLine("寮�濮嬭闃咃紒"); - var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { + Utlis.WriteLine("寮�濮嬭闃咃紒"); + var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] { pirStatus,pirStudy, appDeviceRefresh,appHomeRefresh,appRoomRefresh,residenceChange, topicFilterPush2, topicAlinkStatus ,mqttkeyChange, @@ -336,17 +339,23 @@ public static async Task StartCloudMqtt() { //娌℃湁缃戠粶鐨勭姸鎬佷笅灏濊瘯涓�涓嬭繛鎺qtt 锛屽畨鍗撶殑缃戠粶鐘舵�佸彉鍖栫洃鍚湁寮傚父锛屼慨鏀瑰簳灞傞夯鐑� - if (MainPage.InternetStatus == 0 && MainPage.LinkHdlMqttCount > 1) + if (MainPage.InternetStatus == 0 && MainPage.LinkHdlMqttCount > 1 ) + { + return; + } + + + if (!Common.ApiUtlis.Ins.hadInternet) { return; } MainPage.LinkHdlMqttCount++; - if (!UserInfo.Current.IsLogin) - { - return; - } - if (DB_ResidenceData.Instance.CurrentRegion == null || DB_ResidenceData.Instance.CurrentRegion.id == null) + //if (!UserInfo.Current.IsLogin) + //{ + // return; + //} + if (OnAppConfig.Instance.LastLoginUserId == ""|| DB_ResidenceData.Instance.CurrentRegion == null || DB_ResidenceData.Instance.CurrentRegion.id == null) { return; } @@ -362,6 +371,26 @@ await Task.Factory.StartNew((Func<Task>)(async () => { try { + try + { + //澧炲姞3绉掍簯鏈嶅姟鍣ㄨ繛鎺ユ娴嬶紝杩炰笉涓婃湇鍔″櫒鐨勬椂鍊欎笉鍒锋柊鏁版嵁 + 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); + if (revertObj == null || revertObj.Code != StateCode.SUCCESS) + { + Common.ApiUtlis.Ins.hadInternet = false; + return; + } + else + { + Common.ApiUtlis.Ins.hadInternet = true; + } + } + catch + { + } + #region 鍒濆鍖栬繙绋婱qtt RemoteMqttIsConnecting = true; RemoteMqttClient = new MqttFactory().CreateMqttClient(); @@ -490,48 +519,6 @@ else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up") { MainPage.Log("璁惧鏁版嵁鍒锋柊閫氱煡"); - var deviceResult = new HttpServerRequest().GetDeviceList(); - if (deviceResult.Code == StateCode.SUCCESS) - { - MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛"); - var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); - if (deviceList == null) - { - deviceList = new DevcieApiPack(); - } - string delFile = ""; - if (FunctionList.List.GetDeviceFunctionList().Count > 0) - { - for (int i = 0; i < FunctionList.List.GetDeviceFunctionList().Count;) - { - var localFunction = FunctionList.List.GetDeviceFunctionList()[i]; - if (SPK.MusicSpkList().Contains(localFunction.spk)) - { - i++; - continue; - } - var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId); - - if (delFile == localFunction.savePath) - { - i++; - continue; - } - delFile = localFunction.savePath; - FunctionList.List.DeleteFunction(localFunction); - } - } - //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳� - foreach (var newFunction in deviceList.list) - { - newFunction.SaveFunctionFile(); - FunctionList.List.IniFunctionList(newFunction.savePath); - } - } - else - { - MainPage.Log($"璇诲彇浜戠璁惧鏁版嵁澶辫触:Code:{deviceResult.Code}; Msg:{deviceResult.message}"); - } } //缃戝叧瀵嗛挜鍙樺寲 else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/custom/mqtt/secret/change") @@ -590,7 +577,7 @@ { var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey); var revString = Encoding.UTF8.GetString(bytes); - MainPage.Log($"mqtt 鐘舵�佹洿鏂�:{revString}"); + //MainPage.Log($"mqtt 鐘舵�佹洿鏂�:{revString}"); Control.Ins.UpdataFunctionStatus(revString, null, true); //Control.Ins.MsgInfoList.Add($"mqtt 鐘舵�佹洿鏂�:{revString}"); //Control.Ins.MsgInfoList.Add(revString + "\r\n"); @@ -871,22 +858,8 @@ /// </summary> static void ReceiveNotifySqueezeAsync(string mMes) { -#if DEBUG - //return; -#endif + MainPage.Log($"鎺ㄩ�佹爣璇嗭細{mMes};鏈湴鏍囪瘑锛歿PushSignStr}"); if (mMes == PushSignStr) return;//鏄嚜宸辩殑鐧诲綍鎺ㄩ�佷笉澶勭悊//鎴栬�呭綋鍓嶄笉鏄繙绋嬮摼鎺ョ姸鎬� - //娴嬭瘯璐﹀彿锛屼笉鎸や笅绾� - switch (UserInfo.Current.userMobileInfo) - { - case "15626203746": - case "464027401@qq.com": - return; - } - - if (!UserInfo.Current.IsLogin) - { - return; - } DisConnectRemoteMqttClient("鎸や笅绾�"); @@ -895,44 +868,28 @@ //寮圭獥鎻愮ず琚尋涓嬬嚎 HDLCommon.Current.CheckLogout(); }); - - - //UserInfo.Current.LastTime = DateTime.MinValue; - //UserInfo.Current.SaveUserInfo(); - - //Application.RunOnMainThread(() => { - // MainPage.GoLoginPage(UserInfo.Current); - // //寮圭獥鎻愮ず琚尋涓嬬嚎 - //}); - - //2020-08-11 鍒犻櫎鎺ㄩ�佹暟鎹� - //HDLRequest.Current.PushserivceSignOut (); } - - ///// <summary> - ///// 鏀跺埌CheckGateway涓婚 - ///// </summary> - //static void ReceiveCheckGateway(string mMes) - //{ - // if (!Control.Ins.IsRemote) return; - - // Utlis.WriteLine("ReceiveCheckGateway锛�"); - - // //CheckIfNeedReadAllDeviceStatus (); - - // //var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(mMes); - // Control.Ins.GatewayOnline = true; - //} /// <summary> /// 鎺ㄩ�佹尋涓嬬嚎涓婚 /// </summary> static void SendPushSignOut() { - byte[] message = Encoding.UTF8.GetBytes(PushSignStr); #if DEBUG - MqttRemoteSend(message, 4); + MainPage.Log("璋冭瘯妯″紡锛屼笉鍙戝竷鎸や笅绾夸富棰樸��"); + return; #endif + //娴嬭瘯璐﹀彿锛屼笉鎸や笅绾� + switch (UserInfo.Current.AccountString) + { + case "15626203746": + case "13580507523": + case "18475593023": + return; + } + + byte[] message = Encoding.UTF8.GetBytes(PushSignStr); + MqttRemoteSend(message, 4); } /// <summary> @@ -958,7 +915,6 @@ break; case 4://鍙戝竷鏂版柟妗堢殑鎸や笅绾夸富棰� topicName = $"/BusGateWayToClient/{UserInfo.Current.ID}" + PushNotifySqueeze; - //message = Encoding.UTF8.GetBytes (PushSignStr); await RemoteMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topicName, Payload = message, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce }); break; } @@ -1020,7 +976,7 @@ MqttInfoConfig.Current.mMqttInfo = mqttInfoRequestResult_Obj; - await MQTTConnectAsync(); + //await MQTTConnectAsync(); //1.鍒ゆ柇鏄惁缁戝畾浜嗙綉鍏筹紝鑾峰彇缃戝叧杩滅▼杩炴帴鐨勫姞瀵咾EY //if (DB_ResidenceData.Instance.CheckWhetherGatewayIsBound()) { @@ -1187,7 +1143,7 @@ } catch (Exception ex) { - Console.WriteLine(ex.Message); + MainPage.Log(ex.Message); } return reData; } -- Gitblit v1.8.0