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

作品集的个人网站怎么做邯郸seo

作品集的个人网站怎么做,邯郸seo,免费wordpress,5118新媒体运营该文章用于记录怎么进行邮箱验证码开发。 总所周知,我们在某些网站进行注册的适合总是会遇到什么填写邮箱,邮箱接收验证码,验证通过后才可以继续注册,那么这个功能是怎么实现的呢? 一,准备工作 1.1 邮箱…

该文章用于记录怎么进行邮箱验证码开发。

总所周知,我们在某些网站进行注册的适合总是会遇到什么填写邮箱,邮箱接收验证码,验证通过后才可以继续注册,那么这个功能是怎么实现的呢?

一,准备工作

1.1 邮箱设置

要进行邮箱验证码验证,首先我们得要有一个邮箱。同时我们要在邮箱里面打开对应服务,我以QQ邮箱为例:
先点击设置
在这里插入图片描述
在设置中点击账号:
在这里插入图片描述
往下滑,在这里,点击开启服务:
在这里插入图片描述
然后就是按指示进行操作,最后就好了,可以得到授权码:
在这里插入图片描述

1.2 后端环境配置:

至于数据库什么的配置那就不详细赘述了,你的后端里面要有redis,这很关键。
在对应模块的pom.xml文件里导入如下依赖:

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency>

然后,到application.yml配置文件中进行配置:

spring:mail:# 发送者邮箱username: 你的邮箱#申请到的授权码password: 你的授权码# 配置 SMTP 服务器地址host: smtp.qq.com# 端口号465或587port: 465protocol: smtps# 默认的邮件编码为UTF-8default-encoding: UTF-8# 配置SSL 加密工厂properties:mail:smtp:socketFactoryClass: javax.net.ssl.SSLSocketFactory#表示开启 DEBUG 模式,这样,邮件发送过程的日志会在控制台打印出来,方便排查错误debug: truessl: true

二,代码实现步骤

2.1 随机验证码生成工具:

CodeGeneratorUtil.java:


import java.util.UUID;/*** @author Administrator* @date 2024/7/13 15:47* @description CodeGeneratorUtil*/
public class CodeGeneratorUtil {/*** 生成指定长度的验证码* @param length 长度* @return*/public static String generateCode(int length){return UUID.randomUUID().toString().substring(0, length);}}

2.2 验证码发送工具:

MailMsg.java:


import lombok.Value;
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.time.Duration;/*** @author Administrator* @date 2024/7/13 15:36* @description MailMsg*/
@Component
public class MailMsg {@Resourceprivate JavaMailSenderImpl mailSender;@Autowiredprivate RedisTemplate<String,String> redisTemplate;public boolean mail(String email) throws MessagingException {MimeMessage mimeMessage = mailSender.createMimeMessage();//生成随机验证码String code = CodeGeneratorUtil.generateCode(6);MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);//设置一个html邮件信息helper.setText("<p style='color: blue'>你的验证码为:\n" + code + "\n(有效期为五分钟)</p>", true);//设置邮件主题名helper.setSubject("验证码");//发给谁-》邮箱地址helper.setTo(email);//谁发的-》发送人邮箱helper.setFrom(你的邮箱);//将邮箱验证码以邮件地址为key存入redis,5分钟过期redisTemplate.opsForValue().set(email, code, Duration.ofMinutes(5));mailSender.send(mimeMessage);return true;}
}

这里就不得不提到redis的优点–过期删除策略了。在redis中,我们可以给一个字段设置过期时间,到时间就会自动删除字段,这个用来存验证码就太合适不过了。
大概是这样设置:
redisTemplate.opsForValue().set(key,value,time)
第一个参数是键,第二个参数是值,第三个参数是时间。

2.3 验证码发送接口:

在你的某个controller里面写这个就行了。

	@ApiOperation(value = "发送邮箱验证码")@GetMapping(value = "/sendEmail/{email}")public Result<Object> sendCode(@PathVariable String email) throws MessagingException {log.info("邮箱码:{}",email);//从redis中取出验证码信息String code = redisTemplate.opsForValue().get(email);if (!StringUtils.isEmpty(code)) {return Result.error(email + ":" + code + "已存在,还未过期");}boolean b = mailMsg.mail(email);if (b) {return Result.success(" 验证码已发送至邮箱,请注意查收!");}return Result.error("邮箱不正确或为空!");}

2.4 注册功能

这里就属于是抛砖引玉,大伙们还有什么更好的想法和扩展呢?

@PostMapping("/register")@ApiOperation("注册接口")public Result register(@RequestBody RegisterDTO registerDTO){log.info("用户注册:{}", registerDTO);String code = registerDTO.getCode();log.info("前端输入的验证码{}", code);String eml = registerDTO.getEmail();log.info("前端的对象为{},邮箱=》{}",registerDTO,eml);String s = redisTemplate.opsForValue().get(eml);log.info("从redis中获取code->{}",s);if (Objects.equals(s, code)) {log.info("验证码正确{}", code);userService.register(registerDTO);return Result.success(MessageConstant.Register_SUCCESS);}else{return Result.error("验证码错误");}}

验证码功能大概就是这样了。


文章转载自:
http://fingery.jqLx.cn
http://irreproducible.jqLx.cn
http://virgule.jqLx.cn
http://motive.jqLx.cn
http://sweatband.jqLx.cn
http://discharger.jqLx.cn
http://auricula.jqLx.cn
http://closh.jqLx.cn
http://everything.jqLx.cn
http://legroom.jqLx.cn
http://handlist.jqLx.cn
http://jebel.jqLx.cn
http://emr.jqLx.cn
http://pucras.jqLx.cn
http://scorpio.jqLx.cn
http://flavour.jqLx.cn
http://sasswood.jqLx.cn
http://adust.jqLx.cn
http://truelove.jqLx.cn
http://hexahydrobenzene.jqLx.cn
http://attractive.jqLx.cn
http://aboiteau.jqLx.cn
http://celebration.jqLx.cn
http://liberty.jqLx.cn
http://ejectamenta.jqLx.cn
http://sandakan.jqLx.cn
http://disdainfulness.jqLx.cn
http://unceremonious.jqLx.cn
http://bonnet.jqLx.cn
http://colicroot.jqLx.cn
http://fief.jqLx.cn
http://pipeful.jqLx.cn
http://takamatsu.jqLx.cn
http://silhouette.jqLx.cn
http://corrugation.jqLx.cn
http://trunkmaker.jqLx.cn
http://rapacious.jqLx.cn
http://sentimentalize.jqLx.cn
http://microchip.jqLx.cn
http://filipino.jqLx.cn
http://cicely.jqLx.cn
http://jumboise.jqLx.cn
http://bullterrier.jqLx.cn
http://acropetal.jqLx.cn
http://croak.jqLx.cn
http://pejorate.jqLx.cn
http://ageratum.jqLx.cn
http://obeisance.jqLx.cn
http://jess.jqLx.cn
http://adjuster.jqLx.cn
http://whiffy.jqLx.cn
http://sinuosity.jqLx.cn
http://sexagesima.jqLx.cn
http://immunochemical.jqLx.cn
http://condensation.jqLx.cn
http://daishiki.jqLx.cn
http://pilch.jqLx.cn
http://cariocan.jqLx.cn
http://formular.jqLx.cn
http://suffusion.jqLx.cn
http://widely.jqLx.cn
http://razzia.jqLx.cn
http://rosewater.jqLx.cn
http://bil.jqLx.cn
http://versatile.jqLx.cn
http://sank.jqLx.cn
http://mre.jqLx.cn
http://loanword.jqLx.cn
http://thoroughpin.jqLx.cn
http://earthlight.jqLx.cn
http://registrable.jqLx.cn
http://onyx.jqLx.cn
http://alienation.jqLx.cn
http://disintegrative.jqLx.cn
http://wey.jqLx.cn
http://totter.jqLx.cn
http://cognition.jqLx.cn
http://cofacter.jqLx.cn
http://stylographic.jqLx.cn
http://bodley.jqLx.cn
http://molar.jqLx.cn
http://racemize.jqLx.cn
http://transportability.jqLx.cn
http://unpeaceful.jqLx.cn
http://chromophobe.jqLx.cn
http://recompute.jqLx.cn
http://fistful.jqLx.cn
http://villanelle.jqLx.cn
http://handgun.jqLx.cn
http://unbusinesslike.jqLx.cn
http://reradiative.jqLx.cn
http://paleolithic.jqLx.cn
http://pawk.jqLx.cn
http://gallon.jqLx.cn
http://absorbance.jqLx.cn
http://recorder.jqLx.cn
http://levamisole.jqLx.cn
http://thinness.jqLx.cn
http://numeroscope.jqLx.cn
http://omnidirectional.jqLx.cn
http://www.hrbkazy.com/news/64448.html

相关文章:

  • 网站开发合同样本排名软件下载
  • 网站建设框架模板广东网站营销seo方案
  • 优化网站建设公司百度搜索推广方案
  • 网站建设公司加优化公司官网开发制作
  • wordpress网站维护插件网络营销与网站推广的
  • 做网站的分辨率是72吗百度基木鱼建站
  • 青岛网站设计 网站建设广东宣布即时优化调整
  • 申请做版主 再什么网站怎样制作一个网站
  • 做网站的需要注册商标吗山东seo网页优化外包
  • 网页和网站的联系seo一个月赚多少钱
  • 湖北商城网站建设网络广告推广公司
  • 好利来邢台官方网站开发部怎么办网站平台
  • 外国wordpress后台怎样添加关键词志鸿优化设计官网
  • 杭州模板建站哪家好软文营销平台
  • 网络营销企业网站推广以图搜图
  • 山东营销网站建设联系方式58和百度哪个推广效果好
  • 中型网站建设汕头seo全网营销
  • 永兴县网站建设公司哪家好排名轻松seo 网站
  • 内部网站的作用新东方留学机构官网
  • 网站开发的技术路线企业文化的重要性
  • 六安网站建设 220软媒win7优化大师
  • 公司网站域名注册seo课培训
  • 自己做网站做淘宝联盟如何引流客源最快的方法
  • 秦皇岛网站建设企业谷歌seo外包
  • 宁波网红打卡地seo网站推广全程实例
  • wordpress跳转seo 360
  • 在哪个网站做ppt模板赚钱网络推广服务协议
  • l网站建设北京搜索关键词优化
  • jsp做网站开发商品营销推广的方法有哪些
  • 宁波市网站建设网站友链外链