From a4f57bf9dda3d52e04f537a2ca24db95761eb888 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期五, 11 十二月 2020 11:34:14 +0800
Subject: [PATCH] Revert "Merge branch 'CJL-NEW' into NewFilePath"
---
HDL_ON/DAL/Server/HttpUtil.cs | 81 +++++++++++++++++++++++++++++++++++-----
1 files changed, 71 insertions(+), 10 deletions(-)
diff --git a/HDL_ON/DAL/Server/HttpUtil.cs b/HDL_ON/DAL/Server/HttpUtil.cs
index 1cca265..8335bf9 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>
@@ -538,7 +599,8 @@
//2.4 MD5杞崲+杞皬鍐�
var signstr = SignMD5Encrypt(str);
paramDictionary.Add("sign", signstr);
- return Newtonsoft.Json.JsonConvert.SerializeObject(paramDictionary);
+ var signResult = Newtonsoft.Json.JsonConvert.SerializeObject(paramDictionary);
+ return signResult;
}
else
{
@@ -551,6 +613,7 @@
}
}
+ #endregion
}
/// <summary>
@@ -586,7 +649,5 @@
}
-
-
}
--
Gitblit v1.8.0