From dc840e2d67654781ebc9c7640e6c44a63a6d04d0 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期五, 11 十二月 2020 09:44:37 +0800 Subject: [PATCH] 2020-12-11 1.注册、忘记密码、重置密码、点击返回到时候屏蔽检测错误提示。底部按钮使能效果优化修改。邮箱变密码输入问题修复。2.网络请求底层增加token过期检测刷新方法。3.更新控件库,iOS EditText取消默认密码输入方式。 --- HDL_ON/DAL/Server/HttpUtil.cs | 78 ++++++++++++++++++++++++++++++++++---- 1 files changed, 69 insertions(+), 9 deletions(-) diff --git a/HDL_ON/DAL/Server/HttpUtil.cs b/HDL_ON/DAL/Server/HttpUtil.cs index 1cca265..3b85363 100644 --- a/HDL_ON/DAL/Server/HttpUtil.cs +++ b/HDL_ON/DAL/Server/HttpUtil.cs @@ -12,7 +12,7 @@ public class HttpUtil { - #region HttpUtil 鍏ㄥ眬甯搁噺 + #region **********鍏ㄥ眬甯搁噺********** ///// <summary> ///// API_HTTPS ///// </summary> @@ -36,6 +36,7 @@ #endregion + #region **********缃戠粶璇锋眰灏佽********** /// <summary> /// 鍥哄畾鍩熷悕,姝e紡鐜 /// </summary> @@ -145,7 +146,7 @@ /// <param name="replaceToken"></param> /// <param name="mTimeout"></param> /// <returns></returns> - public static ResponsePackNew RequestHttps(Method method, string apiPath, string bodyParameterJson = null, Dictionary<string, object> queryDictionary = null, Dictionary<string, object> urlSegmentDictionary = null, string urlHead = "", string replaceToken = "", int mTimeout = 10) + static ResponsePackNew RequestHttpsBase(Method method, string apiPath, string bodyParameterJson = null, Dictionary<string, object> queryDictionary = null, Dictionary<string, object> urlSegmentDictionary = null, string urlHead = "", string replaceToken = "", int mTimeout = 10) { #region HttpWebRequest try @@ -167,7 +168,6 @@ RestRequest request = new RestRequest(method); request.Timeout = mTimeout * 1000; request.AddHeader("content-type", "application/json"); - //request.AddHeader ("cache-control", "no-cache"); if (string.IsNullOrEmpty(replaceToken)) { @@ -207,7 +207,6 @@ { try { - ResponsePackNew revertObj = new ResponsePackNew() { }; revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePackNew>(response.Content); //*****涓�浜涘垽绌哄鐞�***************** @@ -222,8 +221,6 @@ } //*****涓�浜涘垽绌哄鐞�***************** - ////缁熶竴杞垚澶у啓 - //revertObj.StateCode = revertObj.StateCode.ToUpper (); return revertObj; } catch (Exception ex) @@ -247,6 +244,69 @@ #endregion + } + + /// <summary> + /// 閫氱敤 璇锋眰鏈嶅姟鍣ㄦ柟娉� + /// 澧炲姞token杩囨湡澶勭悊 + /// </summary> + /// <param name="method"></param> + /// <param name="apiPath"></param> + /// <param name="bodyParameterJson"></param> + /// <param name="queryDictionary"></param> + /// <param name="urlSegmentDictionary"></param> + /// <param name="urlHead"></param> + /// <param name="replaceToken"></param> + /// <param name="mTimeout"></param> + /// <returns></returns> + public static ResponsePackNew RequestHttps(Method method, string apiPath, string bodyParameterJson = null, Dictionary<string, object> queryDictionary = null, Dictionary<string, object> urlSegmentDictionary = null, string urlHead = "", string replaceToken = "", int mTimeout = 10) + { + var responsePackNew = RequestHttpsBase(method, apiPath, bodyParameterJson, queryDictionary, urlSegmentDictionary, urlHead, replaceToken, mTimeout); + //*****************Token杩囨湡澶勭悊***************** + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + //鍒锋柊Token + if (RefreshToken()) { + return RequestHttpsBase(method, apiPath, bodyParameterJson, queryDictionary, urlSegmentDictionary, urlHead, replaceToken, mTimeout); + } + else + { + return responsePackNew; + } + } + //*****************Token杩囨湡澶勭悊***************** + return responsePackNew; + } + + + /// <summary> + /// 鍒锋柊Token + /// </summary> + /// <returns></returns> + static bool RefreshToken() + { + try + { + var requestJson = GetSignRequestJson(new RefreshTokenObj() + { + refreshToken = UserInfo.Current.RefreshToken, + }); + var revertObj = RequestHttpsBase(Method.POST, NewAPI.API_POST_Login, requestJson); + if (revertObj.Code == StateCode.SUCCESS) + { + var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes>(revertObj.Data.ToString()); + UserInfo.Current.LoginTokenString = revertData.headerPrefix + revertData.accessToken; + UserInfo.Current.RefreshToken = revertData.refreshToken; + UserInfo.Current.LastTime = DateTime.Now; + UserInfo.Current.SaveUserInfo(); + return true; + } + return false; + } + catch + { + return false; + } } /// <summary> @@ -275,7 +335,6 @@ ////**************娴嬭瘯************** RestClient client = new RestClient(requestFullUrl); - //client.Timeout = mTimeout * 1000; RestRequest request = new RestRequest(Method.POST); request.Timeout = mTimeout * 1000; request.AddHeader("content-type", "application/json"); @@ -454,7 +513,9 @@ } + #endregion + #region **********绛惧悕鏍¢獙********** /// <summary> /// /// </summary> @@ -551,6 +612,7 @@ } } + #endregion } /// <summary> @@ -586,7 +648,5 @@ } - - } -- Gitblit v1.8.0