From 326a8e72d7bb6def4147fc1e711d3cfa2aa8f4d1 Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期五, 27 十月 2023 18:33:02 +0800 Subject: [PATCH] 修复Siri Token过期无法刷新的问题 --- HDL-ON_Android/SplashActivity.cs | 8 +- HDL_ON/DAL/Server/HttpUtil.cs | 12 ++- HDL_ON/Common/OnAppConfig.cs | 16 +++++ HDL_ON/UI/UI2/FuntionControlView/EnvironmentalScience/EnvironmentalSensorPage.cs | 15 ++++ HDL_ON/DAL/Server/HttpServerRequest.cs | 14 ++++ HDL-ON_iOS/AppDelegate.cs | 7 +- SiriIntents/Server/HttpUtil.cs | 27 ++++++-- SiriKit/Data/SceneDateManager.cs | 38 +++++------- 8 files changed, 91 insertions(+), 46 deletions(-) diff --git a/HDL-ON_Android/SplashActivity.cs b/HDL-ON_Android/SplashActivity.cs index ecdc3c4..096e3b3 100644 --- a/HDL-ON_Android/SplashActivity.cs +++ b/HDL-ON_Android/SplashActivity.cs @@ -85,10 +85,10 @@ { Language.CurrentLanguage = "斜褗谢谐邪褉褋泻懈"; } - //else if (localeList.Language == "uk") - //{ - // Language.CurrentLanguage = "Ukraine"; - //} + else if (localeList.Language == "uk") + { + Language.CurrentLanguage = "Ukraine"; + } else { Language.CurrentLanguage = "English"; diff --git a/HDL-ON_iOS/AppDelegate.cs b/HDL-ON_iOS/AppDelegate.cs index 65119d7..5f5f13d 100644 --- a/HDL-ON_iOS/AppDelegate.cs +++ b/HDL-ON_iOS/AppDelegate.cs @@ -248,6 +248,7 @@ // Shared.IOS.HDLFVSDK.Video.FVapplicationDidBecomeActive(application); //} Console.WriteLine("OnActivated"); + base.OnActivated(application); //HDL_ON.DriverLayer.Control.Ins.SearchLoaclGateway(); @@ -289,9 +290,9 @@ { Language.CurrentLanguage = "Spanish"; } - //else if(NSLocale.PreferredLanguages[0].Contains("uk-")){ - // Language.CurrentLanguage = "Ukraine"; - //} + else if(NSLocale.PreferredLanguages[0].Contains("uk-")){ + Language.CurrentLanguage = "Ukraine"; + } else { Language.CurrentLanguage = "English"; diff --git a/HDL_ON/Common/OnAppConfig.cs b/HDL_ON/Common/OnAppConfig.cs index 884c037..8c86dc0 100644 --- a/HDL_ON/Common/OnAppConfig.cs +++ b/HDL_ON/Common/OnAppConfig.cs @@ -77,10 +77,24 @@ public List<UserAccount> UserList = new List<UserAccount>(); #region 鏈嶅姟鍣ㄦ暟鎹� + public string _RequestHttpsHost = "https://china.hdlcontrol.com"; /// <summary> /// 璐﹀彿娉ㄥ唽鏈嶅姟鍣ㄤ俊鎭� /// </summary> - public string RequestHttpsHost = "https://china.hdlcontrol.com"; + public string RequestHttpsHost { + get + { + return _RequestHttpsHost; + } + set + { +#if __IOS__ + var sdm = new SiriKit.SceneDateManager(); + sdm.GlobalRequestHttpsHost = value; +#endif + _RequestHttpsHost = value; + } + } /// <summary> /// /// </summary> diff --git a/HDL_ON/DAL/Server/HttpServerRequest.cs b/HDL_ON/DAL/Server/HttpServerRequest.cs index fca8e58..f6d8677 100644 --- a/HDL_ON/DAL/Server/HttpServerRequest.cs +++ b/HDL_ON/DAL/Server/HttpServerRequest.cs @@ -161,7 +161,7 @@ /// 鍒锋柊Token /// </summary> /// <returns></returns> - public string RefreshToken() + public string RefreshToken(bool canRefresh = true) { var requestJson = HttpUtil.GetSignRequestJson(new RefreshTokenObj() { @@ -187,6 +187,18 @@ { UserInfo.Current.LastTime = DateTime.MinValue; } +#if __IOS__ + else if (revertObj.Code == "10001") + { + if (canRefresh) + { + MainPage.Log($"UserInfo.Current.RefreshToken 1 : " + UserInfo.Current.RefreshToken); + UserInfo.Current.RefreshToken = SiriKit.NSUserDefaultsHelper.DataSuite.StringForKey(SiriKit.NSUserDefaultsHelper.StorageKeys.GLOBAL_GAccessToken); + MainPage.Log($"UserInfo.Current.RefreshToken 2 : " + UserInfo.Current.RefreshToken); + RefreshToken(false); + } + } +#endif return revertObj.Code; } diff --git a/HDL_ON/DAL/Server/HttpUtil.cs b/HDL_ON/DAL/Server/HttpUtil.cs index 3ca2243..0c95e74 100644 --- a/HDL_ON/DAL/Server/HttpUtil.cs +++ b/HDL_ON/DAL/Server/HttpUtil.cs @@ -4,11 +4,9 @@ using System.Net; using System.Security.Cryptography; using System.Text; -using Foundation; using HDL_ON.Entity; using RestSharp; using Shared; -using SiriKit; namespace HDL_ON.DAL.Server { @@ -212,6 +210,11 @@ } IRestResponse response = client.Execute(request); HDL_ON.Utlis.WriteLine("鍙戦��", requestFullUrl, response.Request.Body?.Value.ToString()); + if(apiPath == NewAPI.API_POST_Login) + { + var ddd = Newtonsoft.Json.JsonConvert.SerializeObject(response); + Console.WriteLine(ddd); + } if (response.StatusCode == HttpStatusCode.OK) { try @@ -304,7 +307,7 @@ /// 鍒锋柊 Token /// </summary> /// <returns></returns> - static bool RefreshToken() + static bool RefreshToken(bool canRefresh = true) { try { @@ -325,7 +328,6 @@ var sdm = new SiriKit.SceneDateManager(); sdm.AccessToken = UserInfo.Current.LoginTokenString; sdm.RefreshToken = UserInfo.Current.RefreshToken; - //var sss = NSUserDefaultsHelper.DataSuite.StringForKey(NSUserDefaultsHelper.StorageKeys.GLOBAL_GAccessToken); #endif return true; } @@ -541,7 +543,7 @@ } - #endregion +#endregion #region **********绛惧悕鏍¢獙********** diff --git a/HDL_ON/UI/UI2/FuntionControlView/EnvironmentalScience/EnvironmentalSensorPage.cs b/HDL_ON/UI/UI2/FuntionControlView/EnvironmentalScience/EnvironmentalSensorPage.cs index a10b239..7661e18 100644 --- a/HDL_ON/UI/UI2/FuntionControlView/EnvironmentalScience/EnvironmentalSensorPage.cs +++ b/HDL_ON/UI/UI2/FuntionControlView/EnvironmentalScience/EnvironmentalSensorPage.cs @@ -661,12 +661,14 @@ { new System.Threading.Thread(() => { + foreach (var tempSensor in sensorList) { if (index >= 6) { break; } + if (tempSensor.sid == function.sid) { continue; @@ -729,7 +731,7 @@ TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.TextFontSize, - Text = function.name, + Text = tempSensor.name, IsBold = true, }; otherInfoView.AddChidren(btnSensorName); @@ -824,6 +826,12 @@ }); System.Threading.Thread.Sleep(50); } + Application.RunOnMainThread(() => { + if (index > 1) + { + contentView.ScrollEnabled = true; + } + }); }).Start(); } catch(Exception ex) @@ -836,6 +844,7 @@ LoadMothed_GetSensorHistoryData(); LoadEvent_ChangeSensorHistoryShowType(); } + } @@ -900,7 +909,7 @@ } ebl.InitXdataText(vs); } - yDataString += ebl.InitYdataText(sr.name, revertData, tipColorStringList[i]); + yDataString += ebl.InitYdataText("", revertData, tipColorStringList[i]); } } i++; @@ -909,6 +918,8 @@ Application.RunOnMainThread(() => { + ebl.xTitle = ""; + ebl.yTitle = ""; myEchartsView.ShowWithOption(ebl.InitOption()); }); diff --git a/SiriIntents/Server/HttpUtil.cs b/SiriIntents/Server/HttpUtil.cs index dc7aca0..24eaa6c 100644 --- a/SiriIntents/Server/HttpUtil.cs +++ b/SiriIntents/Server/HttpUtil.cs @@ -16,13 +16,14 @@ /// 鍥哄畾鍩熷悕,姝e紡鐜 /// 鍏叡鍩熷悕灏辫繎瑙f瀽 /// </summary> - //public const string GlobalRequestHttpsHost = "https://nearest.hdlcontrol.com"; - public const string GlobalRequestHttpsHost = "https://test-gz.hdlcontrol.com"; + public const string GlobalRequestHttpsHost = "https://nearest.hdlcontrol.com"; + //public const string GlobalRequestHttpsHost = "https://test-gz.hdlcontrol.com"; const string APP_KEY = "HDL-HOME-APP-TEST"; const string SECRET_KEY = "WeJ8TY88vbakCcnvH8G1tDUqzLWY8yss"; //public const string GlobalRequestHttpsHost = "http://59.41.255.150:7777";//mmmm //const string APP_KEY = "CPEVRLRT"; //const string SECRET_KEY = "CPEVRLSJCPEVRLSZ"; + /// <summary> /// RegionMark /// </summary> @@ -35,9 +36,9 @@ /// 鐗规畩鎺ュ彛璇锋眰瓒呮椂鏃堕棿 /// </summary> public const int TIME_OUT_LONG = 20; - /////// <summary> - /////// Bearer 鏆傛椂璁句负绌猴紝浠庣櫥闄嗘垚鍔熺殑杩斿洖鐨刪eaderPrefix鍙傛暟鍔ㄦ�佽幏鍙� - /////// </summary> + /// <summary> + /// Bearer 鏆傛椂璁句负绌猴紝浠庣櫥闄嗘垚鍔熺殑杩斿洖鐨刪eaderPrefix鍙傛暟鍔ㄦ�佽幏鍙� + /// </summary> //public const string TOKEN_BEARER = "Bearer "; #endregion @@ -114,6 +115,15 @@ try { + + if (string.IsNullOrEmpty(urlHead)) + { + urlHead = HttpServerRequest.Ins.DataManager.GlobalRequestHttpsHost; + if (string.IsNullOrEmpty(urlHead)) + { + urlHead = "https://nearest.hdlcontrol.com"; + } + } string requestFullUrl = urlHead + apiPath; @@ -122,9 +132,10 @@ RestRequest request = new RestRequest(method); request.Timeout = mTimeout * 1000; request.AddHeader("content-type", "application/json"); + request.AddHeader("language", "cn"); request.AddHeader("Authorization", HttpServerRequest.Ins.DataManager.AccessToken); - + if (bodyParameterJson != null) { request.AddParameter("application/json", bodyParameterJson, ParameterType.RequestBody); @@ -174,6 +185,8 @@ } else { + var ddd =Newtonsoft.Json.JsonConvert.SerializeObject(response); + return new ResponsePackNew() { Code = StateCode.NETWORK_ERROR }; } @@ -204,7 +217,7 @@ { var responsePackNew = RequestHttpsBase(method, apiPath, bodyParameterJson, queryDictionary, urlSegmentDictionary, urlHead, replaceToken, mTimeout); //*****************Token杩囨湡澶勭悊***************** - if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED ) { //鍒锋柊Token if (RefreshToken()) { diff --git a/SiriKit/Data/SceneDateManager.cs b/SiriKit/Data/SceneDateManager.cs index 9ff58b3..01f1d1c 100644 --- a/SiriKit/Data/SceneDateManager.cs +++ b/SiriKit/Data/SceneDateManager.cs @@ -10,29 +10,6 @@ public SceneDateManager() { }//: base(new UserDefaultsStorageDescriptor(NSUserDefaultsHelper.StorageKeys.OrderHistory), new NSMutableArray<HDLSceneSiri.HDLSiriSceneModel>()) { } protected NSUserDefaults UserDefaults = NSUserDefaultsHelper.DataSuite; - - //#region Public API for clients of `SoupOrderDataManager` - //// Convenience method to access the data with a property name that makes - //// sense in the caller's context. - //public NSMutableArray<HDLSceneSiri.HDLSiriSceneModel> OrderHistory - //{ - // get - // { - // return ManagedData as NSMutableArray<HDLSceneSiri.HDLSiriSceneModel>; - // } - //} - - //#endregion - - //#region Support methods for unarchiving saved data - //override protected void FinishUnarchiving(NSObject unarchivedData) - //{ - // var array = (NSArray)unarchivedData; - // HDLSceneSiri.HDLSiriSceneModel[] orders = NSArray.FromArray<HDLSceneSiri.HDLSiriSceneModel>(array); - // ManagedDataBackingInstance = new NSMutableArray<HDLSceneSiri.HDLSiriSceneModel>(orders); - //} - //#endregion - public bool IsLgoin { get @@ -100,5 +77,20 @@ UserDefaults.SetString(value, NSUserDefaultsHelper.StorageKeys.GLOBAL_GHomeId); } } + + public string GlobalRequestHttpsHost + { + get + { + var d = UserDefaults.StringForKey("GlobalRequestHttpsHost"); + return d; + } + set + { + UserDefaults.SetString(value, "GlobalRequestHttpsHost"); + } + } + + } } -- Gitblit v1.8.0