diff --git a/cloud-manager-sms/src/main/java/com/cm/manager/sms/config/properties/SmsProperties.java b/cloud-manager-sms/src/main/java/com/cm/manager/sms/config/properties/SmsProperties.java index 68c2728..15f8f40 100644 --- a/cloud-manager-sms/src/main/java/com/cm/manager/sms/config/properties/SmsProperties.java +++ b/cloud-manager-sms/src/main/java/com/cm/manager/sms/config/properties/SmsProperties.java @@ -17,10 +17,19 @@ import org.springframework.context.annotation.Configuration; @ConfigurationProperties(prefix = "sms") public class SmsProperties { + private Boolean active; private String type; private SmsDefaultProperties defaultSms; private SmsTencentProperties tencentSms; + public Boolean getActive() { + return active == null ? true : active; + } + + public void setActive(Boolean active) { + this.active = active; + } + public String getType() { return type == null ? "" : type.trim(); } @@ -48,8 +57,10 @@ public class SmsProperties { @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); - sb.append("\"type\":") - .append("\"").append(type).append("\""); + sb.append("\"active\":") + .append(active); + sb.append(",\"type\":\"") + .append(type).append('\"'); sb.append(",\"defaultSms\":") .append(defaultSms); sb.append(",\"tencentSms\":") diff --git a/cloud-manager-sms/src/main/java/com/cm/manager/sms/service/impl/SmsServiceImpl.java b/cloud-manager-sms/src/main/java/com/cm/manager/sms/service/impl/SmsServiceImpl.java index 6682eff..b9f2f5c 100644 --- a/cloud-manager-sms/src/main/java/com/cm/manager/sms/service/impl/SmsServiceImpl.java +++ b/cloud-manager-sms/src/main/java/com/cm/manager/sms/service/impl/SmsServiceImpl.java @@ -180,6 +180,9 @@ public class SmsServiceImpl extends AbstractService implements ISmsService { @Override public void saveSms(String phone, String content) throws Exception { LOG.info(">>>>> 向手机号:{},发送短信:{}", phone, content); + if (!smsProperties.getActive()) { + return; + } if (StringUtils.equals(TENCENT_TYPE, smsProperties.getType())) { tencentSms(phone, content); } else { @@ -218,12 +221,14 @@ public class SmsServiceImpl extends AbstractService implements ISmsService { private void sendCode(String phone, String code) throws Exception { LOG.info(">>>>> 向手机号:{},发送验证码:{}", phone, code); + if (!smsProperties.getActive()) { + return; + } if (StringUtils.equals(TENCENT_TYPE, smsProperties.getType())) { tencentSmsCode(phone, code); } else { defaultSmsCode(phone, code); } - } /**