From 04adbe7d46fe4945cc36cf6b74a62f5bcb9be619 Mon Sep 17 00:00:00 2001 From: hsdllcw Date: Thu, 15 Aug 2024 17:21:05 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E9=9D=9E=E7=94=9F=E4=BA=A7=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8D=E5=86=8D=E5=AE=9E=E9=99=85=E4=B8=8B=E5=8F=91?= =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ValidateCodeServiceImpl.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) 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 bef128b90..620727ce8 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 @@ -2,6 +2,7 @@ package com.ruoyi.gateway.service.impl; import java.awt.image.BufferedImage; import java.io.IOException; +import java.util.Arrays; import java.util.concurrent.TimeUnit; import javax.annotation.Resource; import javax.imageio.ImageIO; @@ -9,6 +10,7 @@ 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.core.env.Environment; import org.springframework.stereotype.Service; import org.springframework.util.FastByteArrayOutputStream; import com.google.code.kaptcha.Producer; @@ -49,6 +51,9 @@ public class ValidateCodeServiceImpl implements ValidateCodeService @Autowired private CaptchaProperties.SMS.Aliyuncs smsAliyuncs; + @Autowired + private Environment environment; + /** * 生成验证码 */ @@ -124,14 +129,18 @@ public class ValidateCodeServiceImpl implements ValidateCodeService String code = captchaProducerNumber.createText(); redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); expire = redisService.getExpire(verifyKey); - AliyunUtils.sendSms( - smsAliyuncs.getAccessKeyId(), - smsAliyuncs.getAccessKeySecret(), - smsAliyuncs.getSignName(), - smsAliyuncs.getTemplateCode(), - JSONObject.of("code", code), - receiver - ); + if (Arrays.stream(environment.getActiveProfiles()).toList().contains("prod")) { + AliyunUtils.sendSms( + smsAliyuncs.getAccessKeyId(), + smsAliyuncs.getAccessKeySecret(), + smsAliyuncs.getSignName(), + smsAliyuncs.getTemplateCode(), + JSONObject.of("code", code), + receiver + ); + } else { + ajax.put("captchaCode",code); + } } ajax.put("expire", expire); ajax.put("uuid", uuid);