[feat] 非生产环境不再实际下发短信验证码

pull/445/head
hsdllcw 2024-08-15 17:21:05 +08:00
parent de924c7ee0
commit 04adbe7d46
1 changed files with 17 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package com.ruoyi.gateway.service.impl;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
@ -9,6 +10,7 @@ import javax.imageio.ImageIO;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.ujcms.commons.sms.AliyunUtils; import com.ujcms.commons.sms.AliyunUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.FastByteArrayOutputStream; import org.springframework.util.FastByteArrayOutputStream;
import com.google.code.kaptcha.Producer; import com.google.code.kaptcha.Producer;
@ -49,6 +51,9 @@ public class ValidateCodeServiceImpl implements ValidateCodeService
@Autowired @Autowired
private CaptchaProperties.SMS.Aliyuncs smsAliyuncs; private CaptchaProperties.SMS.Aliyuncs smsAliyuncs;
@Autowired
private Environment environment;
/** /**
* *
*/ */
@ -124,14 +129,18 @@ public class ValidateCodeServiceImpl implements ValidateCodeService
String code = captchaProducerNumber.createText(); String code = captchaProducerNumber.createText();
redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
expire = redisService.getExpire(verifyKey); expire = redisService.getExpire(verifyKey);
AliyunUtils.sendSms( if (Arrays.stream(environment.getActiveProfiles()).toList().contains("prod")) {
smsAliyuncs.getAccessKeyId(), AliyunUtils.sendSms(
smsAliyuncs.getAccessKeySecret(), smsAliyuncs.getAccessKeyId(),
smsAliyuncs.getSignName(), smsAliyuncs.getAccessKeySecret(),
smsAliyuncs.getTemplateCode(), smsAliyuncs.getSignName(),
JSONObject.of("code", code), smsAliyuncs.getTemplateCode(),
receiver JSONObject.of("code", code),
); receiver
);
} else {
ajax.put("captchaCode",code);
}
} }
ajax.put("expire", expire); ajax.put("expire", expire);
ajax.put("uuid", uuid); ajax.put("uuid", uuid);