示例#1
0
        /// <summary>
        /// 获取用户的游戏状态
        /// </summary>
        /// <param name="key">UserID</param>
        /// <returns></returns>
        public GameInfo GetGameData(string key)
        {
            var data = new GameInfo();

            try
            {
                //首先从服务端缓存获取
                data = CacheExts <GameInfo> .GetValue(key);

                if (data == null)
                {
                    //缓存不存在,则读取用户本地Cookie解析成游戏对象
                    var cookieStr = CookiesHelper.GetCookieValue(key);
                    var json      = EncryptAndDecrypt.Decrypt(cookieStr);
                    data = JsonConvert.DeserializeObject <GameInfo>(json);
                }
            }
            catch {}
            if (data == null)
            {
                //如果都没有,则初始化一个游戏对象
                data = new GameInfo();
                RefNum(ref data);
            }
            return(data);
        }
示例#2
0
 public async Task <PasswordKeeper> LoadFromFileAsync(IStorageFile storageFile, string password)
 {
     using (var stream = await storageFile.OpenStreamForReadAsync())
     {
         using (var mem = new MemoryStream())
         {
             EncryptAndDecrypt.Decrypt(stream, password, mem);
             var passwordKeeper = new PasswordKeeper();
             mem.Seek(0, SeekOrigin.Begin);
             passwordKeeper.LoadString(GetText(mem));
             return(passwordKeeper);
         }
     }
 }
示例#3
0
        /// <summary>
        /// 返回用户信息
        /// </summary>
        /// <param name="userId">用户id</param>
        ///  <param name="userType">用户类型</param>
        /// <returns></returns>
        public UserInfo GetUserInfo(string CookieStr)
        {
            var userInfo = new UserInfo();

            try {
                var JsonStr = EncryptAndDecrypt.Decrypt(CookieStr);
                userInfo = JsonConvert.DeserializeObject <UserInfo>(JsonStr);
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(userInfo);
        }
        public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
        {
            if (
                actionContext.ActionDescriptor.GetCustomAttributes <SkipLoginAttribute>(false).Count == 0 &&
                actionContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes <SkipLoginAttribute>(false).Count == 0
                )
            {
                var        CookieUserName = WebConfigOperation.CookieName;
                HttpCookie cookie         = HttpContext.Current.Request.Cookies[CookieUserName];
                if (cookie == null)
                {
                    var data = new { Code = 2001, Msg = "用户未登陆", Success = false };
                    actionContext.Response = new HttpResponseMessage(HttpStatusCode.Accepted)
                    {
                        Content = new StringContent(JsonConvert.SerializeObject(data), System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
                    };
                    return;
                }
                else
                {
                    var CookieEnStr = cookie.Value;
                    var JsonStr     = EncryptAndDecrypt.Decrypt(CookieEnStr);

                    var userInfo = JsonConvert.DeserializeObject <UserInfo>(JsonStr);
                    if (userInfo == null)
                    {
                        var data = new { Code = 2001, Msg = "用户未登陆", Success = false };
                        actionContext.Response = new HttpResponseMessage(HttpStatusCode.Accepted)
                        {
                            Content = new StringContent(JsonConvert.SerializeObject(data), System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
                        };
                        return;
                    }
                }
            }
            //验证通过
            base.OnActionExecuting(actionContext);
        }
示例#5
0
 /// <summary>
 /// 验证权限(行为过滤器,action执行前会先执行这里)
 /// </summary>
 /// <param name="filterContext"></param>
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (!filterContext.ActionDescriptor.IsDefined(typeof(SkipLoginAttribute), false) &&
         !filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipLoginAttribute), false))
     {
         HttpCookie cookie = HttpContext.Current.Request.Cookies[WebConfigOperation.CookieName];
         if (cookie == null)
         {
             //var para = HttpContext.Current.Request.Url.Query;
             //var url = "/" + filterContext.ActionDescriptor.ControllerDescriptor.ControllerName + "/" + filterContext.ActionDescriptor.ActionName + para;
             //filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Login", action = "Index", url }));
             filterContext.Result = new JsonResult
             {
                 Data = new { Code = 2001, Msg = "请登录后重试" },
                 JsonRequestBehavior = JsonRequestBehavior.AllowGet
             };
             return;
         }
         else
         {
             var CookieStr = cookie.Value;
             var JsonStr   = EncryptAndDecrypt.Decrypt(CookieStr);
             var userInfo  = JsonConvert.DeserializeObject <UserInfo>(JsonStr);
             if (userInfo == null)
             {
                 //var para = HttpContext.Current.Request.Url.Query;
                 //var url = "/" + filterContext.ActionDescriptor.ControllerDescriptor.ControllerName + "/" + filterContext.ActionDescriptor.ActionName + para;
                 //filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Login", action = "Index", url }));
                 filterContext.Result = new JsonResult
                 {
                     Data = new { Code = 2001, Msg = "请登录后重试" },
                     JsonRequestBehavior = JsonRequestBehavior.AllowGet
                 };
                 return;
             }
         }
     }
 }
示例#6
0
        public string SwitchOnSOSviaSMS(string encryptedParms, string utcTicks, string ticks, string lat, string longi)
        {
            try
            {
                if (!string.IsNullOrEmpty(encryptedParms))
                {
                    string decodeEncryptedString = EncryptAndDecrypt.DecodeString(encryptedParms);

                    if (!string.IsNullOrEmpty(decodeEncryptedString))
                    {
                        string decryptedParameters = EncryptAndDecrypt.Decrypt(decodeEncryptedString);

                        if (!string.IsNullOrEmpty(decryptedParameters))
                        {
                            string[] parameters = Regex.Split(decryptedParameters, "&");

                            string ProfileID = Regex.Split(parameters[0], "=")[1];
                            string Token     = Regex.Split(parameters[1], "=")[1];
                            string SOS       = Regex.Split(parameters[2], "=")[1];

                            new GeoUpdate().SwitchOnSOSviaSMS(ProfileID, Token, SOS, ticks, lat, longi, utcTicks).GetAwaiter().GetResult();
                            return(ProfileID + "," + Token);
                        }
                    }
                    else
                    {
                        throw new InvalidDataException();
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 protected void btnDecrypt_Click(object sender, EventArgs e)
 {
     txtToEncrypt.Text = EncryptAndDecrypt.Decrypt(txtToDecrypt.Text, true);
 }
        public string SendSMS(object obj, bool IsBackup, EncryptAndDecrypt ead, SubTelcoProvider stProvider, RouteTelcoProvider routeProvider)
        {
            try
            {
                QueueService model   = (QueueService)obj;
                string       content = model.Content;
                if (model.ProcessingCode.Equals(ConfigType.QueueService_ProcessingCode_OTP))
                {
                    content = ead.Decrypt(content);
                }
                var modeltelco = stProvider.getSubTelcoByDest(model.Receiver);
                if (modeltelco == null)
                {
                    return(503 + ":NONE_TELCO");
                }
                else
                {
                    // CHECK TELCO
                    Telco telco = modeltelco.Telco;

                    // GET ROUTE
                    int    route      = routeProvider.getRoute(telco.Id, IsBackup);
                    int    result     = 0;
                    string code_Route = "";
                    if (route == ConfigType.ROUTE_VNET)
                    {
                        result = ConnectVNet.SendSMS(validatePhone(model.Receiver), content);
                        if (result == 0)
                        {
                            code_Route = "VNET";
                            //string log = string.Format("SendSMS: {0} -> {1} | {2}", model.Receiver, model.Content, code_Route);
                            //logger.Info(log + " - " + model.ProcessingCode);
                            return(result + ":" + code_Route);
                        }
                        else if (!IsBackup)
                        {
                            return(SendSMS(obj, true, ead, stProvider, routeProvider));
                        }
                        else
                        {
                            return(501 + ":" + code_Route);
                        }
                    }
                    else if (route == ConfigType.ROUTE_VNTP)
                    {
                        result = ConnectVNTP.SendSMS(validatePhone(model.Receiver), content);
                        if (result == 0)
                        {
                            code_Route = "VNTP";
                            return(result + ":" + code_Route);
                        }
                        else if (!IsBackup)
                        {
                            return(SendSMS(obj, true, ead, stProvider, routeProvider));
                        }
                        else
                        {
                            return(501 + ":" + code_Route);
                        }
                    }
                    else if (route == ConfigType.ROUTE_SOUTHtelecom)
                    {
                        string str_result = ConnectSOUTHtelecom.SendSMSBrandName(validatePhone(model.Receiver), content, "VietinBank");

                        if (result == 0)
                        {
                            code_Route = "SOUTHtelecom";
                            return(result + ":" + code_Route);
                        }
                        else if (!IsBackup)
                        {
                            return(SendSMS(obj, true, ead, stProvider, routeProvider));
                        }
                        else
                        {
                            return(501 + ":" + code_Route);
                        }
                    }
                    else
                    {
                        code_Route = "NONE_ROUTE";
                        //string log = string.Format("SendSMS: {0} -> {1} | {2}", model.Receiver, model.Content, code_Route);
                        //logger.Info(log + " - " + model.ProcessingCode);
                        return(502 + ":" + code_Route);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(555 + ":SendSMS_EX_ERROR");
            }
        }