From efad979b6fae76fb37a4de7e94e6bac0a85cb72c Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期二, 30 十一月 2021 13:14:28 +0800 Subject: [PATCH] 2021-11-30 1.修复乐橙Android,没调用拒接接口问题。 --- HDL_ON/DAL/Server/HttpUtil.cs | 80 +++++++++++++++++++++++---------------- 1 files changed, 47 insertions(+), 33 deletions(-) diff --git a/HDL_ON/DAL/Server/HttpUtil.cs b/HDL_ON/DAL/Server/HttpUtil.cs index d6422ae..cf4a06a 100644 --- a/HDL_ON/DAL/Server/HttpUtil.cs +++ b/HDL_ON/DAL/Server/HttpUtil.cs @@ -13,10 +13,12 @@ { #region **********鍏ㄥ眬甯搁噺********** - ///// <summary> - ///// API_HTTPS - ///// </summary> - //public const string API_HTTPS = "https://"; + /// <summary> + /// 鍥哄畾鍩熷悕,姝e紡鐜 + /// 鍏叡鍩熷悕灏辫繎瑙f瀽 + /// </summary> + //public const string GlobalRequestHttpsHost = "https://nearest.hdlcontrol.com"; + public const string GlobalRequestHttpsHost = "https://test-gz.hdlcontrol.com";//mmmm /// <summary> /// RegionMark /// </summary> @@ -24,7 +26,7 @@ /// <summary> /// 璇锋眰瓒呮椂鏃堕棿 /// </summary> - public const int TIME_OUT = 10; + public const int TIME_OUT = 15; /// <summary> /// 鐗规畩鎺ュ彛璇锋眰瓒呮椂鏃堕棿 /// </summary> @@ -37,12 +39,6 @@ #endregion #region **********缃戠粶璇锋眰灏佽********** - /// <summary> - /// 鍥哄畾鍩熷悕,姝e紡鐜 - /// 鍏叡鍩熷悕灏辫繎瑙f瀽 - /// </summary> - //public const string GlobalRequestHttpsHost = "https://nearest.hdlcontrol.com"; - public const string GlobalRequestHttpsHost = "https://test-gz.hdlcontrol.com"; /// <summary> /// Get 璇锋眰鏈嶅姟鍣ㄦ柟娉� @@ -54,7 +50,7 @@ /// <param name="replaceToken"></param> /// <param name="mTimeout"></param> /// <returns></returns> - public static ResponsePackNew RequestHttpsGet(string apiPath, Dictionary<string, object> queryDictionary = null, Dictionary<string, object> urlSegmentDictionary = null, string urlHead = "", string replaceToken = "", int mTimeout = 10) + public static ResponsePackNew RequestHttpsGet(string apiPath, Dictionary<string, object> queryDictionary = null, Dictionary<string, object> urlSegmentDictionary = null, string urlHead = "", string replaceToken = "", int mTimeout = TIME_OUT) { return RequestHttps(Method.GET, apiPath, null, queryDictionary, urlSegmentDictionary, urlHead, replaceToken, mTimeout); } @@ -71,7 +67,7 @@ ///// <param name="mTimeout">璇锋眰瓒呮椂鏃堕棿锛岄粯璁�10</param> ///// <param name="urlHead"></param> ///// <returns></returns> - //public 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, bool needErrorTip = true) + //public 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 = TIME_OUT, bool needErrorTip = true) //{ // var mResponsePackNew = RequestHttps(method, apiPath, bodyParameterJson, queryDictionary, urlSegmentDictionary, urlHead, replaceToken, mTimeout); // if (needErrorTip) @@ -94,7 +90,7 @@ /// <param name="bodyParameterJson"></param> /// <param name="mTimeout"></param> /// <returns></returns> - public static ResponsePackNew RequestHttpsPostFroHome(string apiPath, string bodyParameterJson, int mTimeout = 10) + public static ResponsePackNew RequestHttpsPostFroHome(string apiPath, string bodyParameterJson, int mTimeout = TIME_OUT) { string urlHead = DB_ResidenceData.Instance.CurrentRegion.regionUrl; //var replaceToken = ""; @@ -115,7 +111,7 @@ /// <param name="replaceToken"></param> /// <param name="mTimeout"></param> /// <returns></returns> - public static ResponsePackNew RequestHttpsPost(string apiPath, string bodyParameterJson, string urlHead = "", string replaceToken = "", int mTimeout = 10) + public static ResponsePackNew RequestHttpsPost(string apiPath, string bodyParameterJson, string urlHead = "", string replaceToken = "", int mTimeout = TIME_OUT) { return RequestHttps(Method.POST, apiPath, bodyParameterJson, null, null, urlHead, replaceToken, mTimeout); } @@ -130,7 +126,7 @@ /// <param name="replaceToken"></param> /// <param name="mTimeout"></param> /// <returns></returns> - public static ResponsePackNew RequestHttpsPost(string apiPath, Dictionary<string, object> queryDictionary, string urlHead = "", string replaceToken = "", int mTimeout = 10) + public static ResponsePackNew RequestHttpsPost(string apiPath, Dictionary<string, object> queryDictionary, string urlHead = "", string replaceToken = "", int mTimeout = TIME_OUT) { return RequestHttps(Method.POST, apiPath, null, queryDictionary, null, urlHead, replaceToken, mTimeout); } @@ -147,8 +143,14 @@ /// <param name="replaceToken"></param> /// <param name="mTimeout"></param> /// <returns></returns> - 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) + 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 = TIME_OUT) { + //Dome妯″紡鐧诲綍 + + if(MainPage.NoLoginMode) + { + return new ResponsePackNew() { Code = "0" }; + } #region HttpWebRequest try { @@ -159,10 +161,6 @@ } string requestFullUrl = urlHead + apiPath; - - ////**************娴嬭瘯************** - //string requestFullUrl = GlobalRequestHttpsHost + apiPath; - ////**************娴嬭瘯************** RestClient client = new RestClient(requestFullUrl); @@ -260,7 +258,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) + 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 = TIME_OUT) { var responsePackNew = RequestHttpsBase(method, apiPath, bodyParameterJson, queryDictionary, urlSegmentDictionary, urlHead, replaceToken, mTimeout); //*****************Token杩囨湡澶勭悊***************** @@ -281,7 +279,7 @@ /// <summary> - /// 鍒锋柊Token + /// 鍒锋柊 Token /// </summary> /// <returns></returns> static bool RefreshToken() @@ -330,10 +328,6 @@ urlHead = OnAppConfig.Instance.RequestHttpsHost; } string requestFullUrl = urlHead + apiPath; - - ////**************娴嬭瘯************** - //string requestFullUrl = GlobalRequestHttpsHost + apiPath; - ////**************娴嬭瘯************** RestClient client = new RestClient(requestFullUrl); RestRequest request = new RestRequest(Method.POST); @@ -389,7 +383,7 @@ /// <param name="replaceToken"></param> /// <param name="mTimeout"></param> /// <returns></returns> - public static ResponsePackNew RequestHttpsUpload(Method method, string apiPath, object bodyParameterObject = null, Dictionary<string, object> queryDictionary = null, Dictionary<string, object> urlSegmentDictionary = null, string urlHead = "", string replaceToken = "", int mTimeout = 10) + public static ResponsePackNew RequestHttpsUpload(Method method, string apiPath, object bodyParameterObject = null, Dictionary<string, object> queryDictionary = null, Dictionary<string, object> urlSegmentDictionary = null, string urlHead = "", string replaceToken = "", int mTimeout = TIME_OUT) { #region HttpWebRequest try @@ -552,19 +546,36 @@ } return signstr.ToLower(); } - + /// <summary> + /// 鍒ゆ柇褰撳墠鍊兼槸鍚﹂渶瑕佸弬涓庣鍚嶏紝淇濇寔璺熶簯绔竴鑷� + /// 绌哄瓧绗︿覆涓嶅弬涓� + /// 鏁扮粍,闆嗗悎,瀵硅薄涓嶅弬涓� + /// </summary> + /// <param name="valueStr"></param> + /// <returns></returns> + static bool IfValueNeedSign(string valueStr) + { + if (string.IsNullOrEmpty(valueStr) || valueStr.StartsWith("{") || valueStr.StartsWith("[")) + { + return false; + } + return true; + } /// <summary> /// 2020-11-02 /// 鍩虹鏈嶅姟鐨勬帴鍙i兘瑕佹牎楠宻ign /// 璁$畻sign绛惧悕 /// </summary> /// <returns></returns> - public static string GetSignRequestJson(object requestObj) + public static string GetSignRequestJson(object requestObj,Dictionary<string,object> paramDictionary = null) { try { //1. 灏唌odel瀹炰綋杞负Dictionary<string, object> - var paramDictionary = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(Newtonsoft.Json.JsonConvert.SerializeObject(requestObj)); + if (paramDictionary == null) + { + paramDictionary = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(Newtonsoft.Json.JsonConvert.SerializeObject(requestObj)); + } //2. 璁$畻sign if (paramDictionary != null) { @@ -580,7 +591,10 @@ if (item.Value != null) { //Value.ToString()涓簄ull鎴栬��""涔熶笉鍙傚姞鏍¢獙 - if (!string.IsNullOrEmpty(item.Value.ToString())) + //if (!string.IsNullOrEmpty(item.Value.ToString()) && (item.Value is string || item.Value.GetType().IsValueType)) + //{ + //妫�娴嬪綋鍓嶅弬鏁版槸鍚﹂渶瑕佸弬涓庢牎楠� + if (IfValueNeedSign(item.Value.ToString())) { //濡傛灉鏄痓ool绫诲瀷锛岃杞皬鍐� if (item.Value is bool) @@ -636,7 +650,7 @@ /// <summary> /// 鍝嶅簲閿欒淇℃伅 /// </summary> - public string message; + public string message = ""; /// <summary> /// 杩欎釜鏄姹傞敊璇椂鐨勬墿灞曟暟鎹�,浠ュ悗鎵�鏈夌殑闄勫甫鎵╁睍鏁版嵁閮戒細鏀惧湪杩欓噷闈㈠姩鎬佺淮鎶� -- Gitblit v1.8.0