From aef56e88ed1faeaa221f36b462a1120d7960e2fa Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 22 十二月 2020 15:09:01 +0800
Subject: [PATCH] 2020-12-22-4
---
HDL_ON/DAL/Server/HttpUtil.cs | 89 +++++++++++++++++++++++++++++++++++++-------
1 files changed, 75 insertions(+), 14 deletions(-)
diff --git a/HDL_ON/DAL/Server/HttpUtil.cs b/HDL_ON/DAL/Server/HttpUtil.cs
index 1cca265..512e33b 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>
@@ -94,7 +95,7 @@
/// <returns></returns>
public static ResponsePackNew RequestHttpsPostFroHome(string apiPath, string bodyParameterJson, int mTimeout = 10)
{
- string urlHead = DB_ResidenceData.residenceData.residecenInfo.regionUrl;
+ string urlHead = DB_ResidenceData.Instance.CurrentRegion.regionUrl;
//var replaceToken = "";
//if (DB_ResidenceData.residenceData.residecenInfo.IsOthreShare)
//{
@@ -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
@@ -153,7 +154,7 @@
if (string.IsNullOrEmpty(urlHead))
{
- urlHead = UserInfo.Current.RequestHttpsHost;
+ urlHead = OnAppConfig.Instance.RequestHttpsHost;
}
string requestFullUrl = urlHead + apiPath;
@@ -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)
@@ -250,6 +247,69 @@
}
/// <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>
/// 涓嬭浇鏂囦欢 璇锋眰鏈嶅姟鍣ㄦ柟娉�
/// </summary>
/// <param name="apiPath"></param>
@@ -266,7 +326,7 @@
{
if (string.IsNullOrEmpty(urlHead))
{
- urlHead = UserInfo.Current.RequestHttpsHost;
+ urlHead = OnAppConfig.Instance.RequestHttpsHost;
}
string requestFullUrl = urlHead + apiPath;
@@ -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");
@@ -337,7 +396,7 @@
if (string.IsNullOrEmpty(urlHead))
{
- urlHead = UserInfo.Current.RequestHttpsHost;
+ urlHead = OnAppConfig.Instance.RequestHttpsHost;
}
string requestFullUrl = urlHead + apiPath;
@@ -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