private void SyncRedisCache(DateTime date)
        {
            var siteDomains = DbContext.Domain.Select(p => p.SiteDomain).ToList();

            foreach (var domain in siteDomains)
            {
                var redisKey  = string.Format("visitor:active:{0}:{1}", date.ToString("yyyyMMdd"), domain);
                var redisBody = CacheContext.Get <List <VisitorActiveByDayCacheItem> >(redisKey);
                if (redisBody != null)
                {
                    var lockDomain = domain;
                    var query      = from p in DbContext.VisitorActive
                                     where p.SiteDomain == lockDomain && p.TotalDate == date
                                     select p.Id;

                    var queryCount = query.Count();
                    if (queryCount > 0)
                    {
                        DbContext.VisitorActive.Delete(p => p.SiteDomain == lockDomain && p.TotalDate == date);
                    }

                    foreach (var m in redisBody)
                    {
                        DbContext.VisitorActive.Add(new VisitorActive
                        {
                            SiteDomain = m.SiteDomain,
                            TotalDate  = m.TotalDate,
                            Depth      = m.Depth,
                            DepthCount = m.DepthCount
                        });
                    }
                    DbContext.SaveChanges();
                }
            }
        }
        private void SyncRedisCache(DateTime date)
        {
            var siteDomains = DbContext.Domain.Select(p => p.SiteDomain).ToList();

            foreach (var domain in siteDomains)
            {
                var redisKey  = string.Format("flow:day:{0}:{1}", date.ToString("yyyyMMdd"), domain);
                var redisBody = CacheContext.Get <FlowVolumeByDay>(redisKey);

                if (redisBody != null)
                {
                    var lockDomain = domain;
                    var query      = from p in DbContext.FlowVolumeByDay
                                     where p.SiteDomain == lockDomain && p.TotalDate == date
                                     select p.Id;

                    var queryCount = query.Count();
                    if (queryCount == 0)
                    {
                        //Insert
                        DbContext.FlowVolumeByDay.Add(new FlowVolumeByDay
                        {
                            SiteDomain              = domain,
                            TotalDate               = date,
                            PageView                = redisBody.PageView,
                            UniqueUser              = redisBody.UniqueUser,
                            NewUniqueUser           = redisBody.NewUniqueUser,
                            NewUniqueUserRate       = redisBody.NewUniqueUserRate,
                            UniqueIp                = redisBody.UniqueIp,
                            AccessNumber            = redisBody.AccessNumber,
                            UserViewPageAverage     = redisBody.UserViewPageAverage,
                            ViewPageDeptAverage     = redisBody.ViewPageDeptAverage,
                            ViewPageTimeSpanAverage = redisBody.ViewPageTimeSpanAverage,
                            BounceRate              = redisBody.BounceRate
                        });

                        DbContext.SaveChanges();
                    }
                    else
                    {
                        //update
                        DbContext.FlowVolumeByDay.Update(
                            p => p.SiteDomain == lockDomain && p.TotalDate == date,
                            m => new FlowVolumeByDay
                        {
                            PageView                = redisBody.PageView,
                            UniqueUser              = redisBody.UniqueUser,
                            NewUniqueUser           = redisBody.NewUniqueUser,
                            NewUniqueUserRate       = redisBody.NewUniqueUserRate,
                            UniqueIp                = redisBody.UniqueIp,
                            AccessNumber            = redisBody.AccessNumber,
                            UserViewPageAverage     = redisBody.UserViewPageAverage,
                            ViewPageDeptAverage     = redisBody.ViewPageDeptAverage,
                            ViewPageTimeSpanAverage = redisBody.ViewPageTimeSpanAverage,
                            BounceRate              = redisBody.BounceRate
                        });
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// referrer:page:[年月日]:[小时]:[域名]
        /// </summary>
        /// <param name="dateTime"></param>
        private void SyncRedisCache(DateTime dateTime)
        {
            var day  = DateTime.Parse(dateTime.ToString("yyyy-MM-dd"));
            var hour = dateTime.Hour;

            var siteDomains = DbContext.Domain.Select(p => p.SiteDomain).ToList();

            foreach (var domain in siteDomains)
            {
                //来源分类统计结果
                var redisKey  = string.Format("referrer:page:{0}:{1}:{2}", dateTime.ToString("yyyyMMdd"), dateTime.Hour.ToString("D2"), domain);
                var redisBody = CacheContext.Get <OriginPageByHourCacheItem>(redisKey);
                if (redisBody != null)
                {
                    var lockDomain = domain;
                    var query      = from p in DbContext.OriginPage
                                     where p.SiteDomain == lockDomain && p.TotalDate == day && p.TotalHour == hour
                                     select p.Id;

                    var queryCount = query.Count();
                    if (queryCount > 0)
                    {
                        DbContext.OriginPage.Delete(p => p.SiteDomain == lockDomain && p.TotalDate == day && p.TotalHour == hour);
                    }

                    //add
                    foreach (var m in redisBody.Items)
                    {
                        if (string.IsNullOrEmpty(m.OriginDomain) == false && m.OriginDomain.Length > 50)
                        {
                            m.OriginDomain = m.OriginDomain.Substring(0, 50);
                        }

                        if (string.IsNullOrEmpty(m.OriginUrl) == false && m.OriginUrl.Length > 1024)
                        {
                            m.OriginUrl = m.OriginUrl.Substring(0, 1024);
                        }

                        DbContext.OriginPage.Add(new OriginPage
                        {
                            SiteDomain   = redisBody.SiteDomain,
                            TotalDate    = redisBody.TotalDate,
                            TotalHour    = redisBody.TotalHour,
                            OriginDomain = m.OriginDomain,
                            OriginUrl    = m.OriginUrl,
                            TotalCount   = m.Count
                        });
                    }

                    try
                    {
                        DbContext.SaveChanges();
                    }
                    catch (DbEntityValidationException entityValidationException)
                    {
                        _logger.Error(entityValidationException);
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 手机号快捷登录
        /// </summary>
        /// <param name="code">验证码</param>
        /// <param name="phone">手机号码</param>
        /// <returns></returns>
        public async Task <WebResponseContent> Login(string code, string phone)
        {
            WebResponseContent responseContent = new WebResponseContent();
            string             _code           = CacheContext.Get <string>(phone + "ValidateSMSCode");

            if (_code == null)
            {
                return(responseContent.Error("请先获取短信验证码"));
            }
            if (_code != code)
            {
                return(responseContent.Error("验证码有误"));
            }
            var user = await DbContext.Set <Hiiops_Cart_SellerUser>().Where(x => x.Phone == phone).FirstOrDefaultAsync();

            if (user == null)
            {
                return(responseContent.Error("手机未注册"));
            }
            string token = JwtHelper.IssueJwt(user.Id.ToString());

            user.Token           = token;
            responseContent.Data = new { token, user.NickName, user.Phone, user.Account, user.Country, user.HeadImgUrl, user.Id, user.Name, user.Privilege, user.Province, user.Remark, user.SearchKey, user.Sex, user.Status };
            DbContext.Update(user);
            SellerContent.Current.LogOut(user.Id);
            return(responseContent.OK(ResponseType.LoginSuccess));
        }
Beispiel #5
0
        private List <Sys_Menu> GetAllMenu()
        {
            //每次比较缓存是否更新过,如果更新则重新获取数据
            if (_menuVersionn != "" && _menuVersionn == CacheContext.Get(_menuCacheKey))
            {
                return(_menus ?? new List <Sys_Menu>());
            }
            lock (_menuObj)
            {
                if (_menuVersionn != "" && _menus != null)
                {
                    return(_menus);
                }
                //2020.12.27增加菜单界面上不显示,但可以分配权限
                _menus = repository.FindAsIQueryable(x => x.Enable == 1 || x.Enable == 2)
                         .OrderByDescending(a => a.OrderNo)
                         .ThenByDescending(q => q.ParentId).ToList();

                _menus.ForEach(x =>
                {
                    // 2022.03.26增移动端加菜单类型
                    x.MenuType ??= 0;
                    if (!string.IsNullOrEmpty(x.Auth) && x.Auth.Length > 10)
                    {
                        try
                        {
                            x.Actions = x.Auth.DeserializeObject <List <Sys_Actions> >();
                        }
                        catch { }
                    }
                    if (x.Actions == null)
                    {
                        x.Actions = new List <Sys_Actions>();
                    }
                });

                string cacheVersion = CacheContext.Get(_menuCacheKey);
                if (string.IsNullOrEmpty(cacheVersion))
                {
                    cacheVersion = DateTime.Now.ToString("yyyyMMddHHMMssfff");
                    CacheContext.Add(_menuCacheKey, cacheVersion);
                }
                else
                {
                    _menuVersionn = cacheVersion;
                }
            }
            return(_menus);
        }
Beispiel #6
0
        /// <summary>
        /// 解析redis数据放入数据库
        /// </summary>
        /// <param name="dateTime"></param>
        private void SyncRedisCache(DateTime dateTime)
        {
            //var day = DateTime.Parse(dateTime.ToString("yyyy-MM-dd"));
            //取得domain
            var siteDomains = DbContext.Domain.Select(p => p.SiteDomain).ToList();

            foreach (var domain in siteDomains)
            {
                //respondents:page:[年月日]:[域名]
                var redisKey  = string.Format("respondents:page:{0}:{1}", dateTime.ToString("yyyyMMdd"), domain);
                var redisBody = CacheContext.Get <List <SurveyPageByDayCacheItem> >(redisKey);
                if (redisBody != null)
                {
                    //清理当前日期的全部数据
                    var lockDomain = domain;
                    var query      = from p in DbContext.SurveyPage
                                     where p.SiteDomain == lockDomain && p.TotalDate == dateTime
                                     select p.Id;

                    var queryCount = query.Count();
                    if (queryCount > 0)
                    {
                        DbContext.SurveyPage.Delete(p => p.SiteDomain == lockDomain && p.TotalDate == dateTime);
                    }

                    foreach (var m in redisBody)
                    {
                        DbContext.SurveyPage.Add(new SurveyPage
                        {
                            SiteDomain              = m.SiteDomain,
                            TotalDate               = m.TotalDate,
                            Url                     = m.Url,
                            PageView                = m.PageView,
                            UniqueUser              = m.UniqueUser,
                            NewUniqueUser           = m.NewUniqueUser,
                            NewUniqueUserRate       = m.NewUniqueUserRate,
                            UniqueIp                = m.UniqueIp,
                            AccessNumber            = m.AccessNumber,
                            UserViewPageAverage     = m.UserViewPageAverage,
                            ViewPageDeptAverage     = m.ViewPageDeptAverage,
                            ViewPageTimeSpanAverage = m.ViewPageTimeSpanAverage,
                            BounceRate              = m.BounceRate
                        });
                    }
                    DbContext.SaveChanges();
                }
            }
        }
Beispiel #7
0
        public bool GetCache(string sessionKey)
        {
            var sessionCacheItem = CacheContext.Get <SessionCacheItem>(sessionKey);

            if (sessionCacheItem == null)
            {
                return(false);
            }

            if (sessionCacheItem.InvalidTime > DateTime.Now)
            {
                return(true);
            }
            //移除无效Session缓存
            CacheContext.Remove(sessionKey);

            return(false);
        }
        private void SyncRedisCache(DateTime dateTime)
        {
            var day  = DateTime.Parse(dateTime.ToString("yyyy-MM-dd"));
            var hour = dateTime.Hour;

            //respondents:domain:[年月日]:[小时]
            var redisKey  = string.Format("respondents:domain:{0}:{1}", dateTime.ToString("yyyyMMdd"), dateTime.Hour.ToString("D2"));
            var redisBody = CacheContext.Get <List <SurveyDomainByHourCacheItem> >(redisKey);

            if (redisBody != null)
            {
                try
                {
                    //清理当前小时的全部数据
                    DbContext.SurveyDomain.Delete(p => p.TotalDate == day && p.TotalHour == hour);

                    //全新插入数据
                    foreach (var m in redisBody)
                    {
                        DbContext.SurveyDomain.Add(new SurveyDomain
                        {
                            SiteDomain              = m.SiteDomain,
                            TotalDate               = m.TotalDate,
                            TotalHour               = m.TotalHour,
                            PageView                = m.PageView,
                            UniqueUser              = m.UniqueUser,
                            NewUniqueUser           = m.NewUniqueUser,
                            NewUniqueUserRate       = m.NewUniqueUserRate,
                            UniqueIp                = m.UniqueIp,
                            AccessNumber            = m.AccessNumber,
                            UserViewPageAverage     = m.UserViewPageAverage,
                            ViewPageDeptAverage     = m.ViewPageDeptAverage,
                            ViewPageTimeSpanAverage = m.ViewPageTimeSpanAverage,
                            BounceRate              = m.BounceRate
                        });
                    }
                    DbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                }
            }
        }
Beispiel #9
0
        private void SyncRedisCache(DateTime date)
        {
            var siteDomains = DbContext.Domain.Select(p => p.SiteDomain).ToList();

            foreach (var domain in siteDomains)
            {
                var redisKey  = string.Format("visitor:newold:{0}:{1}", date.ToString("yyyyMMdd"), domain);
                var redisBody = CacheContext.Get <List <NewOldVisitorByDayCacheItem> >(redisKey);
                if (redisBody != null)
                {
                    var lockDomain = domain;
                    var query      = from p in DbContext.VisitorNewOld
                                     where p.SiteDomain == lockDomain && p.TotalDate == date
                                     select p.Id;

                    var queryCount = query.Count();
                    if (queryCount > 0)
                    {
                        DbContext.VisitorNewOld.Delete(p => p.SiteDomain == lockDomain && p.TotalDate == date);
                    }

                    foreach (var m in redisBody)
                    {
                        DbContext.VisitorNewOld.Add(new VisitorNewOld
                        {
                            SiteDomain              = m.SiteDomain,
                            TotalDate               = m.TotalDate,
                            IsNewVisitor            = m.IsNewVisitor,
                            PageView                = m.PageView,
                            UniqueUser              = m.UniqueUser,
                            UniqueIp                = m.UniqueIp,
                            AccessNumber            = m.AccessNumber,
                            UserViewPageAverage     = m.UserViewPageAverage,
                            ViewPageDeptAverage     = m.ViewPageDeptAverage,
                            ViewPageTimeSpanAverage = m.ViewPageTimeSpanAverage,
                            BounceRate              = m.BounceRate
                        });
                    }
                    DbContext.SaveChanges();
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// 找回密码
        /// </summary>
        /// <param name="phone">手机号码</param>
        /// <param name="code">验证码</param>
        /// <param name="sessionKey">提交表单验证码</param>
        /// <param name="newPassWord">新密码</param>
        /// <param name="againPassWord">重复密码</param>
        /// <returns></returns>
        public WebResponseContent FindPassword(string phone, string code, string sessionKey, string newPassWord, string againPassWord)
        {
            WebResponseContent webResponseContent = new WebResponseContent();

            if (string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(code) || string.IsNullOrEmpty(newPassWord) || string.IsNullOrEmpty(againPassWord))
            {
                return(webResponseContent.Error("请输入完整信息"));
            }
            if (!phone.IsPhoneNo())
            {
                return(webResponseContent.Error("请输入正确的手机号码"));
            }
            if (string.IsNullOrEmpty(CacheContext.Get(sessionKey)))
            {
                return(webResponseContent.Error("请先获取验证码"));
            }
            if (CacheContext.Get(sessionKey) != code)
            {
                return(webResponseContent.Error("请输入正确的验证码"));
            }
            if (!newPassWord.Equals(againPassWord))
            {
                return(webResponseContent.Error("两次输入的密码不一致"));
            }
            var seller = DbContext.Set <Hiiops_Cart_SellerUser>().Where(x => x.Phone == phone).FirstOrDefault();

            if (seller == null)
            {
                return(webResponseContent.Error("手机号未注册"));
            }

            string token = JwtHelper.IssueJwt(seller.Id.ToString());

            seller.Token    = token;
            seller.Password = newPassWord.EncryptDES(AppSetting.Secret.User);
            DbContext.Update(seller);
            if (DbContext.SaveChanges() > 0)
            {
                return(webResponseContent.OK("密码修改成功", data: new { token = seller.Token }));
            }
            return(webResponseContent.Error("密码修改失败"));
        }
Beispiel #11
0
        private void SyncRedisCache(DateTime date)
        {
            var siteDomains = DbContext.Domain.Select(p => p.SiteDomain).ToList();

            foreach (var domain in siteDomains)
            {
                var redisKey  = string.Format("visitor:loyalty:{0}:{1}", date.ToString("yyyyMMdd"), domain);
                var redisBody = CacheContext.Get <List <VisitorLoyaltyByDayCacheItem> >(redisKey);
                if (redisBody != null)
                {
                    var lockDomain = domain;
                    var query      = from p in DbContext.VisitorLoyalty
                                     where p.SiteDomain == lockDomain && p.TotalDate == date
                                     select p.Id;

                    var queryCount = query.Count();
                    if (queryCount > 0)
                    {
                        DbContext.VisitorLoyalty.Delete(p => p.SiteDomain == lockDomain && p.TotalDate == date);
                    }

                    foreach (var m in redisBody)
                    {
                        DbContext.VisitorLoyalty.Add(new VisitorLoyalty
                        {
                            SiteDomain     = m.SiteDomain,
                            TotalDate      = m.TotalDate,
                            FrequencyCount = m.FrequencyCount,
                            UniqueUser     = m.UniqueUser,
                            PageView       = m.PageView
                        });
                    }
                    DbContext.SaveChanges();
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// 判断指定的URL哈希是否存在
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public bool Exist(string url)
        {
            var cacheItem = _cacheContext.Get <string>(url);

            return(string.IsNullOrEmpty(cacheItem) == false);
        }
        /// <summary>
        ///
        /// KEY:referrer:category:[年月日]:[小时]:[域名]
        ///
        /// </summary>
        /// <param name="dateTime"></param>
        private void SyncRedisCache(DateTime dateTime)
        {
            var day  = DateTime.Parse(dateTime.ToString("yyyy-MM-dd"));
            var hour = dateTime.Hour;

            var siteDomains = DbContext.Domain.Select(p => p.SiteDomain).ToList();

            foreach (var domain in siteDomains)
            {
                //来源分类统计结果
                var redisKey  = string.Format("referrer:category:{0}:{1}:{2}", dateTime.ToString("yyyyMMdd"), dateTime.Hour, domain);
                var redisBody = CacheContext.Get <List <OriginCategoryByHourCacheItem> >(redisKey);
                if (redisBody != null && redisBody.Any())
                {
                    foreach (var item in redisBody)
                    {
                        var lockDomain = domain;
                        var cacheItem  = item;
                        var query      = from p in DbContext.OriginCategory
                                         where p.SiteDomain == lockDomain &&
                                         p.TotalDate == day &&
                                         p.TotalHour == hour &&
                                         p.OriginDomain == cacheItem.OriginDomain &&
                                         p.IndustryCode == cacheItem.IndustryCode
                                         select p.Id;

                        var queryCount = query.Count();
                        if (queryCount == 0)
                        {
                            #region Insert

                            DbContext.OriginCategory.Add(new OriginCategory
                            {
                                //时间维度
                                SiteDomain = domain,
                                TotalDate  = day,
                                TotalHour  = hour,

                                //来源分类指标
                                OriginDomain = cacheItem.OriginDomain,
                                IndustryCode = cacheItem.IndustryCode,
                                TotalNumber  = cacheItem.TotalNumber,

                                //通用指标
                                PageView                = cacheItem.PageView,
                                UniqueUser              = cacheItem.UniqueUser,
                                NewUniqueUser           = cacheItem.NewUniqueUser,
                                NewUniqueUserRate       = cacheItem.NewUniqueUserRate,
                                UniqueIp                = cacheItem.UniqueIp,
                                AccessNumber            = cacheItem.AccessNumber,
                                UserViewPageAverage     = cacheItem.UserViewPageAverage,
                                ViewPageDeptAverage     = cacheItem.ViewPageDeptAverage,
                                ViewPageTimeSpanAverage = cacheItem.ViewPageTimeSpanAverage,
                                BounceRate              = cacheItem.BounceRate
                            });
                            DbContext.SaveChanges();

                            #endregion
                        }
                        else
                        {
                            #region update

                            DbContext.OriginCategory.Update(
                                p => p.SiteDomain == lockDomain &&
                                p.TotalDate == day &&
                                p.TotalHour == hour &&
                                p.OriginDomain == cacheItem.OriginDomain &&
                                p.IndustryCode == cacheItem.IndustryCode,
                                m => new OriginCategory
                            {
                                //分类指标
                                TotalNumber = cacheItem.TotalNumber,

                                //通用指标
                                PageView                = cacheItem.PageView,
                                UniqueUser              = cacheItem.UniqueUser,
                                NewUniqueUser           = cacheItem.NewUniqueUser,
                                NewUniqueUserRate       = cacheItem.NewUniqueUserRate,
                                UniqueIp                = cacheItem.UniqueIp,
                                AccessNumber            = cacheItem.AccessNumber,
                                UserViewPageAverage     = cacheItem.UserViewPageAverage,
                                ViewPageDeptAverage     = cacheItem.ViewPageDeptAverage,
                                ViewPageTimeSpanAverage = cacheItem.ViewPageTimeSpanAverage,
                                BounceRate              = cacheItem.BounceRate
                            });

                            #endregion
                        }
                    }
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// 获取短信验证码
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public WebResponseContent ValidateSMSCode(string sessionKey, string code, string phone)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            //取出短信配置参数
            string regionId, accessKeyId, secret;
            string signName, templateCode, templateParam;
            var    config    = DbContext.Set <Hiiops_Cart_System_Config>();
            var    _regionId = CacheContext.Get <string>(Constant.REGIONID);

            if (_regionId == null)
            {
                regionId = config.Where(x => x.KEYNAME == Constant.REGIONID).FirstOrDefault().VAL;
                if (regionId == null || regionId == "")
                {
                    return(webResponseContent.Error("阿里云短信节点配置有误"));
                }
                CacheContext.Add(Constant.REGIONID, regionId);
            }
            else
            {
                regionId = _regionId;
            }
            var _accessKeyId = CacheContext.Get <string>(Constant.ACCESSKEYID);

            if (_accessKeyId == null)
            {
                accessKeyId = config.Where(x => x.KEYNAME == Constant.ACCESSKEYID).FirstOrDefault().VAL;
                if (accessKeyId == null || accessKeyId == "")
                {
                    return(webResponseContent.Error("阿里云短信配置有误"));
                }
                CacheContext.Add(Constant.ACCESSKEYID, accessKeyId);
            }
            else
            {
                accessKeyId = _accessKeyId;
            }

            var _secret = CacheContext.Get <string>(Constant.SECRET);

            if (_secret == null)
            {
                secret = config.Where(x => x.KEYNAME == Constant.SECRET).FirstOrDefault().VAL;
                if (secret == null || secret == "")
                {
                    return(webResponseContent.Error("阿里云短信配置有误"));
                }
                CacheContext.Add(Constant.SECRET, secret);
            }
            else
            {
                secret = _secret;
            }
            var _signName = CacheContext.Get <string>(Constant.SIGNNAME);

            if (_signName == null)
            {
                signName = config.Where(x => x.KEYNAME == Constant.SIGNNAME).FirstOrDefault().VAL;
                if (signName == null || signName == "")
                {
                    return(webResponseContent.Error("阿里云短信配置有误"));
                }
                CacheContext.Add(Constant.SIGNNAME, signName);
            }
            else
            {
                signName = _signName;
            }

            templateCode = config.Where(x => x.KEYNAME == Constant.TEMPLATECODE && x.Remark.Contains("登录验证码")).FirstOrDefault().VAL;
            if (templateCode == null || templateCode == "")
            {
                return(webResponseContent.Error("阿里云短信配置有误"));
            }


            templateParam = config.Where(x => x.KEYNAME == Constant.TEMPLATEPARAM && x.Remark.Contains("登录验证码模板")).FirstOrDefault().VAL;
            if (templateParam == null || templateParam == "")
            {
                return(webResponseContent.Error("阿里云短信配置有误"));
            }

            string _code = CacheContext.Get <string>(sessionKey);

            if (_code == null)
            {
                return(webResponseContent.Error("请先获取验证码"));
            }
            if (_code != code)
            {
                return(webResponseContent.Error("输入的验证码有误!"));
            }

            //组装一下数据
            Random rnd  = new Random();
            int    rand = rnd.Next(1000, 9999);

            CacheContext.Add(phone + "ValidateSMSCode", rand + "", DateTime.Now.AddMinutes(10).GetTimeSpan());
            return(_smsservice.SendTemplateSms(regionId, accessKeyId, secret, phone, signName, templateCode, templateParam));

            //return new WebResponseContent().OK(message: "获取成功", data: new { img = $"data:image/jpeg;base64,{Convert.ToBase64String(data.ToArray())}", sessionKey = guid });
        }
Beispiel #15
0
        /// <summary>
        /// 小程序-通过OpenId快捷登录
        /// </summary>
        /// <param name="code">微信临时code</param>
        /// <returns></returns>
        public async Task <WebResponseContent> Login(string code)
        {
            WebResponseContent responseContent = new WebResponseContent();
            WxUtils            _wxUtils        = new WxUtils();
            //取出appid和secret
            var config = DbContext.Set <Hiiops_Cart_System_Config>().Where(x => x.KEYNAME == Constant.WECHATAPPID || x.KEYNAME == Constant.WECHATAPPSECRET).ToList();

            if (config.Count < 2)
            {
                return(responseContent.Error("请先配置小程序参数"));
            }

            var    appid         = CacheContext.Get <string>(Constant.WECHATAPPID);
            string applet_appid  = "";
            string applet_secret = "";

            if (appid == null)
            {
                applet_appid = config.Where(x => x.KEYNAME == Constant.WECHATAPPID).FirstOrDefault().VAL;
                CacheContext.Add(Constant.WECHATAPPID, applet_appid);
            }
            else
            {
                applet_appid = appid;
            }
            var secret = CacheContext.Get <string>(Constant.WECHATAPPSECRET);

            if (secret == null)
            {
                applet_secret = config.Where(x => x.KEYNAME == Constant.WECHATAPPSECRET).FirstOrDefault().VAL;
                CacheContext.Add(Constant.WECHATAPPSECRET, applet_secret);
            }
            else
            {
                applet_secret = secret;
            }

            //通过code取openid
            string  jsonStr = _wxUtils.GetXcxKey(code, applet_appid, applet_secret);
            JObject json    = JObject.Parse(jsonStr);
            string  openid  = json["openid"].ToString();

            if (string.IsNullOrWhiteSpace(openid))
            {
                return(responseContent.Error("服务繁忙,请重试!"));
            }
            //通过openid判断系统是否存在当前微信用户
            var user = await DbContext.Set <Hiiops_Cart_SellerUser>().Where(x => x.OpenId == openid).FirstOrDefaultAsync();

            if (user == null)
            {
                return(responseContent.Error("第一次使用请先注册!"));
            }
            string token = JwtHelper.IssueJwt(user.Id.ToString());

            user.Token           = token;
            responseContent.Data = new { token, user.NickName, user.Phone, user.Account, user.Country, user.HeadImgUrl, user.Id, user.Name, user.Privilege, user.Province, user.Remark, user.SearchKey, user.Sex, user.Status };
            DbContext.Update(user);
            SellerContent.Current.LogOut(user.Id);
            return(responseContent.OK(ResponseType.LoginSuccess));
        }
        public UserAuthSession Get(string token)
        {
            var sessionCacheItem = CacheContext.Get <UserAuthSession>(token);

            return(sessionCacheItem);
        }
Beispiel #17
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="phone">手机号</param>
        /// <param name="newPwd">新密码</param>
        /// <param name="verificationCode">验证码</param>
        /// <param name="code">短信验证码</param>
        /// <param name="sessionKey">获取图片验证码的ID</param>
        /// <returns></returns>
        public async Task <WebResponseContent> ModifyPwd(string phone, string newPwd, string verificationCode, string code, string sessionKey)
        {
            newPwd = newPwd?.Trim();
            string             message     = "";
            WebResponseContent webResponse = new WebResponseContent();

            try
            {
                if (string.IsNullOrEmpty(phone))
                {
                    return(webResponse.Error("手机号不能为空"));
                }
                if (string.IsNullOrEmpty(newPwd))
                {
                    return(webResponse.Error("新密码不能为空"));
                }
                if (string.IsNullOrEmpty(verificationCode))
                {
                    return(webResponse.Error("验证码不能为空"));
                }
                if (string.IsNullOrEmpty(code))
                {
                    return(webResponse.Error("短信验证码有误"));
                }
                if (string.IsNullOrEmpty(sessionKey))
                {
                    return(webResponse.Error("参数有误"));
                }

                if (newPwd.Length < 6)
                {
                    return(webResponse.Error("密码不能少于6位"));
                }


                string imgCode = CacheContext.Get <string>(sessionKey);
                if (imgCode == null || imgCode != verificationCode)
                {
                    if (string.IsNullOrEmpty(verificationCode))
                    {
                        return(webResponse.Error("请输入正确验证码"));
                    }
                }


                string phoneCode = CacheContext.Get <string>(phone + "ValidateSMSCode");
                if (phoneCode == null || phoneCode != code)
                {
                    return(webResponse.Error("短信验证码有误"));
                }

                var a = await DbContext.Set <Hiiops_Cart_SellerUser>().Where(x => x.Phone == phone).FirstOrDefaultAsync();

                string userCurrentPwd = a.Password;


                string _newPwd = newPwd.EncryptDES(AppSetting.Secret.User);
                if (userCurrentPwd == _newPwd)
                {
                    return(webResponse.Error("新密码不能与旧密码相同"));
                }

                await Task.Run(() =>
                {
                    DbContext.Database.ExecuteSqlRaw($"UPDATA Hiiops_Cart_SellerUser SET Password = '******' , ModifyDate = '{DateTime.Now}'");
                });

                webResponse.OK("密码修改成功");
            }
            catch (Exception ex)
            {
                message = ex.Message;
                webResponse.Error("服务器了点问题,请稍后再试");
            }
            finally
            {
                if (message == "")
                {
                    Logger.OK(LoggerType.ApiModifyPwd, "密码修改成功");
                }
                else
                {
                    Logger.Error(LoggerType.ApiModifyPwd, message);
                }
            }
            return(webResponse);
        }
        private void SyncRedisCache(DateTime date)
        {
            var siteDomains = DbContext.Domain.Select(p => p.SiteDomain).ToList();

            foreach (var domain in siteDomains)
            {
                var redisKey  = string.Format("visitor:region:{0}:{1}", date.ToString("yyyyMMdd"), domain);
                var redisBody = CacheContext.Get <List <VisitorRegionByDayCacheItem> >(redisKey);
                if (redisBody != null)
                {
                    foreach (var m in redisBody)
                    {
                        var lockDomain = domain;
                        var query      = from p in DbContext.VisitorRegion
                                         where p.SiteDomain == lockDomain && p.TotalDate == date && p.UserIpAddress == m.UserIpAddress
                                         select p.Id;

                        var queryCount = query.Count();
                        if (queryCount == 0)
                        {
                            //Insert
                            DbContext.VisitorRegion.Add(new VisitorRegion
                            {
                                SiteDomain              = m.SiteDomain,
                                TotalDate               = m.TotalDate,
                                UserIpAddress           = m.UserIpAddress,
                                PageView                = m.PageView,
                                UniqueUser              = m.UniqueUser,
                                NewUniqueUser           = m.NewUniqueUser,
                                NewUniqueUserRate       = m.NewUniqueUserRate,
                                UniqueIp                = m.UniqueIp,
                                AccessNumber            = m.AccessNumber,
                                UserViewPageAverage     = m.UserViewPageAverage,
                                ViewPageDeptAverage     = m.ViewPageDeptAverage,
                                ViewPageTimeSpanAverage = m.ViewPageTimeSpanAverage,
                                BounceRate              = m.BounceRate
                            });

                            DbContext.SaveChanges();
                        }
                        else
                        {
                            //update
                            var m1 = m;
                            var m2 = m;
                            DbContext.VisitorRegion.Update(p => m2.UserIpAddress != null && (p.SiteDomain == lockDomain && p.TotalDate == date && p.UserIpAddress == m2.UserIpAddress), q => new VisitorRegion
                            {
                                PageView                = m1.PageView,
                                UniqueUser              = m1.UniqueUser,
                                NewUniqueUser           = m1.NewUniqueUser,
                                NewUniqueUserRate       = m1.NewUniqueUserRate,
                                UniqueIp                = m1.UniqueIp,
                                AccessNumber            = m1.AccessNumber,
                                UserViewPageAverage     = m1.UserViewPageAverage,
                                ViewPageDeptAverage     = m1.ViewPageDeptAverage,
                                ViewPageTimeSpanAverage = m1.ViewPageTimeSpanAverage,
                                BounceRate              = m1.BounceRate
                            });
                        }
                    }
                }
            }
        }