[feat] 新增短信验证码下发功能
parent
f9cab79ead
commit
94fa483dd3
|
|
@ -76,6 +76,11 @@
|
|||
<artifactId>ruoyi-common-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.12.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ujcms</groupId>
|
||||
<artifactId>ujcms-commons</artifactId>
|
||||
|
|
@ -89,10 +94,6 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
|
@ -151,6 +152,10 @@
|
|||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
|||
|
|
@ -1,46 +1,84 @@
|
|||
package com.ruoyi.gateway.config.properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 验证码配置
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
@ConfigurationProperties(prefix = "security.captcha")
|
||||
public class CaptchaProperties
|
||||
{
|
||||
/**
|
||||
* 验证码开关
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 验证码类型(math 数组计算 char 字符)
|
||||
*/
|
||||
private String type;
|
||||
|
||||
public Boolean getEnabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled)
|
||||
{
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
package com.ruoyi.gateway.config.properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 验证码配置
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
@ConfigurationProperties(prefix = "security.captcha")
|
||||
public class CaptchaProperties
|
||||
{
|
||||
/**
|
||||
* 验证码开关
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 验证码类型(math 数组计算 char 字符)
|
||||
*/
|
||||
private String type;
|
||||
|
||||
public Boolean getEnabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled)
|
||||
{
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static class SMS {
|
||||
@RefreshScope
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "security.captcha.sms.aliyuncs")
|
||||
public static class Aliyuncs {
|
||||
private String accessKeyId;
|
||||
private String accessKeySecret;
|
||||
private String signName;
|
||||
private String templateCode;
|
||||
public String getAccessKeyId() {
|
||||
return accessKeyId;
|
||||
}
|
||||
public void setAccessKeyId(String accessKeyId) {
|
||||
this.accessKeyId = accessKeyId;
|
||||
}
|
||||
public String getAccessKeySecret() {
|
||||
return accessKeySecret;
|
||||
}
|
||||
|
||||
public void setAccessKeySecret(String accessKeySecret) {
|
||||
this.accessKeySecret = accessKeySecret;
|
||||
}
|
||||
|
||||
public String getSignName() {
|
||||
return signName;
|
||||
}
|
||||
public void setSignName(String signName) {
|
||||
this.signName = signName;
|
||||
}
|
||||
public String getTemplateCode() {
|
||||
return templateCode;
|
||||
}
|
||||
public void setTemplateCode(String templateCode) {
|
||||
this.templateCode = templateCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import java.io.IOException;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ujcms.commons.sms.AliyunUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.FastByteArrayOutputStream;
|
||||
|
|
@ -43,6 +46,9 @@ public class ValidateCodeServiceImpl implements ValidateCodeService
|
|||
@Autowired
|
||||
private CaptchaProperties captchaProperties;
|
||||
|
||||
@Autowired
|
||||
private CaptchaProperties.SMS.Aliyuncs smsAliyuncs;
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
|
|
@ -112,13 +118,21 @@ public class ValidateCodeServiceImpl implements ValidateCodeService
|
|||
return ajax;
|
||||
}
|
||||
// 保存验证码信息
|
||||
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
|
||||
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + receiver + ":" + uuid;
|
||||
long expire = redisService.getExpire(verifyKey);
|
||||
if (expire <= 0) {
|
||||
String code = captchaProducerNumber.createText();
|
||||
redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
|
||||
ajax.put("code", code);
|
||||
expire = redisService.getExpire(verifyKey);
|
||||
AliyunUtils.sendSms(
|
||||
smsAliyuncs.getAccessKeyId(),
|
||||
smsAliyuncs.getAccessKeySecret(),
|
||||
smsAliyuncs.getSignName(),
|
||||
smsAliyuncs.getTemplateCode(),
|
||||
JSONObject.of("code", code),
|
||||
receiver
|
||||
);
|
||||
}
|
||||
ajax.put("expire", expire);
|
||||
ajax.put("uuid", uuid);
|
||||
|
|
|
|||
Loading…
Reference in New Issue