Exemplo n.º 1
0
        public IActionResult VerifiyCode()
        {
            var verificationCode  = VerificationCodeUtil.GenerateRandomCode();
            var verificationImage = VerificationCodeUtil.GenerateCodeImage(verificationCode);

            //验证码存入缓存
            RedisServer.Cache.Set($"VerificationCode:{verificationImage.VerificationUUID}", verificationCode, 1800);
            var resultData = new
            {
                VerificationCode = $"data:image/png;base64,{Convert.ToBase64String(verificationImage.CaptchaMemoryStream.ToArray())}",
                VerificationUuid = verificationImage.VerificationUUID
            };

            return(ToResponseJson(ResultModel <object> .Ok(resultData)));
        }
Exemplo n.º 2
0
        public FileContentResult getvImage()
        {
            string randomcode = VerificationCodeUtil.CreateCode(4);

            Session["vcode"] = randomcode;

            MemoryStream ms = new MemoryStream();

            using (Bitmap map = VerificationCodeUtil.CreateImage(randomcode))
            {
                //生成图片
                map.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            }

            return(File(ms.ToArray(), "image/gif"));
        }
Exemplo n.º 3
0
        public VerificationCode NewCode(Dictionary <string, List <VerificationCode> > codeDict, string phone)
        {
            VerificationCode code = VerificationCodeUtil.NewCode();

            if (codeDict.ContainsKey(phone))
            {
                List <VerificationCode> codeList = codeDict[phone];
                if (codeList == null)
                {
                    codeList        = new List <VerificationCode>();
                    codeDict[phone] = codeList;
                }
                codeList.Add(code);
            }
            else
            {
                List <VerificationCode> codeList = new List <VerificationCode>();
                codeList.Add(code);
                codeDict.Add(phone, codeList);
            }
            return(code);
        }
Exemplo n.º 4
0
        public IActionResult VCode()
        {
            var stream = new VerificationCodeUtil().Create(out var code);

            return(File(stream.ToArray(), "image/png"));
        }