wap视频网站,如何自己建网站,做淘宝类网站,学校网站开发价格写在最前
如果这个项目让你有所收获#xff0c;记得 Star 关注哦#xff0c;这对我是非常不错的鼓励与支持。
源码地址#xff08;后端#xff09;#xff1a;https://gitee.com/csps/mingyue
源码地址#xff08;前端#xff09;#xff1a;https://gitee.com/csps…写在最前
如果这个项目让你有所收获记得 Star 关注哦这对我是非常不错的鼓励与支持。
源码地址后端https://gitee.com/csps/mingyue
源码地址前端https://gitee.com/csps/mingyue-ui
文档地址https://gitee.com/csps/mingyue/wikis
阿里云短信
需要注册一个阿里云账号进入阿里云短信服务的控制台选择快速学习和测试https://dysms.console.aliyun.com/quickstart 发送验证码
引入依赖
!-- 短信工具 --
dependencygroupIdcom.csp.mingyue/groupIdartifactIdmingyue-common-sms/artifactId
/dependency
!-- 阿里云短信依赖 --
dependencygroupIdcom.aliyun/groupIdartifactIddysmsapi20170525/artifactId
/dependencyNacos 短信配置 accessKeyId阿里云 AccessKey ID accessKeySecret阿里云 AccessKey Secret signName阿里云签名名称 sms:enabled: trueendpoint: dysmsapi.aliyuncs.comaccessKeyId: xxxaccessKeySecret: xxxsignName: 阿里云短信测试短信配置类
Data
ConfigurationProperties(prefix sms)
public class SmsProperties {private Boolean enabled;/*** 配置节点 阿里云 dysmsapi.aliyuncs.com*/private String endpoint;/*** key*/private String accessKeyId;/*** 密匙*/private String accessKeySecret;/** 短信签名*/private String signName;}注册配置类
/*** 短信配置类** author Strive* date 2023/8/25 10:04*/
AutoConfiguration
EnableConfigurationProperties(SmsProperties.class)
public class SmsAutoConfiguration {ConfigurationConditionalOnProperty(value sms.enabled, havingValue true)ConditionalOnClass(com.aliyun.dysmsapi20170525.Client.class)static class AliyunSmsConfiguration {Beanpublic SmsTemplate aliyunSmsTemplate(SmsProperties smsProperties) {return new AliyunSmsTemplate(smsProperties);}}}短信接口 String templateId “”; templateId阿里云模版Code例如SMS_154950909 /*** 短信验证码* param phone 用户手机号*/GetMapping(/code)Operation(summary 短信验证码, parameters { Parameter(name phone, description 手机号, required true) })public RVoid smsCaptcha(NotBlank(message 手机号不能为空) String phone) {if (!smsProperties.getEnabled()) {return R.fail(当前系统没有开启短信功能);}String key CacheConstants.CAPTCHA_CODE_KEY phone;String code RandomUtil.randomNumbers(4);redisTemplate.opsForValue().set(key, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);log.info(验证码短信「{}」发送至手机「{}」 {}, code, phone);// 验证码模板 ID 暂时可以写死String templateId ;MapString, String map new HashMap(1);map.put(code, code);SmsTemplate smsTemplate SpringUtils.getBean(SmsTemplate.class);SmsResult result smsTemplate.send(phone, templateId, map);if (!result.getIsSuccess()) {log.error(验证码短信发送异常 {}, result);return R.fail(result.getMessage());}return R.ok();
}发送测试
手机接收到短信即可
小结
现在短信验证码已经可以推送至手机上了接下来修改短信登录通过手机号发送短信验证码然后登录