增加自定义短信
This commit is contained in:
parent
3d255e4495
commit
d83aa7aa36
@ -32,6 +32,7 @@
|
||||
<groupId>com.tencentcloudapi</groupId>
|
||||
<artifactId>tencentcloud-sdk-java</artifactId>
|
||||
<version>3.1.501</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- tencent sms end -->
|
||||
|
||||
|
@ -0,0 +1,11 @@
|
||||
package ink.wgink.module.sms.factory.sms;
|
||||
|
||||
/**
|
||||
* @ClassName: ISmsCustomSend
|
||||
* @Description: 自定义短信发送
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/28 10:38
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface ICustomSmsSend extends ISmsSend{
|
||||
}
|
@ -5,8 +5,6 @@ import ink.wgink.module.sms.factory.sms.impl.DefaultSmsSendImpl;
|
||||
import ink.wgink.module.sms.factory.sms.impl.TencentSmsSendImpl;
|
||||
import ink.wgink.properties.sms.SmsProperties;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
@ -35,12 +33,17 @@ public class SmsSendFactory {
|
||||
* @param smsProperties
|
||||
* @return
|
||||
*/
|
||||
public static ISmsSend getSendSms(SmsProperties smsProperties) {
|
||||
public static ISmsSend getSendSms(SmsProperties smsProperties, ICustomSmsSend smsCustomSend) {
|
||||
if (!smsProperties.getActive()) {
|
||||
throw new SystemException("短信配置未激活");
|
||||
}
|
||||
if (StringUtils.equals(TENCENT_TYPE, smsProperties.getType())) {
|
||||
return new TencentSmsSendImpl(smsProperties.getTencentSms());
|
||||
} else if (StringUtils.equals(CUSTOM_TYPE, smsProperties.getType())) {
|
||||
if (smsCustomSend == null) {
|
||||
throw new SystemException("自定义发送短信类不存在");
|
||||
}
|
||||
return smsCustomSend;
|
||||
}
|
||||
return new DefaultSmsSendImpl(smsProperties.getDefaultSms());
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.user.IUserBaseService;
|
||||
import ink.wgink.module.sms.dao.sms.ISmsDao;
|
||||
import ink.wgink.module.sms.factory.sms.ICustomSmsSend;
|
||||
import ink.wgink.module.sms.factory.sms.SmsSendFactory;
|
||||
import ink.wgink.module.sms.manager.VerifyCodeManager;
|
||||
import ink.wgink.module.sms.pojo.dtos.sms.SmsDTO;
|
||||
@ -51,6 +52,9 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
|
||||
private ISmsDao smsDao;
|
||||
@Autowired
|
||||
private IUserBaseService userBaseService;
|
||||
@Autowired(required = false)
|
||||
private ICustomSmsSend smsCustomSend;
|
||||
|
||||
private ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(2);
|
||||
|
||||
@Override
|
||||
@ -115,7 +119,7 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
|
||||
smsVO.setContent(content);
|
||||
try {
|
||||
LOG.info(">>>>> 向手机号:{},发送内容:{}", phone, content);
|
||||
SmsSendFactory.getSendSms(smsProperties).content(phone, content);
|
||||
SmsSendFactory.getSendSms(smsProperties, smsCustomSend).content(phone, content);
|
||||
smsVO.setSendStatus(1);
|
||||
} catch (Exception e) {
|
||||
String errorMessage = e.getMessage();
|
||||
@ -143,7 +147,7 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
|
||||
smsVO.setPhone(phone);
|
||||
smsVO.setContent(code);
|
||||
try {
|
||||
SmsSendFactory.getSendSms(smsProperties).code(phone, code);
|
||||
SmsSendFactory.getSendSms(smsProperties, smsCustomSend).code(phone, code);
|
||||
verifyCodeManager.setVerificationCode(phone, code);
|
||||
smsVO.setSendStatus(1);
|
||||
} catch (Exception e) {
|
||||
|
@ -49,7 +49,7 @@
|
||||
KEY `phone` (`phone`),
|
||||
KEY `send_status` (`send_status`),
|
||||
KEY `is_delete` (`is_delete`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
</update>
|
||||
|
||||
<!-- 新增短信 -->
|
||||
|
Loading…
Reference in New Issue
Block a user