新增短信发送激活配置

This commit is contained in:
wenc000 2020-05-31 12:26:57 +08:00
parent c104c3a589
commit 54565ed1e5
2 changed files with 19 additions and 3 deletions

View File

@ -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\":")

View File

@ -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);
}
}
/**