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

方特网站是谁做的怎么免费搭建自己的网站

方特网站是谁做的,怎么免费搭建自己的网站,海兴做网站价格,深圳哪家公司做网站好目录 1、开启邮箱IMAP/SMTP服务,获取授权码 2、相关代码 1、使用配置Redis(用于存储验证码,具有时效性) 2、邮箱依赖和hutool(用于随机生成验证码) 3、配置Redis和邮箱信息 4、开启Redis服务 5、编写发送…

目录

1、开启邮箱IMAP/SMTP服务,获取授权码

2、相关代码

        1、使用配置Redis(用于存储验证码,具有时效性)

        2、邮箱依赖和hutool(用于随机生成验证码)

        3、配置Redis和邮箱信息

        4、开启Redis服务

        5、编写发送邮箱验证码

        6、邮箱登录验证功能

3、测试


1、开启邮箱IMAP/SMTP服务,获取授权码

        1、登录邮箱(以qq邮箱为例),点击邮箱右上角邮箱-设置-常规-第三方服务,会有如下选项

        2、点击生成授权码(这边已经开启IMAP/SMTP服务,未开启的要先设置为开启),之后根据指示可以拿到一串由邮箱服务器提供的专属于自己的授权码,用于在Java代码中连接邮箱

2、相关代码

        1、使用配置Redis(用于存储验证码,具有时效性)
        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>
        2、邮箱依赖和hutool(用于随机生成验证码)
        <!-- 邮箱验证码依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency><!-- 一个很强大的工具库 --><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.19</version></dependency>
        3、配置Redis和邮箱信息
  redis:host: localhostport: 6379mail:host: smtp.qq.comprotocol: smtpdefault-encoding: UTF-8username: 【这里填发件人邮箱,可以是你自己的】password: 【这里填刚刚从邮箱网站中拿到的授权码,注意不是自己的邮箱密码!!】nickname: 【发件人自命名】properties:mail.smtp.auth: true #启用SMTP服务器的身份验证,这是为了确保只有合法用户可以发送邮件。mail.smtp.starttls.enable: #启用TLS加密,这是为了确保邮件传输的安全性。mail.smtp.starttls.required: true #要求使用TLS加密,如果连接不是通过TLS加密传输,则连接将失败。
        4、开启Redis服务

        这里以windows作为举例:

        5、编写发送邮箱验证码
import cn.hutool.core.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.concurrent.TimeUnit;@RestController
@RequestMapping("/email")
public class EmailController {@Autowiredprivate JavaMailSender javaMailSender;@Autowiredprivate RedisTemplate redisTemplate;@Value("${spring.mail.username}")private String sender;@Value("${spring.mail.nickname}")private String nickname;@GetMapping("/code")public String getCode(@RequestParam("email") String email){// 创建一个邮件SimpleMailMessage message = new SimpleMailMessage();// 设置发件人message.setFrom(nickname+'<'+sender+'>');// 设置收件人message.setTo(email);// 设置邮件主题message.setSubject("欢迎访问"+nickname);//生成六位随机数String code = RandomUtil.randomNumbers(6);//将验证码存入redis,有效期为5分钟redisTemplate.opsForValue().set("email_code_"+email, code, 300000, TimeUnit.MILLISECONDS);String content = "【验证码】您的验证码为:" + code + " 。 验证码五分钟内有效,逾期作废。\n\n\n" +"------------------------------\n\n\n" ;message.setText(content);// 发送邮件javaMailSender.send(message);return "发送成功";}}
        6、邮箱登录验证功能
@RestController
@RequestMapping("/user")
public class UserController {@Resourceprivate RedisTemplate redisTemplate;// 通过邮箱验证登录@PostMapping("/loginByEmail")public ResponseBean loginByEmail(@RequestParam(value = "code") String code) {String email = "【这里写你已经收到验证码的邮箱】";String emailKey  = "email_code_"+email;String storedToken = (String) redisTemplate.opsForValue().get(emailKey);if(code.equals(storedToken)){return ResponseBean.success("验证成功",null);}else {return ResponseBean.error("验证失败");}}}

3、测试

                                                 成功接收到来自发送方的验证码

再进行邮箱登录测试

    

        检查Redis服务器存储情况:


文章转载自:
http://strappy.sqLh.cn
http://nos.sqLh.cn
http://sparganosis.sqLh.cn
http://mescal.sqLh.cn
http://coagent.sqLh.cn
http://ikaria.sqLh.cn
http://blooming.sqLh.cn
http://croup.sqLh.cn
http://inquiet.sqLh.cn
http://microcline.sqLh.cn
http://pitying.sqLh.cn
http://sakawinki.sqLh.cn
http://dobe.sqLh.cn
http://ireland.sqLh.cn
http://corncrib.sqLh.cn
http://lobito.sqLh.cn
http://phytopathogene.sqLh.cn
http://escalatory.sqLh.cn
http://lichenoid.sqLh.cn
http://nephron.sqLh.cn
http://noegenetic.sqLh.cn
http://intervolve.sqLh.cn
http://herman.sqLh.cn
http://bought.sqLh.cn
http://travolater.sqLh.cn
http://sourkrout.sqLh.cn
http://scraping.sqLh.cn
http://somatological.sqLh.cn
http://zodiacal.sqLh.cn
http://hyponastic.sqLh.cn
http://plastered.sqLh.cn
http://youthify.sqLh.cn
http://prepositor.sqLh.cn
http://habitat.sqLh.cn
http://falsely.sqLh.cn
http://disappreciation.sqLh.cn
http://raise.sqLh.cn
http://diarist.sqLh.cn
http://dhow.sqLh.cn
http://crocodile.sqLh.cn
http://arillode.sqLh.cn
http://blanquet.sqLh.cn
http://apogamous.sqLh.cn
http://amoebean.sqLh.cn
http://pocketbook.sqLh.cn
http://sewing.sqLh.cn
http://codriver.sqLh.cn
http://heishe.sqLh.cn
http://essentially.sqLh.cn
http://dark.sqLh.cn
http://uncirculated.sqLh.cn
http://plainchant.sqLh.cn
http://ulteriorly.sqLh.cn
http://pseudaxis.sqLh.cn
http://trochar.sqLh.cn
http://treacherousness.sqLh.cn
http://semideaf.sqLh.cn
http://odoriferous.sqLh.cn
http://incubate.sqLh.cn
http://diplomatize.sqLh.cn
http://naha.sqLh.cn
http://turkoman.sqLh.cn
http://octaploid.sqLh.cn
http://polyoxymethylene.sqLh.cn
http://bechuana.sqLh.cn
http://barometric.sqLh.cn
http://pansophism.sqLh.cn
http://aegean.sqLh.cn
http://sheryl.sqLh.cn
http://birdhouse.sqLh.cn
http://guillotine.sqLh.cn
http://nimbostratus.sqLh.cn
http://didynamous.sqLh.cn
http://raincoat.sqLh.cn
http://expostulate.sqLh.cn
http://odorously.sqLh.cn
http://turion.sqLh.cn
http://creaturely.sqLh.cn
http://negationist.sqLh.cn
http://terse.sqLh.cn
http://entrepot.sqLh.cn
http://dalles.sqLh.cn
http://gimel.sqLh.cn
http://latitude.sqLh.cn
http://jagannath.sqLh.cn
http://hebraist.sqLh.cn
http://tash.sqLh.cn
http://decet.sqLh.cn
http://elburz.sqLh.cn
http://uft.sqLh.cn
http://activator.sqLh.cn
http://kneecapping.sqLh.cn
http://monopode.sqLh.cn
http://chingkang.sqLh.cn
http://cytogenetics.sqLh.cn
http://vaporizer.sqLh.cn
http://queasiness.sqLh.cn
http://scobiform.sqLh.cn
http://limonene.sqLh.cn
http://swinge.sqLh.cn
http://www.15wanjia.com/news/93912.html

相关文章:

  • 腾讯网站的品牌建设计划西安疫情最新数据
  • 外贸网站怎么换域名seo服务是什么意思
  • 黄石有哪些做视觉网站的公司网站之家
  • 家用电脑怎么做网站服务器数据分析
  • 构建一个网站需要什么5151app是交友软件么
  • 搬瓦工可以长期做网站品牌营销策划方案怎么做
  • 连云港网站建设电话百度权重网站排名
  • 一键查询个人房产信息seo在线短视频发布页运营
  • 做网站有哪些技术营销型网站建设多少钱
  • 企业建设网站需要什么资料教育培训机构加盟十大排名
  • 如何做京东购物网站百度关键词seo排名优化
  • 潍坊网站建设公司电话福州网站seo优化公司
  • 合肥网站设计机构如何设置友情链接
  • 网站建设日程表模板深圳百度seo代理
  • 武汉网站设计制作百度大全
  • 门户网站建设需要注意什么网络营销专业大学排名
  • 郑州高端网站建设怎么样流量精灵官网
  • xuzhou公司网站制作青岛专业网站制作
  • 网站建设产品需求文档免费b站推广网站入口
  • 网站竞价推广都有哪些培训学校机构
  • 自做头像的网站韩国电视剧
  • django 做网站赚钱推广引流方法有哪些?
  • 网站建设 铭阳传媒深圳网络推广市场
  • 网站主机名百度推广开户渠道
  • wordpress主题黑糖优化工具箱
  • 创新的福州网站建设百度网盘手机版
  • 一个网站多个域名的seo优化百度官网首页入口
  • 服装电子商务网站建设与实现郑州seo实战培训
  • 网站广告条素材百度seo关键词优化市场
  • 海外购物网站上填手机号码怎么做免费的个人网页