Esempio n. 1
0
        public CaptchaHelperModel SendAuthCode(CaptchaEnum captchaEnum, int accId, CaptchaPhoneEmailEnum typeEnum,
                                               string phoneOrEmail)
        {
            var redisCacheService = new RedisCacheService();

            if (string.IsNullOrWhiteSpace(phoneOrEmail))
            {
                throw new ArgumentNullException("phoneOrEmail", "手机号码邮箱地址为空");
            }


            //获取失败次数
            var strWrongTimesKey = GetWrongTimesKey(captchaEnum, accId);



            int iWrongTimes = redisCacheService.Get <int>(strWrongTimesKey);

            //判断验证码错误次数
            if (iWrongTimes > _checkWrongTimes)
            {
                return(new CaptchaHelperModel(false, "验证码错误次数过多,请1小时后重试或联系客服", typeEnum));
            }

            //获取验证码key
            var strCaptchaKey = GetCaptchaKey(captchaEnum, accId, phoneOrEmail);

            if (string.IsNullOrEmpty(strCaptchaKey))
            {
                return(new CaptchaHelperModel(false, "错误的手机号或邮箱", typeEnum));
            }


            //判断是否之前发过验证码
            int iCaptcha = redisCacheService.Get <int>(strCaptchaKey);

            if (iCaptcha == 0)
            {
                iCaptcha = Helper.GetInt32(Helper.GetRandomNum(), 111111);
            }

            var smsStr = string.Format("【生意专家】您本次获取的验证码为:{0},此验证码{1}分钟内有效。维护您的数据安全是生意专家义不容辞的责任。", iCaptcha,
                                       _outTimeMinutes);
            var mailSend = new EmailSend();
            var smsSend  = new SmsSend();
            var result   = typeEnum == CaptchaPhoneEmailEnum.Phone
                ? smsSend.SendSys(phoneOrEmail, smsStr, 13)
                : mailSend.SendVerifiEmail(accId, "", phoneOrEmail, iCaptcha.ToString());

            if (result)
            {
                _logger.Debug("发送验证码成功:" + iCaptcha);
                redisCacheService.Set(strCaptchaKey, iCaptcha, _outTimeMinutes * 60);
                return(new CaptchaHelperModel(true, "发送验证码成功", CaptchaPhoneEmailEnum.Email));
            }
            else
            {
                return(new CaptchaHelperModel(false, "发送失败", CaptchaPhoneEmailEnum.Email));
            }
        }
Esempio n. 2
0
        public bool HadReceivedDailyMaterialCoupon(int accId, int groupId, int totalSeconds)
        {
            string key = RedisConsts.DailyMaterialCoupon + groupId.ToString() + accId.ToString();
            var    redisCacheService = new RedisCacheService();

            return(redisCacheService.Set(key, true.ToString(), totalSeconds));
        }
        /// <summary>
        ///     更新支出分类Redis缓存数据
        /// </summary>
        /// <param name="userContext"></param>
        private void UpdateRedisPayClassCatch(UserContext userContext)
        {
            var redisCacheService    = new RedisCacheService();
            var currentNeedCatchData = GetExpensesCategoryFromDb(userContext);
            var setCatchKey          = string.Format("I200:{0}:{1}", RedisConsts.PayClassList, userContext.AccId);

            redisCacheService.Set(setCatchKey, currentNeedCatchData, catchTime * 60);
        }
Esempio n. 4
0
        public IEnumerable <WeatherForecast> Get()
        {
            var key = $"{nameof(WeatherForecastController)}:{nameof(Get)}";

            _logger.LogDebug("attempting to retrieve weather information using cache key {key}", key);

            //cache-aside pattern
            var weather = _redisCacheSvc.Get <WeatherForecast[]>(key);

            if (weather is null || weather.Length == 0)
            {
                _logger.LogWarning("cache item with cache key {key} doesn't exist", key);
                weather = GenerateWeather();
                _redisCacheSvc.Set(key, weather, TimeSpan.FromSeconds(10));//cache for n seconds
                _logger.LogInformation("item added with cache key {key} and data {data}", key, weather);
            }
Esempio n. 5
0
        public CaptchaHelperModel CheckCaptchaCode(CaptchaEnum captchaEnum, int accId, CaptchaPhoneEmailEnum typeEnum,
                                                   int captchaCode, string phoneOrEmail)
        {
            var redisCacheService = new RedisCacheService();
            CaptchaHelperModel model;

            //获取失败次数
            var strWrongTimesKey = GetWrongTimesKey(captchaEnum, accId);
            int iWrongTimes      = redisCacheService.Get <int>(strWrongTimesKey);

            //判断验证码错误次数
            if (iWrongTimes > 10)
            {
                return(new CaptchaHelperModel(false, "验证码错误次数过多,请1小时后重试或联系客服", typeEnum));
            }

            //获取验证码key
            string strCaptchaKey = GetCaptchaKey(captchaEnum, accId, phoneOrEmail);

            if (string.IsNullOrWhiteSpace(strCaptchaKey))
            {
                return(new CaptchaHelperModel(false, "验证码校验失败", typeEnum));
            }

            //获取发过的验证码
            int iCaptcha = redisCacheService.Get <int>(strCaptchaKey);

            if (iCaptcha == captchaCode)
            {
                _logger.Debug("验证验证码成功:" + iCaptcha);
                redisCacheService.RemoveKey(strWrongTimesKey);
                redisCacheService.RemoveKey(strCaptchaKey);
                return(new CaptchaHelperModel(true, "验证码校验成功", typeEnum));
            }
            else if (iCaptcha == 0)
            {
                _logger.Debug("验证验证码失败:" + captchaCode);
                return(new CaptchaHelperModel(false, "验证码过期,请重新申请发送验证码", typeEnum));
            }
            else
            {
                //失败添加失败次数
                redisCacheService.Set(strWrongTimesKey, iWrongTimes + 1, 60 * 60);
                return(new CaptchaHelperModel(false, "验证码校验失败", typeEnum));
            }
        }
        /// <summary>
        /// redis获取商品详情
        /// </summary>
        /// <param name="goodsId"></param>
        /// <returns></returns>
        private MaterialGoodsInfo GetMaterialGoodsDetails(int goodsId)
        {
            MaterialGoodsInfo entity;
            string            key = RedisConsts.MaterialGoodsInfo + goodsId;
            var redisCacheService = new RedisCacheService();

            if (redisCacheService.HasKey(key))
            {
                entity = redisCacheService.Get <MaterialGoodsInfo>(key);
            }
            else
            {
                entity = GetMaterialGoodsDb(goodsId);
                //Insert Cache 7days
                Task.Factory.StartNew(() =>
                {
                    redisCacheService.Set(key, entity, 60 * 60 * 24 * 7);
                });
            }
            return(entity);
        }
        /// <summary>
        /// redis获取商品列表
        /// </summary>
        /// <returns></returns>
        private IEnumerable <MaterialGoodsListRedisItem> GetMaterialGoodsIdList()
        {
            IEnumerable <MaterialGoodsListRedisItem> rModel;
            string key = RedisConsts.MaterialGoodsList;
            var    redisCacheService = new RedisCacheService();

            if (redisCacheService.HasKey(key))
            {
                rModel = redisCacheService.Get <List <MaterialGoodsListRedisItem> >(key);
            }
            else
            {
                rModel = Mapper.Map <IEnumerable <T_MaterialGoods2>, IEnumerable <MaterialGoodsListRedisItem> >(_materialGoods.FindAll());

                //Insert Cache 7days
                Task.Factory.StartNew(() =>
                {
                    redisCacheService.Set(key, rModel, 60 * 60 * 24 * 7);
                });
            }
            return(rModel);
        }
Esempio n. 8
0
        public AccountVersion GetAccountVersion(int accId)
        {
            var redisCacheService  = new RedisCacheService();
            var accVersionRedisKey = RedisConsts.AccountVersion + accId.ToString();
            var accVersionResult   = redisCacheService.Get <AccountVersion>(accVersionRedisKey);

            if (accVersionResult != null)
            {
                _logger.Debug(string.Format("Get app account version from redis cache. {0},{1} ", accId, accVersionRedisKey));
                return(accVersionResult);
            }

            var accVersion = GetAccountVersionBasic(accId);
            var entity     = new AccountVersion
            {
                Version = accVersion.Version,
                VersionExpirationTime = accVersion.VersionExpirationTime
            };

            entity.VersionName = entity.Version.ToEnumDescriptionString(typeof(AccountVersionEnum));
            //行业版
            if (entity.Version == (int)AccountVersionEnum.Industry)
            {
                entity.SubVersionName = accVersion.IndustryName;
            }
            //试用高级版
            if (entity.Version == (int)AccountVersionEnum.Advanced && accVersion.BetaAdvance == (int)BetaAdvanceEnum.UsingBetaAdvance)
            {
                entity.SubVersionName = Convert.ToInt32(BetaAdvanceEnum.UsingBetaAdvance).ToEnumDescriptionString(typeof(AccountVersionEnum));
            }
            //todo:终身高级版
            //todo:购买后更新redis
            var expireSeconds = 108000;

            redisCacheService.Set(accVersionRedisKey, entity, expireSeconds);
            return(entity);
        }
Esempio n. 9
0
        private HomeIndex GetHomeIndexModel(int locationId)
        {
            var cacheSrv = new RedisCacheService();

            //Get the city
            var city = Cidade.Load(locationId);

            //Get the home object
            var objHome = city.Microregion.Home;

            #region GET CACHE

            //Set the const time value
            const int time = 1;

            //Set the cache key
            var key = $"Home:{objHome.Id}";

            //Find in the cache for the model
            var objModel = cacheSrv.Get <HomeIndex>(key);

            //If model exists in cache return the object
            if (objModel != null)
            {
                return(objModel);
            }
            #endregion

            //Save the current home state
            var currentHome = objHome;

            //If Home is disabled load the main home
            if (!objHome.Status)
            {
                objHome = Home.Load(1); //Home Curitiba
            }
            //Get list of news highlights
            var lstHighlights = Noticia.GetHighlightNewsByHome(objHome.Id).ToList();

            //Create initial negation list with hiloghts id's
            var notInList = lstHighlights.Select(s => s.Id).ToList();

            objModel = new HomeIndex
            {
                //Base
                Title       = "Massa News - A notícia em movimento!",
                Description = "O Massa News oferece a melhor cobertura jornalística do Paraná com notícias personalizadas da sua região.",
                Robots      = "index, follow",
                Canonical   = Constants.UrlWeb,

                //Model
                Cidade           = Cidade.Load(12), //Curitiba //objCidade,
                SidebarHighlight = objHome.SidebarHighlight,
                TemplateId       = objHome.Highlight.TemplateId,
                Highlights       = lstHighlights
            };

            //SUA REGIÃO
            //Este módulo recebe a cidade original
            objModel.DestaqueComTagsSuaRegiao = GetDestaquesComtags(Section.SuaRegiao, currentHome, ref notInList);

            //ESPORTES
            objModel.DestaqueComTagsEsportes = GetDestaquesComtags(Section.Esportes, currentHome, ref notInList);

            //ENTRETEDIMENTO
            objModel.DestaqueComTagsEntretedimento = GetDestaquesComtags(Section.Entretenimento, currentHome, ref notInList);

            //PARANÁ - TODOS OS PLANTÕES
            objModel.DestaqueComTagsParana = GetDestaquesComtags(Section.Parana, currentHome, ref notInList);

            //CATEGORIAS DESTAQUES
            objModel.CategoriasDestaquesModel = GetCategoriaDestaquesModel(objHome.Id, ref notInList);

            //VIAJAR É MASSA
            objModel.DestaqueComTagsViajarEMassa = GetDestaquesComtags(Section.ViajarEMassa, currentHome, ref notInList);

            //WHERE CURITIBA
            if (currentHome.Id == 1)
            {
                objModel.DestaqueComTagsWhereCuritiba = GetDestaquesComtags(Section.WhereCuritiba, currentHome, ref notInList);
            }

            //NEGÓCIOS DA TERRA
            objModel.DestaqueComTagsNegociosDaTerra = GetDestaquesComtags(Section.NegociosDaTerra, currentHome, ref notInList);

            //VIDEOS
            objModel.DestaqueVideo = GetVideoHighlights(city, ref notInList);

            //FOTOS (GALERIAS)
            objModel.HighlightsFotos = Noticia.GetBySection(8, Section.Fotos, 1, ref notInList, true).ToList();

            //BLOGS
            objModel.Blogs = GetBlogListByMicroregion(currentHome.MicroregiaoId);

            #region ENQUETE
            var statusEnquete = EnqueteSrv.GetStatusEnquete();

            switch (statusEnquete.Status)
            {
            case (int)EnqueteEnum.Estadual:
                objModel.ShowEnquete = true;
                objModel.EnqueteId   = Constants.EnqueteRegionalId;
                break;

            case (int)EnqueteEnum.Regional:
                foreach (var item in statusEnquete.RegioesEnquetes.Where(item => objHome.MicroregiaoId == item.MicroregiaoId && item.Status))
                {
                    objModel.ShowEnquete = true;
                    objModel.EnqueteId   = item.EnqueteId;
                }
                break;

            default:
                objModel.ShowEnquete = false;
                break;
            }
            #endregion

            //Set the cache
            cacheSrv.Set(key, objModel, time);

            return(objModel);
        }
Esempio n. 10
0
        /// <summary>
        /// 获取广告详情
        /// </summary>
        /// <returns></returns>
        public ResponseModel GetAdvertDetail(string positionCode, int accountId = -1, UserContext userContext = null)
        {
            var adverApi = new Entity.Api.Advert.Advert();

            string key = RedisConsts.StationAdvertKey + positionCode.ToLower();

            var redisCacheService = new RedisCacheService();

            if (redisCacheService.HasKey(key))
            {
                adverApi = redisCacheService.Get <Entity.Api.Advert.Advert>(key);
            }
            else
            {
                var advertModel =
                    _advertDataRepository.FindAll(ad => ad.AdPositionCode == positionCode &&
                                                  ad.Enable == 1 &&
                                                  ad.StartDate <= DateTime.Now &&
                                                  ad.EndDate >= DateTime.Now
                                                  ).OrderByDescending(o => o.Id).FirstOrDefault();

                if (advertModel == null)
                {
                    //throw new YuanbeiException("获取站内广告信息失败,未找到对应信息");
                    return(new ResponseModel
                    {
                        Code = 0,
                        Message = "无数据",
                        Data = null
                    });
                }

                var adverResourcesList = _advertResourcesDataRepository.FindAll(ad => ad.AdId == advertModel.Id &&
                                                                                ad.State == 1)
                                         .OrderByDescending(o => o.Id);

                //TO DTO
                adverApi.title   = advertModel.AdTitle;
                adverApi.display = advertModel.DisplayMode;
                adverApi.width   = advertModel.AdWidth;
                adverApi.height  = advertModel.AdHieght;
                adverApi.items   = new List <Entity.Api.Advert.AdvertResources>();
                foreach (var advertResourcese in adverResourcesList)
                {
                    var advertResourceApi = new Entity.Api.Advert.AdvertResources();
                    //advertResourceApi.link = advertResourcese.AdLink;
                    advertResourceApi.link = WebConfigSetting.Instance.AdvertTransferUrl +
                                             string.Format("?adresid={0}&turl={1}", advertResourcese.Id,
                                                           HttpUtility.UrlEncode(advertResourcese.AdLink));
                    advertResourceApi.image = WebConfigSetting.Instance.ImageServer + advertResourcese.AdImageUrl;

                    adverApi.items.Add(advertResourceApi);
                }

                //Insert Cache 7days
                redisCacheService.Set(key, adverApi, 60 * 60 * 24 * 7);
            }

            //Insert View Log
            Task.Factory.StartNew(() =>
            {
                var advertModel =
                    _advertDataRepository.FindAll(ad => ad.AdPositionCode == positionCode &&
                                                  ad.Enable == 1 &&
                                                  ad.StartDate <= DateTime.Now &&
                                                  ad.EndDate >= DateTime.Now
                                                  ).OrderByDescending(o => o.Id).FirstOrDefault();

                AdvertLog advertLog = new AdvertLog();
                advertLog.AdId      = advertModel.Id;
                advertLog.AccountId = accountId;
                if (userContext != null)
                {
                    advertLog.Ip = userContext.IpAddress;
                }
                advertLog.Type       = 1;
                advertLog.CreateTime = DateTime.Now;
                _advertLogDataRepository.Insert(advertLog);
            });

            //TODO 店铺权限判断
            if (accountId != -1)
            {
            }

            //2.返回查询结果
            return(new ResponseModel
            {
                Code = 0,
                Message = "获取数据成功",
                Data = adverApi
            });
        }
Esempio n. 11
0
 private static void set(string key, string value)
 {
     _redisCacheService.Set(key, value);
 }