From 54565ed1e5bd2c8507ba0768a41a125cdb2704da Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Sun, 31 May 2020 12:26:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9F=AD=E4=BF=A1=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=BF=80=E6=B4=BB=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/config/properties/SmsProperties.java | 15 +++++++++++++-- .../manager/sms/service/impl/SmsServiceImpl.java | 7 ++++++- 2 files changed, 19 insertions(+), 3 deletions(-) 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); } - } /**