发送短信验证码
发送短信验证码
REAI选择短信接入服务商
服务商
- 阿里云短信
- 腾讯云短信
- 百度云SMS
荣联云通讯
接入步骤
- 注册开发者账号
- 创建应用
- 对接测试
- 上线运营
1.注册云通讯账号:https://www.yuntongxun.com/
2.设置平台测试号码
SDK
sdk+md5: https://www.lanzouw.com/imDFWvwq8tg
发送短信验证码
1 | <!--云通讯 Java SMS SDK--> |
service
创建用户,生成验证码(1111-9999),发送验证码,缓存验证码到redis
1 | //创建用户 |
serviceImpl
1 |
|
1 | //手机短信验证 |
controller
1 | //手机注册 |
输入手机号,密码 ,名字测试
1 http://localhost:8081/auth/api/registerByPhone
1
2
3
4
5 {
"userCode": "13663797602",
"userName": "asd",
"userPassword": "123"
}
1
2
3
4
5
6
7
8
9 ==> Preparing: INSERT INTO itrip_user ( usercode, userpassword, username ) VALUES ( ?, ?, ? )
==> Parameters: 13663797602(String), 202cb962ac59075b964b07152d234b70(String), asd(String)
<== Updates: 1
phone==>13663797602
result==>{data={templateSMS={dateCreated=20211029161603, smsMessageSid=c3f097fa6fca4d06a9105f2dd3bfbc8d}}, statusCode=000000}
短信发送成功!
2111
验证码存入redis服务器
验证短信验证码
1 http://localhost:8081/auth/api/validatephone?code=2111&user=13663797602
1
2
3
4
5
6
7 对比验证码=>2111
==> Preparing: SELECT id,usercode,userpassword,usertype,flatid,username,wechat,qq,weibo,baidu,creationdate,createdby,modifydate,modifiedby,activated FROM itrip_user WHERE userCode = ?
==> Parameters: 13663797602(String)
<== Columns: id, usercode, userpassword, usertype, flatid, username, wechat, qq, weibo, baidu, creationdate, createdby, modifydate, modifiedby, activated
<== Row: 77, 13663797602, 202cb962ac59075b964b07152d234b70, null, null, asd, null, null, null, null, null, null, null, null, null
<== Total: 1验证码正确更新用户激活状态
1
2
3 ==> Preparing: UPDATE itrip_user SET usercode=?, userpassword=?, usertype=?, flatid=?, username=?, activated=? WHERE id=?
==> Parameters: 13663797602(String), 202cb962ac59075b964b07152d234b70(String), 0(Integer), 77(Long), asd(String), 1(Integer), 77(Long)
<== Updates: 1验证成功
1
2
3
4
5 {
"code": 200,
"message": "验证成功",
"data": null
}
邮箱验证码
引入邮箱依赖
1 | <!--email依赖--> |
配置yml
1 | spring: |
发送方必须要开启smtp,获取到的授权码,QQ邮箱获取授权码方法:
https://service.mail.qq.com/cgi-bin/help?subtype=1&&no=1001256&&id=28
EmailMessage
邮件发送接口主要使用JavaMailSender
参数说明:
subject :邮件主题
content :邮件主题内容
from:发件人Email地址
to:收件人Email地址
1 | package com.ytzl.util; |
service
1 | //发送 |
serviceImpl
1 |
|
controller
1 | //邮箱注册 |
评论
匿名评论隐私政策