Exemplo n.º 1
0
        /// <summary>
        /// 获取结果(Post方式)
        /// </summary>
        /// <returns></returns>
        public static ResultModel Post(string url, string post, string resultKey = null, string errorKey = null)
        {
            JObject postObj = null;

            if (!VerifyHelper.IsEmpty(post))
            {
                postObj = JsonHelper.Deserialize <JObject>(post);
            }
            if (VerifyHelper.IsNull(postObj))
            {
                postObj = new JObject();
            }

            //公共post参数
            postObj["AppId"]    = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyAppId);
            postObj["ClientId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyClientId);
            postObj["Version"]  = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyVersion);
            postObj["ip"]       = BrowserHelper.GetClientIP();

            var passport = postObj.GetValue("passport", StringComparison.InvariantCultureIgnoreCase);

            if (VerifyHelper.IsNull(passport))
            {
                passport = GetTempUserPassport();
            }
            postObj["passport"] = passport;
            //postObj["culture"] = CommonHelper.GetContext().Culture;
            //postObj["security"] = "1xxxx";
            return(Request(url, JsonHelper.Serialize(postObj), resultKey: resultKey, errorKey: errorKey));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取临时用户登录Passport
        /// </summary>
        /// <returns></returns>
        protected static JObject GetTempUser()
        {
            var tempUser = CachingHelper <HttpRuntimeCaching> .Get <JObject>(KeyModel.Cache.DataCenterTempUser);

            if (VerifyHelper.IsEmpty(tempUser))
            {
                var tempUserAccount = StringHelper.Get(DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyApiTempUser)).Split('|');
                if (VerifyHelper.IsEmpty(tempUserAccount))
                {
                    throw new DefaultException("数据中心TempUser配置错误");
                }

                var data = new JObject();
                data["AppId"]    = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyAppId);
                data["ClientId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyClientId);
                data["Version"]  = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyVersion);
                data["ip"]       = BrowserHelper.GetClientIP();
                data["Account"]  = tempUserAccount.Length > 0 ? tempUserAccount[0] : "";
                data["Password"] = tempUserAccount.Length > 1 ? tempUserAccount[1] : "";

                var result = Request(DataCenterConfig.GetApiUrl(KeyModel.Config.DataCenter.KeyAccountLogin), JsonHelper.Serialize(data), resultKey: null, errorKey: null);
                if (result.Code == EnumHelper.GetValue(EnumResultCode.操作成功) && !VerifyHelper.IsEmpty(result.Obj))
                {
                    tempUser = result.Obj;
                }
            }
            return(VerifyHelper.IsEmpty(tempUser) ? new JObject() : tempUser);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 写请求数据中心日志
        /// </summary>
        protected static void WriteLog()
        {
            bool isWriteLog = BoolHelper.Get(DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyWriteLog));

            //if (BoolHelper.Get(SysModelConfigs.ApiLog.GetSysModelValue()))
            //{
            //    Log4NetHelper.Get(EnumHelper.GetName(EnumLogType.ApiLog)).WriteLogAsync(string.Format("--[Request]--\r\n{0}\r\n--[Response]--\r\n{1}\r\n", JsonHelper.Serialize(item), httpResult.Html));
            //}
        }