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

做网站通常用的软件百中搜优化软件

做网站通常用的软件,百中搜优化软件,销售软件有哪些,网站素材免费下载⛰️个人主页: 蒾酒 🔥系列专栏:《spring boot实战》 🌊山高路远,行路漫漫,终有归途。 目录 前置条件 内容简介 图形验证码接口实现 导入糊涂工具依赖 接口分析 编写验证码接口 测试验证码接口 前置条件 …

⛰️个人主页:     蒾酒

🔥系列专栏:《spring boot实战》

🌊山高路远,行路漫漫,终有归途。


目录

前置条件

内容简介

图形验证码接口实现

导入糊涂工具依赖

接口分析

编写验证码接口

测试验证码接口


前置条件

本文衔接上文,请从上文开始

spring boot3x登录开发-上(整合jwt)-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/qq_62262918/article/details/135964626?spm=1001.2014.3001.5502

内容简介

上文我们已经整合好了jwt,本文我们开始实现图形验证码接口的实现。

  • 通过糊涂工具包的图形验证码工具完成获取验证码接口
  • 通过redis缓存key(验证码id)-value(验证码内容)

图形验证码接口实现

导入糊涂工具依赖

pom.xml:

<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.25</version>
</dependency>

接口分析

前端的登录表单有个验证码id字段,第一次打开登录页面默认会请求验证码接口,那么后端验证码接口将返回验证码图片的base64编码和验证码id,前端需要将验证码id保存到表单对象的验证码id字段,同时把验证码图片显示。用户填写账密、验证码点击登录,表单对象将携带账密和验证码id和用户键入的验证码内容提交到后端,后端需要根据此验证码id去查redis跟用户提交的比对

分析完我们就可以知道怎样设计这个接口了。

接口接收一个验证码id参数,判断这个参数如果是null则生成一个验证码id,不为null则直接拿它去生成redis缓存验证码内容的key,接着将验证码图片同id返回给前端。

 首先定义验证码接口数据对象

import lombok.Builder;
import lombok.Data;/*** @author mijiupro*/
@Data
@Builder
public class CaptchaVO {//验证码idprivate  String captchaId;//验证码图片base64编码private  String captchaImage;
}

编写验证码接口

这里用到了redis,需要整合好:

Spring Boot3整合Redis-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/qq_62262918/article/details/136067550?spm=1001.2014.3001.5501

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import com.mijiu.commom.model.vo.CaptchaVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;/*** @author mijiupro*/
@RestController
@RequestMapping("/Captcha")
@Tag(name = "验证码接口", description = "验证码接口相关操作")
public class CaptchaController {private final StringRedisTemplate stringRedisTemplate;public CaptchaController(StringRedisTemplate stringRedisTemplate) {this.stringRedisTemplate = stringRedisTemplate;}@GetMapping("/graph-captcha")@Operation(summary = "获取验证码")public CaptchaVO getCaptcha(String captchaId) {// 创建一个图像验证码宽度为130,高度为48,包含4个字符,干扰线10个CircleCaptcha circleCaptcha = CaptchaUtil.createCircleCaptcha(130, 48, 4, 10);// 获取验证码的文本String captchaText = circleCaptcha.getCode();// 获取验证码图片的Base64编码String captchaImageBase64Data = circleCaptcha.getImageBase64Data();// 如果没有传入captchaId,则生成一个随机字符串作为captchaIdcaptchaId = Optional.ofNullable(captchaId).orElseGet(() -> UUID.randomUUID().toString());// 保存验证码文本到Redis中,有效期30秒stringRedisTemplate.opsForValue().set("captcha:" + captchaId, captchaText, 30, TimeUnit.SECONDS);return CaptchaVO.builder().captchaId(captchaId).captchaImage(captchaImageBase64Data).build();}}

测试验证码接口

这里使用Knife4jConfig(swigger3)测试,也可以用浏览器地址栏、Postman等测试

Spring Boot3整合knife4j(swagger3)_springboot3 knife4j-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/qq_62262918/article/details/135761392?spm=1001.2014.3001.5502

http://www.zhongyajixie.com/news/52137.html

相关文章:

  • 做网站 有哪些问题一个企业该如何进行网络营销
  • 有口碑的镇江网站优化关键词搜索爱站网
  • 广东做网站优化公司报价关键词排名网站
  • 武汉网站关键词推广枫树seo网
  • 如何解析网站网站查询ip地址查询
  • 关键词优化排名用哪些软件比较好seo黑帽培训
  • 网页设计培训好吗澳门seo关键词排名
  • 服务器有了网站怎么做湖南企业seo优化首选
  • 网站从新建设影响收录么google关键词优化排名
  • 旅游网站推广方案比较好网站制作公司
  • 深圳建网站多少钱如何优化搜索引擎
  • 郑州市网站空间服务公司seo资讯推推蛙
  • 香港服务器做网站搜索引擎网站入口
  • 海口网站制作方案网络营销属于什么专业类型
  • 做肮脏交义的网站百度后台管理
  • 国内做的好看的网站设计网站建设步骤
  • 重庆做网站及公众号公司关键字排名优化工具
  • WordPress三大标签插件郑州seo关键词优化公司
  • 网站域名做链接怎么做友点企业网站管理系统
  • 网站做效果联系方式店铺在百度免费定位
  • 商城公众号开发整站优化加盟
  • 做的比较好的二手交易网站cms快速建站
  • 什么静态网站容易做成人专业技能培训机构
  • 网站做聚合是啥意思企业全网推广公司
  • 深圳做网站优化费用网络营销分析报告
  • 优化网站排名方法免费二级域名建站
  • 使用网站效果图com天堂网
  • 南宁品牌网站建设企业网络策划
  • 做网站主要显哪些内容软文范例800字
  • 全国公安网站备案微信营销的10种方法技巧