当前位置: 首页 > 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.yidumall.com/news/83859.html

相关文章:

  • 网站建设意义必要性巨量算数关键词查询
  • 我做的静态网站怎么发布到网上seo职位
  • 搜索引擎网站推广可以自己做吗查询网址域名
  • 陕西省建设网信息截图营销推广seo
  • 云南网站建设电话经典软文推广案例
  • 佛山市手机网站建设哪家好seo搜索是什么意思
  • 公司宣传网站建设推广官网
  • 招聘网站做沙龙百度推广电话
  • 建筑公司名称起名大全sem推广优化
  • 做网站需求 后期方便优化百度推广网站平台
  • 保定网站网站建设正规seo多少钱
  • 郑州网站建设推广优化全国疫情排行榜
  • 舟山建设银行网站山西疫情最新情况
  • 柬埔寨网站开发北京百度推广代理公司
  • 做网站哪里有seo网络营销招聘
  • 微信公众平台怎么做微网站拼多多代运营公司十大排名
  • 开个做网站的公司 知乎如何做好平台推广
  • ppt网站超链接怎么做网络舆情处置的五个步骤
  • wordpress 2.9下载seo排名优化公司
  • 古交市住房和城乡建设局网站百度一下就知道百度首页
  • 滕州个人兼职做网站杭州网站推广公司
  • 政府网站建设回顾互联网营销策划
  • 网站中队人物介绍怎么做百度权重10的网站
  • 用php做网站用什么框架国际网站平台有哪些
  • wordpress图片付费主题网站优化流程
  • 泉州全网营销优化企业站seo
  • 如何给网站做快速排名推广普通话内容100字
  • 海外网站代理免费b站推广入口
  • 深圳门户网站建设特点亚马逊站外推广网站
  • 安徽网站seo免费域名注册