增加自定义短信

This commit is contained in:
wanggeng 2022-06-29 17:30:31 +08:00
parent 3d255e4495
commit d83aa7aa36
5 changed files with 25 additions and 6 deletions

View File

@ -32,6 +32,7 @@
<groupId>com.tencentcloudapi</groupId> <groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId> <artifactId>tencentcloud-sdk-java</artifactId>
<version>3.1.501</version> <version>3.1.501</version>
<scope>provided</scope>
</dependency> </dependency>
<!-- tencent sms end --> <!-- tencent sms end -->

View File

@ -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{
}

View File

@ -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.module.sms.factory.sms.impl.TencentSmsSendImpl;
import ink.wgink.properties.sms.SmsProperties; import ink.wgink.properties.sms.SmsProperties;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* When you feel like quitting. Think about why you started * When you feel like quitting. Think about why you started
@ -35,12 +33,17 @@ public class SmsSendFactory {
* @param smsProperties * @param smsProperties
* @return * @return
*/ */
public static ISmsSend getSendSms(SmsProperties smsProperties) { public static ISmsSend getSendSms(SmsProperties smsProperties, ICustomSmsSend smsCustomSend) {
if (!smsProperties.getActive()) { if (!smsProperties.getActive()) {
throw new SystemException("短信配置未激活"); throw new SystemException("短信配置未激活");
} }
if (StringUtils.equals(TENCENT_TYPE, smsProperties.getType())) { if (StringUtils.equals(TENCENT_TYPE, smsProperties.getType())) {
return new TencentSmsSendImpl(smsProperties.getTencentSms()); 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()); return new DefaultSmsSendImpl(smsProperties.getDefaultSms());
} }

View File

@ -7,6 +7,7 @@ import ink.wgink.exceptions.ParamsException;
import ink.wgink.exceptions.base.SystemException; import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.user.IUserBaseService; import ink.wgink.interfaces.user.IUserBaseService;
import ink.wgink.module.sms.dao.sms.ISmsDao; 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.factory.sms.SmsSendFactory;
import ink.wgink.module.sms.manager.VerifyCodeManager; import ink.wgink.module.sms.manager.VerifyCodeManager;
import ink.wgink.module.sms.pojo.dtos.sms.SmsDTO; import ink.wgink.module.sms.pojo.dtos.sms.SmsDTO;
@ -51,6 +52,9 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
private ISmsDao smsDao; private ISmsDao smsDao;
@Autowired @Autowired
private IUserBaseService userBaseService; private IUserBaseService userBaseService;
@Autowired(required = false)
private ICustomSmsSend smsCustomSend;
private ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(2); private ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(2);
@Override @Override
@ -115,7 +119,7 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
smsVO.setContent(content); smsVO.setContent(content);
try { try {
LOG.info(">>>>> 向手机号:{},发送内容:{}", phone, content); LOG.info(">>>>> 向手机号:{},发送内容:{}", phone, content);
SmsSendFactory.getSendSms(smsProperties).content(phone, content); SmsSendFactory.getSendSms(smsProperties, smsCustomSend).content(phone, content);
smsVO.setSendStatus(1); smsVO.setSendStatus(1);
} catch (Exception e) { } catch (Exception e) {
String errorMessage = e.getMessage(); String errorMessage = e.getMessage();
@ -143,7 +147,7 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
smsVO.setPhone(phone); smsVO.setPhone(phone);
smsVO.setContent(code); smsVO.setContent(code);
try { try {
SmsSendFactory.getSendSms(smsProperties).code(phone, code); SmsSendFactory.getSendSms(smsProperties, smsCustomSend).code(phone, code);
verifyCodeManager.setVerificationCode(phone, code); verifyCodeManager.setVerificationCode(phone, code);
smsVO.setSendStatus(1); smsVO.setSendStatus(1);
} catch (Exception e) { } catch (Exception e) {

View File

@ -49,7 +49,7 @@
KEY `phone` (`phone`), KEY `phone` (`phone`),
KEY `send_status` (`send_status`), KEY `send_status` (`send_status`),
KEY `is_delete` (`is_delete`) KEY `is_delete` (`is_delete`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
</update> </update>
<!-- 新增短信 --> <!-- 新增短信 -->