前言:最近写的实验室的一个管理系统需要更改登录界面的验证码,原来使用的是若依的,但是有时确实容易看错,没有太大必要,所以就更换一个简单清晰的,在网上看了一下之后,决定更换为easy-captcha来实现 1 生成验证的流程 ⬇️前端发送请求 ⬇️后端接受请求并进行处理 ↘️生成uuid、验证码和图片 ...
specCaptcha.toBase64();// 如果不想要base64的头部data:image/png;base64,specCaptcha.toBase64("");// 加一个空的参数即可 输出到磁盘上的方法如下所示: FileOutputStreamoutputStream=newFileOutputStream(newFile("C:/captcha.png"))SpecCaptchaspecCaptcha=newSpecCaptcha(130,48,5); specCaptcha.out(out...
设置宽度为160,高度为40,长度为5GifCaptchagifCaptcha=newGifCaptcha(160,40,5);// 获取生成的验证码内容finalStringcaptcha=gifCaptcha.text().toLowerCase();System.out.println(captcha);// 获取生成验证码的base64字符串// String base64 = gifCaptcha.toBase64...
String captchaValue = captcha.text(); final String captchaKey = getCaptchaKey(uuid); log.debug("图形验证码key:{},value:{}", captchaKey, captchaValue); //放入redis并设置过期时间 redisUtil.set(captchaKey, captchaValue, Constants.VERIFYCODE_EXPIRETIME * 60); final CaptchaResult captchaResult =...
5、编写验证码结果集业务层:EasyCaptchaService.java,我已经将你每次要获取的验证码值以及Base64编码封装到一个Map中返回,你可以拿到之后进行自己相应的业务操作。 import com.changlu.springbootcaptcha.easycaptcha.enums.CodeTypeEnum; import com.changlu.springbootcaptcha.easycaptcha.producer.EasyCaptchaProducer; ...
StringcaptchaBase64captcha.toBase64();//获取验证码图片的base64编码 captcha.out(response.getOutputStream());//前后端不分离,直接将图片以流的形式返回 1. 2. 3. 4. 5. 正文开始:Springboot版本依赖为2.6.6,步骤1-4你不用额外关注,关注service封装方法即可 ...
2.2.base64验证码 data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAY 2.3.中文验证码 3.导入项目 3.1.maven方式引入 在你的pom.xml中添加如下代码: <dependency> <groupId>io.github.yufeixuan</groupId> <artifactId>easy-captcha</artifactId> <version>1.5.4</version> </dependency> ...
{ // 创建验证码对象 Captcha captcha = new ArithmeticCaptcha(); // 生成验证码编号 String verifyCodeKey = UUID.randomUUID().toString(); String verifyCode = captcha.text(); // 获取验证码图片,构造响应结果 VerifyCodeEntity verifyCodeEntity = new VerifyCodeEntity(verifyCodeKey, captcha.toBase64(), ...
5.4.输出base64编码 5.5.输出到文件 6.前后端分离项目的使用 7.自定义效果 8.更新日志 EasyCaptcha 1.简介 Java图形验证码,支持gif、中文、算术等类型,可用于Java Web、JavaSE等项目。 2.效果展示 算术类型: ...
5、编写验证码结果集业务层:EasyCaptchaService.java,我已经将你每次要获取的验证码值以及Base64编码封装到一个Map中返回,你可以拿到之后进行自己相应的业务操作。 importcom.changlu.springbootcaptcha.easycaptcha.enums.CodeTypeEnum;importcom.changlu.springbootcaptcha.easycaptcha.producer.EasyCaptchaProducer;import...