예제 #1
0
        /// <summary>
        /// 获取图片验证码
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public WebResponseContent ValidateCode()
        {
            var    data = VierificationCodeServices.Create(out string code, 4);//获取4位验证码并生图片
            string guid = Guid.NewGuid().ToString();

            CacheContext.Add(guid, code, expiresIn: DateTime.Now.AddMinutes(10).GetTimeSpan());//10分钟有效
            return(new WebResponseContent().OK(message: "获取成功", data: new { img = $"data:image/jpeg;base64,{Convert.ToBase64String(data.ToArray())}", sessionKey = guid }));
        }
예제 #2
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);
        }
예제 #3
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));
        }
예제 #4
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 });
        }