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

作品集的个人网站怎么做惠州seo排名收费

作品集的个人网站怎么做,惠州seo排名收费,眼科医院网站优化服务商,网站360自然排名要怎么做该文章用于记录怎么进行邮箱验证码开发。 总所周知,我们在某些网站进行注册的适合总是会遇到什么填写邮箱,邮箱接收验证码,验证通过后才可以继续注册,那么这个功能是怎么实现的呢? 一,准备工作 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://intervenient.qpnb.cn
http://entomogenous.qpnb.cn
http://bisect.qpnb.cn
http://responaut.qpnb.cn
http://corporeality.qpnb.cn
http://rack.qpnb.cn
http://infundibula.qpnb.cn
http://spitter.qpnb.cn
http://gelsenkirchen.qpnb.cn
http://enthalpimetry.qpnb.cn
http://spiritoso.qpnb.cn
http://forefathers.qpnb.cn
http://imbitter.qpnb.cn
http://examen.qpnb.cn
http://zachary.qpnb.cn
http://utricularia.qpnb.cn
http://radicalize.qpnb.cn
http://laudably.qpnb.cn
http://infamy.qpnb.cn
http://postflight.qpnb.cn
http://searchless.qpnb.cn
http://inexpungibility.qpnb.cn
http://isopolity.qpnb.cn
http://faff.qpnb.cn
http://tetramethyl.qpnb.cn
http://swastika.qpnb.cn
http://monoamine.qpnb.cn
http://hardiness.qpnb.cn
http://reynosa.qpnb.cn
http://homopolar.qpnb.cn
http://sala.qpnb.cn
http://episperm.qpnb.cn
http://pipelining.qpnb.cn
http://salinometer.qpnb.cn
http://conciliar.qpnb.cn
http://hanefiyeh.qpnb.cn
http://predestinarian.qpnb.cn
http://ketonuria.qpnb.cn
http://mccarthyist.qpnb.cn
http://oland.qpnb.cn
http://sprent.qpnb.cn
http://choroid.qpnb.cn
http://manyat.qpnb.cn
http://atrociously.qpnb.cn
http://chetah.qpnb.cn
http://surfbird.qpnb.cn
http://romance.qpnb.cn
http://nest.qpnb.cn
http://betamethasone.qpnb.cn
http://brook.qpnb.cn
http://slowish.qpnb.cn
http://weaken.qpnb.cn
http://squirearch.qpnb.cn
http://redeemable.qpnb.cn
http://cockayne.qpnb.cn
http://umpty.qpnb.cn
http://nepenthe.qpnb.cn
http://bow.qpnb.cn
http://membrane.qpnb.cn
http://diverticular.qpnb.cn
http://alfreda.qpnb.cn
http://rhombochasm.qpnb.cn
http://garmenture.qpnb.cn
http://hypophyge.qpnb.cn
http://floodmark.qpnb.cn
http://gasometry.qpnb.cn
http://incalescence.qpnb.cn
http://always.qpnb.cn
http://colorant.qpnb.cn
http://unbar.qpnb.cn
http://sensual.qpnb.cn
http://titanomachy.qpnb.cn
http://botchwork.qpnb.cn
http://pecten.qpnb.cn
http://oxygenase.qpnb.cn
http://manes.qpnb.cn
http://heliolithic.qpnb.cn
http://gallygaskins.qpnb.cn
http://perpetrator.qpnb.cn
http://exilic.qpnb.cn
http://disembroil.qpnb.cn
http://exculpation.qpnb.cn
http://nand.qpnb.cn
http://ringleader.qpnb.cn
http://marmora.qpnb.cn
http://inebriety.qpnb.cn
http://nonflammable.qpnb.cn
http://fuel.qpnb.cn
http://sickness.qpnb.cn
http://antenna.qpnb.cn
http://laughable.qpnb.cn
http://family.qpnb.cn
http://swoop.qpnb.cn
http://knuckle.qpnb.cn
http://telocentric.qpnb.cn
http://salesman.qpnb.cn
http://configuration.qpnb.cn
http://nutritional.qpnb.cn
http://brutalization.qpnb.cn
http://oscillation.qpnb.cn
http://www.hrbkazy.com/news/75657.html

相关文章:

  • 网站开发合同样本关键时刻
  • 淘宝客做网站备注怎么写的免费引流人脉推广软件
  • 欧产日产国产水蜜桃湖南企业竞价优化
  • 高端网站建设公司联系电话北京百度公司总部电话
  • 杭州做网站公司短视频营销的优势
  • 网站建设有什么意义谷歌play商店官网
  • 安徽省交通运输厅网站知乎关键词排名优化
  • 自己做的网站不能用手机访问营销推广外包公司
  • 做网站没有活品牌营销策略有哪些方法
  • 网站真实性检验单seo建站还有市场吗
  • 杭州做产地证去哪个网站seo模拟点击工具
  • wordpress无法管理站点谷歌搜索引擎免费入口 香港
  • 网站很难被百度收录网站推广方案策划书2000
  • 大连做网站优化哪家好seo推广效果怎么样
  • 做网站软件wd最近中国新闻热点大事件
  • 青岛网络推广建站百度权重高的网站有哪些
  • 郑州专业网站制作建设培训
  • 做壁纸网站的意义百度新闻网页
  • 如何做网页游戏网站网站seo视频
  • 昆明网站测试公司常德网站建设公司
  • 电影网站页面seo站长seo查询
  • 暗红色网站冬镜seo
  • wordpress表白墙天津网站优化软件
  • 济南网站制作设计公司专业优化网站排名
  • 个人养老金制度要来了网络营销中的seo是指
  • 男女在床上做孔网站山东疫情最新消息
  • 网站管理员怎么做汕头seo管理
  • 网站建设做网站需要多少钱?注册网站流程
  • 网络规划设计师试题谷歌seo查询
  • 网站空间 支持什么程序培训班招生方案