wxr
2021-07-01 b409ece9569247d7e7b44fc15e8a02556ca05a57
HDL_ON/DAL/Server/HttpUtil.cs
@@ -13,10 +13,13 @@
    {
        #region **********全局常量**********
        ///// <summary>
        ///// API_HTTPS
        ///// </summary>
        //public const string API_HTTPS = "https://";
        /// <summary>
        /// 固定域名,正式环境
        /// 公共域名就近解析
        ///
        /// </summary>
        //public const string GlobalRequestHttpsHost = "https://nearest.hdlcontrol.com";
        public const string GlobalRequestHttpsHost = "https://test-gz.hdlcontrol.com";//mmmm
        /// <summary>
        /// RegionMark
        /// </summary>
@@ -37,11 +40,6 @@
        #endregion
        #region **********网络请求封装**********
        /// <summary>
        /// 固定域名,正式环境
        /// </summary>
        //public const string GlobalRequestHttpsHost = "https://nearest.hdlcontrol.com";
        public const string GlobalRequestHttpsHost = "https://test-gz.hdlcontrol.com";
        /// <summary>
        ///  Get  请求服务器方法
@@ -148,6 +146,12 @@
        /// <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)
        {
            //Dome模式登录
            if(MainPage.NoLoginMode)
            {
                return new ResponsePackNew() { Code = "0" };
            }
            #region HttpWebRequest
            try
            {
@@ -212,7 +216,7 @@
                        //*****一些判空处理*****************
                        if (revertObj.Code == null)
                        {
                            revertObj.Code = "DATA_EXCEPTION";
                            revertObj.Code = StateCode.DATA_EXCEPTION;
                        }
                        if (revertObj.Data == null)
@@ -226,20 +230,20 @@
                    catch (Exception ex)
                    {
                        HDL_ON.Utlis.WriteLine(ex.Message);
                        return new ResponsePackNew() { Code = "DATA_EXCEPTION" };
                        return new ResponsePackNew() { Code = StateCode.DATA_EXCEPTION };
                    }
                }
                else
                {
                    HDL_ON.Utlis.WriteLine(response.Content);
                    return new ResponsePackNew() { Code = "NETWORK_ERROR" };
                    return new ResponsePackNew() { Code = StateCode.NETWORK_ERROR };
                }
            }
            catch (Exception ex)
            {
                HDL_ON.Utlis.WriteLine(ex.Message);
                return new ResponsePackNew() { Code = "NETWORK_ERROR" };
                return new ResponsePackNew() { Code = StateCode.NETWORK_ERROR };
            }
            #endregion
@@ -453,7 +457,7 @@
                        revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePackNew>(response.Content);
                        if (revertObj.Code == null)
                        {
                            revertObj.Code = "DATA_EXCEPTION";
                            revertObj.Code = StateCode.DATA_EXCEPTION;
                        }
                        ////统一转成大写
                        //revertObj.StateCode = revertObj.StateCode.ToUpper ();
@@ -462,20 +466,20 @@
                    catch (Exception ex)
                    {
                        HDL_ON.Utlis.WriteLine(ex.Message);
                        return new ResponsePackNew() { Code = "DATA_EXCEPTION" };
                        return new ResponsePackNew() { Code = StateCode.DATA_EXCEPTION };
                    }
                }
                else
                {
                    HDL_ON.Utlis.WriteLine(response.Content);
                    return new ResponsePackNew() { Code = "NETWORK_ERROR" };
                    return new ResponsePackNew() { Code = StateCode.NETWORK_ERROR };
                }
            }
            catch (Exception ex)
            {
                HDL_ON.Utlis.WriteLine(ex.Message);
                return new ResponsePackNew() { Code = "NETWORK_ERROR" };
                return new ResponsePackNew() { Code = StateCode.NETWORK_ERROR };
            }
            #endregion
@@ -551,19 +555,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
        /// 基础服务的接口都要校验sign
        /// 计算sign签名
        /// </summary>
        /// <returns></returns>
        public static string GetSignRequestJson(object requestObj)
        public static string GetSignRequestJson(object requestObj,Dictionary<string,object> paramDictionary = null)
        {
            try
            {
                //1. 将model实体转为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)
                {
@@ -579,7 +600,10 @@
                        if (item.Value != null)
                        {
                            //Value.ToString()为null或者""也不参加校验
                            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()))
                            {
                                //如果是bool类型,要转小写
                                if (item.Value is bool)
@@ -637,6 +661,11 @@
        /// </summary>
        public string message;
        /// <summary>
        /// 这个是请求错误时的扩展数据,以后所有的附带扩展数据都会放在这里面动态维护
        /// </summary>
        public object extra;
        ///// <summary>
        ///// isSuccess
        ///// </summary>