Exemplo n.º 1
0
        /// <summary>
        /// 获取验证码
        /// </summary>
        public ActionResult CheckCode()
        {
            var yzm = new YzmHelper();

            yzm.CreateImage();
            var code = yzm.Text;

            Session["ValidateCode"] = code;
            Bitmap       img = yzm.Image;
            MemoryStream ms  = new MemoryStream();

            img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            return(File(ms.ToArray(), @"image/jpeg"));
        }
Exemplo n.º 2
0
        public IActionResult GetVerifyCodeAsync()
        {
            var response = new Response <Object>();

            try {
                YzmHelper yzm = new YzmHelper(RandType.Letters, 6, 20, 36);
                yzm.CreateImage();
                HttpContext.Session.SetString("VerifyCode", yzm.Text);

                response.Code = true;
                response.Data = yzm.CreateBase64String();
            }
            catch (Exception ex) {
            }
            return(response.ToHttpResponse());
        }
Exemplo n.º 3
0
        public ResponseBaseModel <dynamic> CheckCodeBaseStr(string token)
        {
            var yzm = new YzmHelper();

            yzm.CreateImage();
            var          code = yzm.Text;
            Bitmap       img  = yzm.Image;
            MemoryStream ms   = new MemoryStream();

            img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            string str = Convert.ToBase64String(ms.ToArray());

            RedisCacheHelper.Remove(RedisCacheKey.AuthCheckCodeKey + token);
            RedisCacheHelper.AddSet(RedisCacheKey.AuthCheckCodeKey + token, code, DateTime.Now.AddMinutes(3));
            return(new ResponseBaseModel <dynamic> {
                ResultCode = ResponceCodeEnum.Success, Message = "", Data = "data:image/png;base64," + str
            });
        }