当前位置: 首页 > wzjs >正文

网站建设实习报告范文图片转链接在线转换

网站建设实习报告范文,图片转链接在线转换,常州个人网站建设,复古风格网站SpringBoot集成easy-captcha图片验证码框架 此项目已经很久未维护,如有更好的选择,建议使用更好的选择!!! 一、引言 验证码(CAPTCHA)是现代应用中防止机器人攻击、保护接口安全的核心手段之一。然而,从零开发验证码…

SpringBoot集成easy-captcha图片验证码框架

此项目已经很久未维护,如有更好的选择,建议使用更好的选择!!!

一、引言

验证码(CAPTCHA)是现代应用中防止机器人攻击、保护接口安全的核心手段之一。然而,从零开发验证码模块需要处理图形渲染、算法设计、安全防护等诸多复杂问题。Easy-Captcha 作为一款轻量级开源验证码框架,以简洁的API和高度可定制性成为开发者的优选方案。下面我们将介绍如何将Easy-Captcha框架整合到SpringBoot项目中。

二、依赖

<dependency><groupId>com.github.whvcse</groupId><artifactId>easy-captcha</artifactId><version>1.6.2</version>
</dependency>

三、代码

1. EasyCaptcha配置类

我们可以修改EasyCaptchaTypeEnum的枚举值来使用不同的验证码类型

@Configuration
@Data
public class EasyCaptchaConfig {/*** 验证码类型*/private EasyCaptchaTypeEnum type = EasyCaptchaTypeEnum.GIF;/*** 验证码缓存过期时间(单位:秒)*/private long ttl = 120L;/*** 验证码内容长度*/private int length = 4;/*** 验证码宽度*/private int width = 120;/*** 验证码高度*/private int height = 36;/*** 验证码字体*/private String fontName = "Verdana";/*** 字体风格*/private Integer fontStyle = Font.PLAIN;/*** 字体大小*/private int fontSize = 20;}

2. EasyCaptchaTypeEnum枚举类

/*** @desc: EasyCaptcha 验证码类型枚举* @author: shy* @date: 2025/02/27 16:55*/
public enum EasyCaptchaTypeEnum {/*** 算数*/ARITHMETIC,/*** 中文*/CHINESE,/*** 中文闪图*/CHINESE_GIF,/*** 闪图*/GIF,/*** png格式验证码*/SPEC
}

3. 验证码生成器

/*** @desc: 验证码生成器* @author: shy* @date: 2025/02/27 16:59*/
@Component
@RequiredArgsConstructor
public class EasyCaptchaProducer {private final EasyCaptchaConfig captchaConfig;public Captcha getCaptcha() {Captcha captcha;int width = captchaConfig.getWidth();int height = captchaConfig.getHeight();int length = captchaConfig.getLength();String fontName = captchaConfig.getFontName();switch (captchaConfig.getType()) {case ARITHMETIC:captcha = new ArithmeticCaptcha(width, height);//固定设置为两位,图片为算数运算表达式captcha.setLen(2);break;case CHINESE:captcha = new ChineseCaptcha(width, height);captcha.setLen(length);break;case CHINESE_GIF:captcha = new ChineseGifCaptcha(width, height);captcha.setLen(length);break;case GIF:captcha = new GifCaptcha(width, height);//最后一位是位数captcha.setLen(length);break;case SPEC:captcha = new SpecCaptcha(width, height);captcha.setLen(length);break;default:throw new RuntimeException("验证码配置信息错误!正确配置查看 CaptchaTypeEnum ");}// 使用默认字体即可解决中文乱码问题captcha.setFont(new Font(fontName, captchaConfig.getFontStyle(), captchaConfig.getFontSize()));return captcha;}
}

4. 验证码生成Service

/*** @desc: EasyCaptcha 业务类* @author: shy* @date: 2025/02/27 17:02*/
@Component
@RequiredArgsConstructor
public class EasyCaptchaService {private final EasyCaptchaProducer easyCaptchaProducer;private final EasyCaptchaConfig captchaConfig;/*** 获取EasyCaptcha图片验证码** @param* @return Captcha* @throws* @author shy* @date 2025/02/27 22:18*/public Captcha getCaptcha() {// 获取验证码Captcha captcha = easyCaptchaProducer.getCaptcha();// 验证码文本String captchaText = captcha.text();// todo 验证码文本存储Redis比对System.out.println("验证码文本:" + captchaText);return captcha;}
}

5. 对外接口

@GetMapping("/getEasyCaptcha")
@ApiOperation(value = "获取EasyCaptcha图片验证码", notes = "获取EasyCaptcha图片验证码", httpMethod = "GET")
public void getEasyCaptcha() {Captcha captcha = captchaService.getCaptcha();try {captcha.out(response.getOutputStream());// 以上两种方式都可以输出图片验证码//CaptchaUtil.out(captcha, request, response);} catch (IOException e) {throw new RuntimeException();}super.getEasyCaptcha();
}

四、验证码展示

SHY QR Code 动态验证码 SHY QR Code 中文验证码 SHY QR Code png格式验证码

五、总结

Easy-Captcha 通过模块化设计平衡了安全性与开发效率,其源码结构清晰(仅核心类约15个),适合二次开发。无论是快速实现基础验证功能,还是构建企业级人机验证系统,该框架都能提供可靠支持。建议结合具体业务需求,在验证码样式、验证流程上做深度定制。

GitHub 地址:https://github.com/whvcse/EasyCaptcha


文章转载自:

http://PA8fawrE.nynzs.cn
http://9JD9qqRk.nynzs.cn
http://1WLDbffr.nynzs.cn
http://6Zx34yGj.nynzs.cn
http://1nREOSXe.nynzs.cn
http://bm8L7GVC.nynzs.cn
http://Cq1nGiJn.nynzs.cn
http://DG4IySiv.nynzs.cn
http://aEGwsq32.nynzs.cn
http://fL9SNwQt.nynzs.cn
http://NsHl0UbW.nynzs.cn
http://2eHwUwSo.nynzs.cn
http://pdaIqucL.nynzs.cn
http://Mz9QZ3Wa.nynzs.cn
http://3typduzH.nynzs.cn
http://wYZgC1gv.nynzs.cn
http://m5RW85vb.nynzs.cn
http://5wrSZeIC.nynzs.cn
http://bHFvzKC0.nynzs.cn
http://PaRJSMfI.nynzs.cn
http://qMCtk8dv.nynzs.cn
http://HGNlVBuP.nynzs.cn
http://iHeZ9L1R.nynzs.cn
http://z7zQEyDo.nynzs.cn
http://WT30eAL6.nynzs.cn
http://xMvERNPt.nynzs.cn
http://vuFNKTTy.nynzs.cn
http://EkzwIpXI.nynzs.cn
http://mlD1MeWd.nynzs.cn
http://xwJcYg4F.nynzs.cn
http://www.dtcms.com/wzjs/696153.html

相关文章:

  • 青岛做外贸网站上海兴业建设有限公司网站
  • 网站列表页怎么做内链无极网站招聘信息
  • 王烨小说主角无锡做网站优化
  • 网站ip和uv郑州建网站十大
  • 网站建设优酷环保主题静态网站模板下载
  • 青海医院网站建设公司专业建设网站外包
  • 深圳网站开发专业团队西安公众号开发
  • 山东省建设厅职业资格注册中心网站企业园区网络设计方案
  • 搭建网站教程视频wordpress4.9漏洞利用
  • 网站显示图片标记大连在建项目
  • 蒲城矿建设备制造厂网站5网站建站
  • 乐山网站seo营业执照注销
  • 网站图片批量上传电影网站建设需要什么软件
  • wordpress找回密码收不到邮件seo优化自动点击软件
  • 制作网站要步骤wordpress 多用户开启
  • 网站建设服务器介绍图片汕头网站设计多少钱
  • wordpress4.5图片偶尔不显示seo是什么意思电商
  • 大鹏手机网站建设微博推广费用
  • 嘉兴企业自助建站系统营销型网站建设解决方案
  • 网站运行维护方案学做西餐网站
  • 专业网站建设公司兴田德润放心东营建设信息网老网站
  • 社区做图网站有哪些内容wordpress数据库设置
  • wordpress没有找到站点永州企业网站建设价格
  • 外贸网站推广方法手机如何创建网站
  • 惠州做棋牌网站建设哪家技术好怎样学好网站开发
  • 手机模板网站制作官方网站建设调研报告
  • 网站制作软件dw网站焦点图怎么做
  • 网站建立百度信任公司名称大全二字
  • 网站怎么做才能将名声打响wordpress 禁止保存
  • 济南本地网站建设广州定制网站建设公司