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

科研网站建设营销是做什么

科研网站建设,营销是做什么,网站怎么做不违法,wordpress 列表分类链接 v1.3SpringBoot集成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://www.dtcms.com/wzjs/7956.html

相关文章:

  • 企业网站建设专业精准乙 鸣远科技免费搭建网站平台
  • 制作app的费用广州百度推广排名优化
  • 什么是软件外包公司seo建站收费地震
  • 广告网站建设及推广百度搜索网站排名
  • 网页设计的交流网站软文推广文章
  • 外贸网页制作公司网络营销优化推广公司
  • 北京网站建设亿玛酷出名5淘宝关键词搜索
  • 海南省建设工程质量监督网站seo中国
  • 网站建设经验典型站长工具是做什么的
  • 宁波做网站优化多少钱百度官网app下载
  • 如何做pdf电子书下载网站成都短视频代运营
  • 合肥做网站首选 晨飞网络seo推广招聘
  • 做网站要注册那些商标北京优化网站建设
  • 网站图标怎么换天津网站建设优化
  • 如何创建电子商务网站站长工具ip地址查询
  • 网站建设及运维合同百度网络推广怎么收费
  • 团风做网站aso优化服务站
  • 桐城网站建设网推获客平台
  • 做美女网站流量seo挂机赚钱
  • 专业购物网站建设报价网络营销经典案例
  • 贵州省住房和城乡建设厅官网站首页外贸网站平台都有哪些 免费的
  • 国产做的视频网站百度关键词推广网站
  • 深圳网站建制作网络营销是学什么
  • 日本做设计的网站有哪些方面武汉seo网站推广培训
  • wordpress页面第一次访问被劫持cpu优化软件
  • 商业网站建设知识点灰色产业推广引流渠道
  • 中山企业网站建设公司百度搜索数据
  • 东莞互联网营销网站建设推广形式
  • 做网站怎么电话约客户视频剪辑培训班
  • 城北区建设局网站关键词搜索点击软件