update sms 2.2.0 => 3.1.0

2.X
AprilWind 1 year ago
parent bd278742db
commit a6932f8c0a

@ -54,28 +54,59 @@ mail:
connectionTimeout: 0
# sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商
# https://wind.kim/doc/start 文档地址 各个厂商可同时使用
# https://sms4j.com/doc3/ 差异配置文档地址 支持单厂商多配置,可以配置多个同时使用
sms:
# 阿里云 dysmsapi.aliyuncs.com
alibaba:
#请求地址 默认为 dysmsapi.aliyuncs.com 如无特殊改变可以不用设置
requestUrl: dysmsapi.aliyuncs.com
#阿里云的accessKey
accessKeyId: xxxxxxx
#阿里云的accessKeySecret
accessKeySecret: xxxxxxx
#短信签名
signature: 测试
tencent:
#请求地址默认为 sms.tencentcloudapi.com 如无特殊改变可不用设置
requestUrl: sms.tencentcloudapi.com
#腾讯云的accessKey
accessKeyId: xxxxxxx
#腾讯云的accessKeySecret
accessKeySecret: xxxxxxx
#短信签名
signature: 测试
#短信sdkAppId
sdkAppId: appid
#地域信息默认为 ap-guangzhou 如无特殊改变可不用设置
territory: ap-guangzhou
# 配置源类型用于标定配置来源(interface,yaml)
config-type: yaml
# 用于标定yml中的配置是否开启短信拦截接口配置不受此限制
restricted: true
# 短信拦截限制单手机号每分钟最大发送,只对开启了拦截的配置有效
minute-max: 1
# 短信拦截限制单手机号每日最大发送量,只对开启了拦截的配置有效
account-max: 30
# 以下配置来自于 org.dromara.sms4j.provider.config.BaseConfig类中
blends:
# 自定义的标识也就是configId这里可以是任意值最好不要是中文
tx1:
# 框架定义的厂商名称标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
supplier: tencent
# 有些称为accessKey有些称之为apiKey也有称为sdkKey或者appId。
access-key-id: 您的accessKey
# 称为accessSecret有些称之为apiSecret
access-key-secret: 您的accessKeySecret
# 您的短信签名
signature: 您的短信签名
#模板ID 如果不需要简化的sendMessage方法可以不配置如果使用sendMessage的快速发送需此配置
template-id: xxxxxxxx
#您的sdkAppId
sdk-app-id: 您的sdkAppId
# 随机权重负载均衡的权重值依赖于此默认为1如不需要负载均衡可不进行配置
weight: 1
#短信自动重试间隔时间 默认五秒
retry-interval: 3
# 短信重试次数默认0次不重试如果你需要短信重试则根据自己的需求修改值即可
max-retries: 1
# 当前厂商的发送数量上限,默认不设置上限
maximum: 10000
# 自定义的标识也就是configId这里可以是任意值最好不要是中文
tx2:
#厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
supplier: tencent
#您的accessKey
access-key-id: 您的accessKey
#您的accessKeySecret
access-key-secret: 您的accessKeySecret
#您的短信签名
signature: 您的短信签名
#模板ID 非必须配置如果使用sendMessage的快速发送需此配置
template-id: xxxxxxxx
#您的sdkAppId
sdk-app-id: 您的sdkAppId
# 随机权重负载均衡的权重值依赖于此默认为1如不需要负载均衡可不进行配置
weight: 1
#短信自动重试间隔时间 默认五秒
retry-interval: 3
# 短信重试次数默认0次不重试如果你需要短信重试则根据自己的需求修改值即可
max-retries: 1
# 当前厂商的发送数量上限,默认不设置上限
maximum: 10000

@ -56,7 +56,7 @@
<okhttp.version>4.10.0</okhttp.version>
<!-- SMS 配置 -->
<sms4j.version>2.2.0</sms4j.version>
<sms4j.version>3.1.0</sms4j.version>
<!-- 插件版本 -->
<maven-compiler-plugin.verison>3.11.0</maven-compiler-plugin.verison>

@ -1,24 +1,145 @@
package org.dromara.resource.api;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.resource.api.domain.RemoteSms;
import java.util.LinkedHashMap;
import java.util.List;
/**
*
*
* @author Lion Li
* @author Feng
*/
public interface RemoteSmsService {
/**
*
*
*
* @param phones ()
* @param templateId id
* @param param
* @param phone
* @param message
* @return RemoteSms
*/
RemoteSms send(String phones, String templateId, LinkedHashMap<String, String> param) throws ServiceException;
RemoteSms sendMessage(String phone, String message);
/**
*
*
* @param phone
* @param messages 使 LinkedHashMap
* @return RemoteSms
*/
RemoteSms sendMessage(String phone, LinkedHashMap<String, String> messages);
/**
* 使
*
* @param phone
* @param templateId ID
* @param messages 使 LinkedHashMap
* @return RemoteSms
*/
RemoteSms sendMessage(String phone, String templateId, LinkedHashMap<String, String> messages);
/**
*
*
* @param phones 1~1000
* @param message
* @return RemoteSms
*/
RemoteSms massTexting(List<String> phones, String message);
/**
* 使
*
* @param phones 1~10001~1000
* @param templateId ID
* @param messages 使 LinkedHashMap
* @return RemoteSms
*/
RemoteSms massTexting(List<String> phones, String templateId, LinkedHashMap<String, String> messages);
/**
*
*
* @param phone
* @param message
*/
void sendMessageAsync(String phone, String message);
/**
* 使
*
* @param phone
* @param templateId ID
* @param messages 使 LinkedHashMap
*/
void sendMessageAsync(String phone, String templateId, LinkedHashMap<String, String> messages);
/**
*
*
* @param phone
* @param message
* @param delayedTime
*/
void delayedMessage(String phone, String message, Long delayedTime);
/**
* 使
*
* @param phone
* @param templateId ID
* @param messages 使 LinkedHashMap
* @param delayedTime
*/
void delayedMessage(String phone, String templateId, LinkedHashMap<String, String> messages, Long delayedTime);
/**
*
*
* @param phones 1~1000
* @param message
* @param delayedTime
*/
void delayMassTexting(List<String> phones, String message, Long delayedTime);
/**
* 使
*
* @param phones 1~1000
* @param templateId ID
* @param messages 使 LinkedHashMap
* @param delayedTime
*/
void delayMassTexting(List<String> phones, String templateId, LinkedHashMap<String, String> messages, Long delayedTime);
/**
*
*
* @param phone
*/
void joinInBlacklist(String phone);
/**
*
*
* @param phones
*/
void joinInBlacklist(List<String> phones);
/**
*
*
* @param phone
*/
void removeFromBlacklist(String phone);
/**
*
*
* @param phones
*/
void removeFromBlacklist(List<String> phones);
}

@ -19,15 +19,15 @@ public class RemoteSms implements Serializable {
/**
*
*/
private Boolean isSuccess;
private Boolean success;
/**
*
* Alibaba
*/
private String message;
private String configId;
/**
*
*
* <p>
* SDK SendSmsResponse
*/

@ -20,13 +20,12 @@
<dependency>
<groupId>org.dromara.sms4j</groupId>
<artifactId>sms4j-spring-boot-starter</artifactId>
<exclusions>
<!-- 排除京东短信内存在的fastjson等待作者后续修复 -->
<exclusion>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- RuoYi Common Redis-->
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-redis</artifactId>
</dependency>
</dependencies>

@ -1,14 +1,24 @@
package org.dromara.common.sms.config;
import org.dromara.common.redis.config.RedisConfiguration;
import org.dromara.common.sms.core.dao.PlusSmsDao;
import org.dromara.sms4j.api.dao.SmsDao;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
/**
* ( )
*
*
* @author Lion Li
* @version 4.2.0
* @author Feng
*/
@AutoConfiguration
@AutoConfiguration(after = {RedisConfiguration.class})
public class SmsAutoConfiguration {
@Primary
@Bean
public SmsDao smsDao() {
return new PlusSmsDao();
}
}

@ -0,0 +1,59 @@
package org.dromara.common.sms.core.dao;
import org.dromara.common.core.constant.GlobalConstants;
import org.dromara.common.redis.utils.RedisUtils;
import org.dromara.sms4j.api.dao.SmsDao;
import java.time.Duration;
/**
* SmsDao (使RedisUtils )
* <p>
*
* @author Feng
*/
public class PlusSmsDao implements SmsDao {
/**
*
*
* @param key
* @param value
* @param cacheTime )
*/
@Override
public void set(String key, Object value, long cacheTime) {
RedisUtils.setCacheObject(GlobalConstants.GLOBAL_REDIS_KEY + key, value, Duration.ofSeconds(cacheTime));
}
/**
*
*
* @param key
* @param value
*/
@Override
public void set(String key, Object value) {
RedisUtils.setCacheObject(GlobalConstants.GLOBAL_REDIS_KEY + key, value, true);
}
/**
*
*
* @param key
* @return
*/
@Override
public Object get(String key) {
return RedisUtils.getCacheObject(GlobalConstants.GLOBAL_REDIS_KEY + key);
}
/**
*
*/
@Override
public void clean() {
RedisUtils.deleteObject(GlobalConstants.GLOBAL_REDIS_KEY + "sms:");
}
}

@ -5,7 +5,6 @@ import org.dromara.common.core.domain.R;
import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.dromara.sms4j.provider.enumerate.SupplierType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -35,7 +34,7 @@ public class SmsController {
public R<Object> sendAliyun(String phones, String templateId) {
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
map.put("code", "1234");
SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA);
SmsBlend smsBlend = SmsFactory.getSmsBlend("tx1");
SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map);
return R.ok(smsResponse);
}
@ -51,7 +50,7 @@ public class SmsController {
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
// map.put("2", "测试测试");
map.put("1", "1234");
SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.TENCENT);
SmsBlend smsBlend = SmsFactory.getSmsBlend("tx1");
SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map);
return R.ok(smsResponse);
}

@ -14,7 +14,6 @@ import org.dromara.common.web.core.BaseController;
import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.dromara.sms4j.provider.enumerate.SupplierType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -50,11 +49,11 @@ public class SysSmsController extends BaseController {
String templateId = "";
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
map.put("code", code);
SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA);
SmsBlend smsBlend = SmsFactory.getSmsBlend("tx1");
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
if (!"OK".equals(smsResponse.getCode())) {
if (!smsResponse.isSuccess()) {
log.error("验证码短信发送异常 => {}", smsResponse);
return R.fail(smsResponse.getMessage());
return R.fail(smsResponse.getData().toString());
}
return R.ok();
}

@ -8,7 +8,7 @@ import org.dromara.resource.api.RemoteMessageService;
import org.springframework.stereotype.Service;
/**
*
*
*
* @author Lion Li
*/

@ -3,22 +3,20 @@ package org.dromara.resource.dubbo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.json.utils.JsonUtils;
import org.dromara.resource.api.RemoteSmsService;
import org.dromara.resource.api.domain.RemoteSms;
import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.dromara.sms4j.provider.enumerate.SupplierType;
import org.springframework.stereotype.Service;
import java.util.LinkedHashMap;
import java.util.List;
/**
*
*
* @author Lion Li
* @author Feng
*/
@Slf4j
@RequiredArgsConstructor
@ -27,20 +25,211 @@ import java.util.LinkedHashMap;
public class RemoteSmsServiceImpl implements RemoteSmsService {
/**
*
* SmsBlend
*
* @param phones ()
* @param templateId id
* @param param
* @return SmsBlend
*/
public RemoteSms send(String phones, String templateId, LinkedHashMap<String, String> param) throws ServiceException {
SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA);
SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, param);
RemoteSms sysSms = new RemoteSms();
sysSms.setIsSuccess(smsResponse.isSuccess());
sysSms.setMessage(smsResponse.getMessage());
sysSms.setResponse(JsonUtils.toJsonString(smsResponse));
return sysSms;
private SmsBlend getSmsBlend() {
return SmsFactory.getSmsBlend("tx1");
}
/**
* SmsResponse RemoteSms
*
* @param smsResponse
* @return RemoteSms
*/
private RemoteSms getRemoteSms(SmsResponse smsResponse) {
// 创建一个 RemoteSms 对象,封装响应信息
RemoteSms sms = new RemoteSms();
sms.setSuccess(smsResponse.isSuccess());
sms.setResponse(smsResponse.getData().toString());
sms.setConfigId(smsResponse.getConfigId());
return sms;
}
/**
*
*
* @param phone
* @param message
* @return RemoteSms
*/
@Override
public RemoteSms sendMessage(String phone, String message) {
// 调用 getSmsBlend 方法获取对应短信供应商的 SmsBlend 实例
SmsResponse smsResponse = getSmsBlend().sendMessage(phone, message);
return getRemoteSms(smsResponse);
}
/**
*
*
* @param phone
* @param messages 使 LinkedHashMap
* @return RemoteSms
*/
@Override
public RemoteSms sendMessage(String phone, LinkedHashMap<String, String> messages) {
SmsResponse smsResponse = getSmsBlend().sendMessage(phone, messages);
return getRemoteSms(smsResponse);
}
/**
*
*
* @param phone
* @param templateId ID
* @param messages 使 LinkedHashMap
* @return RemoteSms
*/
@Override
public RemoteSms sendMessage(String phone, String templateId, LinkedHashMap<String, String> messages) {
// 调用 getSmsBlend 方法获取对应短信供应商的 SmsBlend 实例
SmsResponse smsResponse = getSmsBlend().sendMessage(phone, templateId, messages);
return getRemoteSms(smsResponse);
}
/**
*
*
* @param phones
* @param message
* @return RemoteSms
*/
@Override
public RemoteSms massTexting(List<String> phones, String message) {
// 调用 getSmsBlend 方法获取对应短信供应商的 SmsBlend 实例
SmsResponse smsResponse = getSmsBlend().massTexting(phones, message);
return getRemoteSms(smsResponse);
}
/**
*
*
* @param phones
* @param templateId ID
* @param messages 使 LinkedHashMap
* @return RemoteSms
*/
@Override
public RemoteSms massTexting(List<String> phones, String templateId, LinkedHashMap<String, String> messages) {
// 调用 getSmsBlend 方法获取对应短信供应商的 SmsBlend 实例
SmsResponse smsResponse = getSmsBlend().massTexting(phones, templateId, messages);
return getRemoteSms(smsResponse);
}
/**
*
*
* @param phone
* @param message
*/
@Override
public void sendMessageAsync(String phone, String message) {
getSmsBlend().sendMessageAsync(phone, message);
}
/**
*
*
* @param phone
* @param templateId ID
* @param messages 使 LinkedHashMap
*/
@Override
public void sendMessageAsync(String phone, String templateId, LinkedHashMap<String, String> messages) {
getSmsBlend().sendMessageAsync(phone, templateId, messages);
}
/**
*
*
* @param phone
* @param message
* @param delayedTime
*/
@Override
public void delayedMessage(String phone, String message, Long delayedTime) {
getSmsBlend().delayedMessage(phone, message, delayedTime);
}
/**
*
*
* @param phone
* @param templateId ID
* @param messages 使 LinkedHashMap
* @param delayedTime
*/
@Override
public void delayedMessage(String phone, String templateId, LinkedHashMap<String, String> messages, Long delayedTime) {
getSmsBlend().delayedMessage(phone, templateId, messages, delayedTime);
}
/**
*
*
* @param phones
* @param message
* @param delayedTime
*/
@Override
public void delayMassTexting(List<String> phones, String message, Long delayedTime) {
getSmsBlend().delayMassTexting(phones, message, delayedTime);
}
/**
*
*
* @param phones
* @param templateId ID
* @param messages 使 LinkedHashMap
* @param delayedTime
*/
@Override
public void delayMassTexting(List<String> phones, String templateId, LinkedHashMap<String, String> messages, Long delayedTime) {
getSmsBlend().delayMassTexting(phones, templateId, messages, delayedTime);
}
/**
*
*
* @param phone
*/
@Override
public void joinInBlacklist(String phone) {
getSmsBlend().joinInBlacklist(phone);
}
/**
*
*
* @param phones
*/
@Override
public void joinInBlacklist(List<String> phones) {
getSmsBlend().batchJoinBlacklist(phones);
}
/**
*
*
* @param phone
*/
@Override
public void removeFromBlacklist(String phone) {
getSmsBlend().removeFromBlacklist(phone);
}
/**
*
*
* @param phones
*/
@Override
public void removeFromBlacklist(List<String> phones) {
getSmsBlend().batchRemovalFromBlacklist(phones);
}
}

Loading…
Cancel
Save