Beispiel #1
0
 /// <summary>
 /// 发送短信验证码
 /// </summary>
 /// <param name="phone">手机号码</param>
 /// <param name="phoneCode">验证码</param>
 /// <returns></returns>
 public async Task HttpPostPhoneCodeAsync(string clientIp, string phone, string phoneCode)
 {
     await Task.Run(() =>
     {
         try
         {
             var paramsList = new Dictionary <string, string>();
             paramsList.Add("mob", phone);
             paramsList.Add("msg", string.Format(ConfigHelp.ConfigObject["phoneCodeMessage"].ToString(), phoneCode));
             paramsList.Add("pswd", ConfigHelp.ConfigObject["messagePostPswd"].ToString());
             var headList = new Dictionary <string, string>();
             headList.Add("clientIPAddr", clientIp);
             headList.Add("requestAccount", ConfigHelp.ConfigObject["messagePostAccount"].ToString());
             HttpHelper.GetResponseString(HttpHelper.CreatePostHttpResponse(
                                              ConfigHelp.ConfigObject["messagePostUrlPath"].ToString(), paramsList, headList, 300,
                                              string.Empty,
                                              null));
             HttpSendLog.InfoLogAsync(
                 "HttpSendCode HttpPostPhoneCodeAsync run success! clientIp:{0} phone:{1} phoneCode:{2} ",
                 clientIp, phone, phoneCode);
         }
         catch (Exception e)
         {
             HttpSendLog.ErrorLogAsync(
                 "HttpSendCode HttpPostPhoneCodeAsync run success! clientIp:{0} phone:{1} phoneCode:{2} err:{3}",
                 clientIp, phone, phoneCode, e);
         }
     });
 }
Beispiel #2
0
        /// <summary>
        /// 入口拦截器
        /// create by gloomy 2017-12-20 17:06:40
        /// </summary>
        /// <param name="context">请求对象</param>
        private void AuthenExecuting(ActionExecutingContext context)
        {
            if (!NoFilterHelper.IssureFilter <NoAuthenFilterAttribute>(context))
            {
                var resultModel    = new ResponeStruct();
                var controllerName = context.ActionDescriptor.RouteValues["controller"];
                var actionName     = context.ActionDescriptor.RouteValues["action"];
                var userAuthen     = context.HttpContext.Request.Cookies[ConfigHelp.ConfigObject["saveUserCookieName"].ToString()];
                var clientIp       = HttpClientIp.GetMyClientIp(context.HttpContext.Request);

                if (userAuthen != null)
                {
                    var decUserAuthen   = new StringAesDes().Decrypt(userAuthen, ConfigHelp.ConfigObject["authenEncryptionKey"].ToString());
                    var userAuthenArray = decUserAuthen.Split(':');
                    if (userAuthenArray.Length == 2 && userAuthenArray[1] == clientIp)
                    {
                        //成功
                    }
                    resultModel.resultCode = ResultCode.ILLEGAL_IDENTITY_REQUEST;
                }
                else
                {
                    resultModel.resultCode = ResultCode.NOT_LOGIN;
                }
                context.HttpContext.Response.Redirect("/");

                HttpSendLog.ErrorLogAsync("ApiAuthenFilterAttribute AuthenExecuting controller:{0} action:{1} clientIp:{2} phone:{3} ",
                                          controllerName, actionName, clientIp);

                //直接出去
                context.Result = AuthenResult(resultModel);
            }
        }
Beispiel #3
0
 public static void SetRedisNoAsync(string saveKey, string saveValue, int saveTimeLong)
 {
     try
     {
         var timeNow = DateTime.Now;
         var db      = redis.GetDatabase(Convert.ToInt32(ConfigHelp.ConfigObject["redisDatabase"].ToString()));
         db.StringSet(saveKey, saveValue, timeNow.AddSeconds(saveTimeLong) - timeNow);
     }
     catch (Exception e)
     {
         HttpSendLog.ErrorLogAsync("RedisProcess SetRedis run err! saveKey:{0} saveValue:{1} err: {2}",
                                   saveKey,
                                   saveValue, e);
     }
 }
Beispiel #4
0
        /// <summary>
        /// 获取redis存储值
        /// </summary>
        /// <param name="saveKey">存储的键</param>
        /// <returns></returns>
        public static string GetRedis(string saveKey)
        {
            var redisSaveValue = string.Empty;

            try
            {
                var db = redis.GetDatabase(Convert.ToInt32(ConfigHelp.ConfigObject["redisDatabase"].ToString()));
                redisSaveValue = db.StringGet(saveKey);
            }
            catch (Exception e)
            {
                HttpSendLog.ErrorLogAsync("RedisProcess GetRedis run err! saveKey:{0} err: {2}", saveKey, e);
            }

            return(redisSaveValue ?? string.Empty);
        }
Beispiel #5
0
        public override void OnException(ExceptionContext context)
        {
            Console.WriteLine(context.Exception.ToString());
            if (!Convert.ToBoolean(ConfigHelp.ConfigObject["isWriteLog"].ToString()))
            {
                context.ExceptionHandled = true; // mark exception as handled
            }

            HttpSendLog.ErrorLogAsync(
                "UiExceptionFilterAttribute OnException! httpReuqstUrl:{0} method:{1} {2} {3} err:{4}",
                context.HttpContext.Request.GetDisplayUrl(), context.HttpContext.Request.Method,
                context.HttpContext.Request.Form.Aggregate("requestForm:",
                                                           (current, item) => string.Format("{0} {1}:{2}", current, item.Key, item.Value)),
                context.RouteData.Values.Aggregate("RouteData:",
                                                   (current, item) => string.Format("{0} {1}:{2}", current, item.Key, item.Value)),
                context.Exception.ToString());



            context.Result = AuthenResult(new ResponeStruct
            {
                resultCode = ResultCode.SYSTEM_ERROR
            });
        }