diff --git a/ruoyi-gateway/pom.xml b/ruoyi-gateway/pom.xml index 7cbcdbcde..8839061e7 100644 --- a/ruoyi-gateway/pom.xml +++ b/ruoyi-gateway/pom.xml @@ -76,6 +76,11 @@ ruoyi-common-redis + + com.squareup.okhttp3 + okhttp + 3.12.13 + com.ujcms ujcms-commons @@ -89,10 +94,6 @@ org.springframework spring-web - - com.squareup.okhttp3 - okhttp - @@ -151,6 +152,10 @@ + + 16 + 16 + diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/properties/CaptchaProperties.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/properties/CaptchaProperties.java index dea2e1685..0b15361c2 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/properties/CaptchaProperties.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/properties/CaptchaProperties.java @@ -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; + } + } + } +} diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/service/impl/ValidateCodeServiceImpl.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/service/impl/ValidateCodeServiceImpl.java index d2d169429..60a5da521 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/service/impl/ValidateCodeServiceImpl.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/service/impl/ValidateCodeServiceImpl.java @@ -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);