新增短信验证

This commit is contained in:
zhuyijun 2022-10-21 18:47:34 +08:00
parent 2179f4f527
commit 44ea6dffa6
30 changed files with 915 additions and 13 deletions

View File

@ -58,6 +58,11 @@
<artifactId>zyjblogs-minio-spring-boot-starter</artifactId> <artifactId>zyjblogs-minio-spring-boot-starter</artifactId>
<version>${zyjblogs.version}</version> <version>${zyjblogs.version}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.zyjblogs.starter</groupId>
<artifactId>zyjblogs-sms-spring-boot-starter</artifactId>
<version>${zyjblogs.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<build> <build>

13
pom.xml
View File

@ -56,9 +56,15 @@
<easyexcel.version>2.2.11</easyexcel.version> <easyexcel.version>2.2.11</easyexcel.version>
<bcprov-jdk15on.version>1.70</bcprov-jdk15on.version> <bcprov-jdk15on.version>1.70</bcprov-jdk15on.version>
<nacos-client.version>2.0.4</nacos-client.version> <nacos-client.version>2.0.4</nacos-client.version>
<!-- 短信sdk--> <!-- 短信sdk-->
<!-- 异步 -->
<alibabacloud-dysmsapi20170525.version>1.0.1</alibabacloud-dysmsapi20170525.version> <alibabacloud-dysmsapi20170525.version>1.0.1</alibabacloud-dysmsapi20170525.version>
<tencentcloud-sdk-java.version>3.1.612</tencentcloud-sdk-java.version> <!-- 同步 -->
<dysmsapi20170525.version>2.0.9</dysmsapi20170525.version>
<tencentcloud-sdk-java.version>3.1.600</tencentcloud-sdk-java.version>
<!-- xxl-job-core核心版本号 --> <!-- xxl-job-core核心版本号 -->
<xxl-job-core.version>2.3.0</xxl-job-core.version> <xxl-job-core.version>2.3.0</xxl-job-core.version>
<!-- oos --> <!-- oos -->
@ -289,6 +295,11 @@
<!-- 请到https://search.maven.org/search?q=tencentcloud-sdk-java查询所有版本最新版本如下 --> <!-- 请到https://search.maven.org/search?q=tencentcloud-sdk-java查询所有版本最新版本如下 -->
<version>${tencentcloud-sdk-java.version}</version> <version>${tencentcloud-sdk-java.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
<version>${dysmsapi20170525.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

View File

@ -25,5 +25,27 @@ spring:
password: ${spring.cloud.nacos.config.password} password: ${spring.cloud.nacos.config.password}
namespace: ${spring.cloud.nacos.config.namespace} namespace: ${spring.cloud.nacos.config.namespace}
group: public group: public
gateway:
httpclient:
response-timeout: 10000
connect-timeout: 1000
default-filters[0]:
name: Retry
#根据默认参数只重试GET请求修改参数使POST也支持
args:
methods[0]: GET
methods[1]: POST
logging: logging:
config: classpath:logback-spring.xml config: classpath:logback-spring.xml

View File

@ -86,10 +86,9 @@
<artifactId>core</artifactId> <artifactId>core</artifactId>
<version>3.3.3</version> <version>3.3.3</version>
</dependency> </dependency>
<!-- minio -->
<dependency> <dependency>
<groupId>cn.zyjblogs.starter</groupId> <groupId>cn.zyjblogs.starter</groupId>
<artifactId>zyjblogs-minio-spring-boot-starter</artifactId> <artifactId>zyjblogs-sms-spring-boot-starter</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -10,7 +10,6 @@ import cn.zyjblogs.server.user.vo.OAuth2AccessTokenVo;
import cn.zyjblogs.starter.common.entity.constant.CommonRedisKeyConstant; import cn.zyjblogs.starter.common.entity.constant.CommonRedisKeyConstant;
import cn.zyjblogs.starter.common.entity.response.HttpCode; import cn.zyjblogs.starter.common.entity.response.HttpCode;
import cn.zyjblogs.starter.common.exception.AuthRuntimeException; import cn.zyjblogs.starter.common.exception.AuthRuntimeException;
import cn.zyjblogs.starter.minio.service.MinioService;
import cn.zyjblogs.starter.redis.utils.RedisTemplateHandler; import cn.zyjblogs.starter.redis.utils.RedisTemplateHandler;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -30,14 +29,12 @@ import java.util.concurrent.TimeUnit;
public class QrCodeSeriveImpl implements QrCodeSerive { public class QrCodeSeriveImpl implements QrCodeSerive {
private final TokenGranter tokenGranter; private final TokenGranter tokenGranter;
private final RedisTemplateHandler<String, QrCode> redisTemplateHandler; private final RedisTemplateHandler<String, QrCode> redisTemplateHandler;
private final MinioService minioService;
private final ClientDetailsService clientDetails; private final ClientDetailsService clientDetails;
private final OAuth2RequestFactory oAuth2RequestFactory; private final OAuth2RequestFactory oAuth2RequestFactory;
public QrCodeSeriveImpl(AuthorizationServerEndpointsConfiguration authorizationServerEndpointsConfiguration, public QrCodeSeriveImpl(AuthorizationServerEndpointsConfiguration authorizationServerEndpointsConfiguration,
ClientDetailsService clientDetails, RedisTemplateHandler redisTemplateHandler, MinioService minioService) { ClientDetailsService clientDetails, RedisTemplateHandler redisTemplateHandler) {
this.redisTemplateHandler = redisTemplateHandler; this.redisTemplateHandler = redisTemplateHandler;
this.minioService = minioService;
this.clientDetails = clientDetails; this.clientDetails = clientDetails;
this.oAuth2RequestFactory = new DefaultOAuth2RequestFactory(clientDetails); this.oAuth2RequestFactory = new DefaultOAuth2RequestFactory(clientDetails);
this.tokenGranter = authorizationServerEndpointsConfiguration.getEndpointsConfigurer().getTokenGranter(); this.tokenGranter = authorizationServerEndpointsConfiguration.getEndpointsConfigurer().getTokenGranter();

View File

@ -106,4 +106,5 @@ security:
client-id: ${spring.application.name} client-id: ${spring.application.name}
client-secret: secret client-secret: secret
resource: resource:
id: ${spring.application.name} id: ${spring.application.name}

View File

@ -0,0 +1,35 @@
{
"groups": [
{
"name": "minio",
"type": "cn.zyjblogs.starter.minio.config.MinioProperties",
"sourceType": "cn.zyjblogs.starter.minio.config.MinioProperties"
}
],
"properties": [
{
"defaultValue": "",
"name": "minio.endpoint",
"description": "端点",
"type": "java.lang.String"
},
{
"defaultValue": "",
"name": "minio.accessKey",
"description": "账号",
"type": "java.lang.String"
},
{
"defaultValue": "",
"name": "minio.secretKey",
"description": "密码",
"type": "java.lang.String"
},
{
"defaultValue": "",
"name": "minio.bucketName",
"description": "储存桶",
"type": "java.lang.String"
}
]
}

View File

@ -0,0 +1,35 @@
{
"groups": [
{
"name": "minio",
"type": "cn.zyjblogs.starter.minio.config.MinioProperties",
"sourceType": "cn.zyjblogs.starter.minio.config.MinioProperties"
}
],
"properties": [
{
"defaultValue": "",
"name": "minio.endpoint",
"description": "端点",
"type": "java.lang.String"
},
{
"defaultValue": "",
"name": "minio.accessKey",
"description": "账号",
"type": "java.lang.String"
},
{
"defaultValue": "",
"name": "minio.secretKey",
"description": "密码",
"type": "java.lang.String"
},
{
"defaultValue": "",
"name": "minio.bucketName",
"description": "储存桶",
"type": "java.lang.String"
}
]
}

View File

@ -0,0 +1,5 @@
#Generated by Maven
#Mon Jul 25 15:29:06 CST 2022
groupId=cn.zyjblogs.starter
artifactId=zyjblogs-oauth-spring-boot-starter
version=1.0-SNAPSHOT

View File

@ -0,0 +1,5 @@
#Generated by Maven
#Mon Jul 25 15:29:06 CST 2022
groupId=cn.zyjblogs.starter
artifactId=zyjblogs-rabbitmq-spring-boot-starter
version=1.0-SNAPSHOT

View File

@ -36,12 +36,20 @@
<dependency> <dependency>
<groupId>com.aliyun</groupId> <groupId>com.aliyun</groupId>
<artifactId>alibabacloud-dysmsapi20170525</artifactId> <artifactId>alibabacloud-dysmsapi20170525</artifactId>
<version>${alibabacloud-dysmsapi20170525.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.tencentcloudapi</groupId> <groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java-sms</artifactId> <artifactId>tencentcloud-sdk-java-sms</artifactId>
<version>${tencentcloud-sdk-java.version}</version> <!-- go to https://search.maven.org/search?q=tencentcloud-sdk-java and get the latest version. -->
<!-- 请到https://search.maven.org/search?q=tencentcloud-sdk-java查询所有版本最新版本如下 -->
<!-- <version>${tencentcloud-sdk-java.version}</version>-->
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>com.aliyun</groupId>-->
<!-- <artifactId>dysmsapi20170525</artifactId>-->
<!-- <version>${dysmsapi20170525.version}</version>-->
<!-- </dependency>-->
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@ -0,0 +1,77 @@
package cn.zyjblogs.starter.sms.autoconfigure;
import cn.zyjblogs.starter.sms.config.SmsProperties;
import cn.zyjblogs.starter.sms.provider.CompositeSmsGranter;
import cn.zyjblogs.starter.sms.provider.SmsGranter;
import cn.zyjblogs.starter.sms.provider.aliyun.AliSmsHandleGranter;
import cn.zyjblogs.starter.sms.provider.tencent.TenSmsHandleGranter;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import darabonba.core.client.ClientOverrideConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
@Configuration
@EnableConfigurationProperties({SmsProperties.class})
public class SmsConfiguration {
@Bean
public CompositeSmsGranter smsGranter(SmsProperties smsProperties) {
List<SmsGranter> list = new ArrayList<>();
list.add(new AliSmsHandleGranter(aliSyncClient(smsProperties), smsProperties.getAliyun()));
list.add(new TenSmsHandleGranter(tenClient(smsProperties), smsProperties.getTencent()));
return new CompositeSmsGranter(list);
}
/**
* 异步客户端
*
* @param smsProperties
* @return
* @throws Exception
*/
@Bean
public AsyncClient aliSyncClient(SmsProperties smsProperties) {
SmsProperties.AliyunSmsProperties aliyun = smsProperties.getAliyun();
if (aliyun == null || Boolean.FALSE.equals(aliyun.getEnable())) {
return null;
}
StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
.accessKeyId(aliyun.getAccessKey())
.accessKeySecret(aliyun.getAccessSecret())
//.securityToken("<your-token>") // use STS token
.build());
return AsyncClient.builder()
.region(aliyun.getRegion())
.credentialsProvider(provider)
//.serviceConfiguration(Configuration.create()) // Service-level configuration
// Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
.overrideConfiguration(
ClientOverrideConfiguration.create()
.setEndpointOverride(aliyun.getEndpoint())
//.setReadTimeout(Duration.ofSeconds(30))
)
.build();
}
@Bean
public SmsClient tenClient(SmsProperties smsProperties) {
SmsProperties.TencentSmsProperties tencent = smsProperties.getTencent();
if (tencent == null || Boolean.FALSE.equals(tencent.getEnable())) {
return null;
}
com.tencentcloudapi.common.Credential credential = new com.tencentcloudapi.common.Credential(tencent.getAccessKey(), tencent.getAccessSecret());
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint(tencent.getEndpoint());
return new SmsClient(credential, tencent.getRegion());
}
}

View File

@ -0,0 +1,6 @@
package cn.zyjblogs.starter.sms.common;
public class SmsActionConstant {
public static final String SIMPLE_CLIENT_SEND = "simpleSendSms";
public static final String ASYNC_CLIENT_SEND = "asyncSendSms";
}

View File

@ -0,0 +1,12 @@
package cn.zyjblogs.starter.sms.common;
public class SmsCommon {
/**
* 短信 参数key
*/
public static final String TEMPLATE_PARAM = "templateParam";
/**
* 腾讯sdk专用 senderid 港澳台专用
*/
public static final String SENDERID = "senderid";
}

View File

@ -0,0 +1,25 @@
package cn.zyjblogs.starter.sms.common;
public enum SmsEnum {
ALI_SMS("aliyun"),
TEN_SMS("tencent");
private String name;
SmsEnum(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static SmsEnum findByName(String name) {
SmsEnum[] values = SmsEnum.values();
for (SmsEnum value : values) {
if (value.getName().equals(name)) {
return value;
}
}
return null;
}
}

View File

@ -0,0 +1,32 @@
package cn.zyjblogs.starter.sms.common;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Map;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SmsRequest implements Serializable {
/**
* 签名
*/
private String signName;
/**
* 模板编号
*/
private String templateCode;
/**
* 参数map
*/
private Map<String, Object> paramsMap;
/**
* 方法
*/
private String action;
}

View File

@ -0,0 +1,17 @@
package cn.zyjblogs.starter.sms.common;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SmsResponse implements Serializable {
private String message;
private String code;
}

View File

@ -0,0 +1,63 @@
package cn.zyjblogs.starter.sms.config;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
@ConfigurationProperties(prefix = "sms")
public class SmsProperties {
private AliyunSmsProperties aliyun;
private TencentSmsProperties tencent;
@Data
@AllArgsConstructor
public static class AliyunSmsProperties implements Serializable {
private Boolean enable;
private String accessKey;
//秘钥
private String accessSecret;
//ip地址
private String endpoint;
//地区
private String region;
//模板编号
private String templateCode;
/**
* 批量发送最数量
*/
private Integer maxSize;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class TencentSmsProperties implements Serializable {
private Boolean enable;
private String accessKey;
//秘钥
private String accessSecret;
//ip地址
private String endpoint;
//地区
private String region;
//模板编号
private String templateCode;
private String sign;
private String appId;
private String senderId;
/**
* 批量发送最数量
*/
private Integer maxSize;
}
}

View File

@ -0,0 +1,9 @@
package cn.zyjblogs.starter.sms.exception;
public class SmsRuntimeException extends RuntimeException {
public SmsRuntimeException(String message) {
super(message);
}
}

View File

@ -0,0 +1,28 @@
package cn.zyjblogs.starter.sms.provider;
import cn.zyjblogs.starter.sms.common.SmsRequest;
import java.util.List;
public abstract class AbstractSmsGranter implements SmsGranter {
private final String typeName;
public AbstractSmsGranter(String typeName) {
this.typeName = typeName;
}
@Override
public SmsGranter getGranter(String typeName) {
return null;
}
@Override
public void sendSms(String typeName, List<String> phones, SmsRequest smsRequest) {
sendSms(phones, smsRequest);
}
public void sendSms(List<String> phones, SmsRequest smsRequest) {
}
}

View File

@ -0,0 +1,40 @@
package cn.zyjblogs.starter.sms.provider;
import cn.zyjblogs.starter.sms.common.SmsRequest;
import java.util.ArrayList;
import java.util.List;
public class CompositeSmsGranter implements SmsGranter {
private final List<SmsGranter> smsGranters;
public CompositeSmsGranter(List<SmsGranter> smsGranters) {
this.smsGranters = new ArrayList<>(smsGranters);
}
@Override
public SmsGranter getGranter(String typeName) {
for (SmsGranter granter : smsGranters) {
SmsGranter granters = granter.getGranter(typeName);
if (granters != null) {
return granters;
}
}
return null;
}
@Override
public void sendSms(String typeName, List<String> phones, SmsRequest smsRequest) {
SmsGranter granter1 = getGranter(typeName);
if (granter1 != null) {
granter1.sendSms(typeName, phones, smsRequest);
}
}
public void addTokenGranter(SmsGranter smsGranter) {
if (smsGranter == null) {
throw new IllegalArgumentException("sms granter is null");
}
smsGranters.add(smsGranter);
}
}

View File

@ -0,0 +1,19 @@
package cn.zyjblogs.starter.sms.provider;
import cn.zyjblogs.starter.sms.common.SmsRequest;
import java.util.List;
public interface SmsGranter {
SmsGranter getGranter(String typeName);
/**
* 短信发送 手机号为多个以逗号隔开
*
* @param typeName
* @param phones
* @param smsRequest
* @return
*/
void sendSms(String typeName, List<String> phones, SmsRequest smsRequest);
}

View File

@ -0,0 +1,78 @@
package cn.zyjblogs.starter.sms.provider.aliyun;
import cn.zyjblogs.starter.sms.common.SmsCommon;
import cn.zyjblogs.starter.sms.common.SmsEnum;
import cn.zyjblogs.starter.sms.common.SmsRequest;
import cn.zyjblogs.starter.sms.config.SmsProperties;
import cn.zyjblogs.starter.sms.exception.SmsRuntimeException;
import cn.zyjblogs.starter.sms.provider.AbstractSmsGranter;
import cn.zyjblogs.starter.sms.provider.SmsGranter;
import com.alibaba.fastjson.JSON;
import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest;
import wiremock.com.google.common.collect.Lists;
import java.util.List;
public class AliSmsHandleGranter extends AbstractSmsGranter {
private static final String TYPE_NAME = SmsEnum.ALI_SMS.getName();
private final AsyncClient aliSyncClient;
private final SmsProperties.AliyunSmsProperties aliyunSmsProperties;
public AliSmsHandleGranter(AsyncClient aliSyncClient, SmsProperties.AliyunSmsProperties aliyunSmsProperties, String typeName) {
super(typeName);
this.aliSyncClient = aliSyncClient;
this.aliyunSmsProperties = aliyunSmsProperties;
if (aliyunSmsProperties.getMaxSize() == null || aliyunSmsProperties.getMaxSize() < 100) {
aliyunSmsProperties.setMaxSize(200);
}
}
public AliSmsHandleGranter(AsyncClient aliSyncClient, SmsProperties.AliyunSmsProperties aliyunSmsProperties) {
super(TYPE_NAME);
this.aliSyncClient = aliSyncClient;
this.aliyunSmsProperties = aliyunSmsProperties;
if (aliyunSmsProperties.getMaxSize() == null || aliyunSmsProperties.getMaxSize() < 100) {
aliyunSmsProperties.setMaxSize(200);
}
}
/**
* 短信发送 手机号为多个以逗号隔开
*
* @param phones
* @param smsRequest
* @return
*/
@Override
public void sendSms(List<String> phones, SmsRequest smsRequest) {
Object o = smsRequest.getParamsMap().get(SmsCommon.TEMPLATE_PARAM);
if (o == null) {
throw new SmsRuntimeException("参数不能为空");
}
try {
String templateCode = smsRequest.getTemplateCode();
String templateParam = JSON.toJSONString(o);
List<List<String>> partition = Lists.partition(phones, aliyunSmsProperties.getMaxSize());
partition.forEach(phoneList -> {
SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
.phoneNumbers(String.join(",", phoneList))
.signName(smsRequest.getSignName())
.templateCode(templateCode)
.templateParam(templateParam)
.build();
aliSyncClient.sendSms(sendSmsRequest);
});
} catch (Exception e) {
throw new SmsRuntimeException("发送失败");
}
}
@Override
public SmsGranter getGranter(String typeName) {
if (TYPE_NAME.equals(typeName)) {
return this;
}
return null;
}
}

View File

@ -0,0 +1,75 @@
package cn.zyjblogs.starter.sms.provider.tencent;
import cn.zyjblogs.starter.sms.common.SmsCommon;
import cn.zyjblogs.starter.sms.common.SmsEnum;
import cn.zyjblogs.starter.sms.common.SmsRequest;
import cn.zyjblogs.starter.sms.config.SmsProperties;
import cn.zyjblogs.starter.sms.exception.SmsRuntimeException;
import cn.zyjblogs.starter.sms.provider.AbstractSmsGranter;
import cn.zyjblogs.starter.sms.provider.SmsGranter;
import com.alibaba.fastjson2.JSON;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
public class TenSmsHandleGranter extends AbstractSmsGranter {
private static final String TYPE_NAME = SmsEnum.TEN_SMS.getName();
private final SmsClient smsClient;
private final SmsProperties.TencentSmsProperties tencentSmsProperties;
public TenSmsHandleGranter(SmsClient smsClient, SmsProperties.TencentSmsProperties tencentSmsProperties, String typeName) {
super(typeName);
this.smsClient = smsClient;
this.tencentSmsProperties = tencentSmsProperties;
if (tencentSmsProperties.getMaxSize() == null || tencentSmsProperties.getMaxSize() < 100) {
tencentSmsProperties.setMaxSize(200);
}
}
public TenSmsHandleGranter(SmsClient smsClient, SmsProperties.TencentSmsProperties tencentSmsProperties) {
super(TYPE_NAME);
this.smsClient = smsClient;
this.tencentSmsProperties = tencentSmsProperties;
if (tencentSmsProperties.getMaxSize() == null || tencentSmsProperties.getMaxSize() < 100) {
tencentSmsProperties.setMaxSize(200);
}
}
@Override
public void sendSms(List<String> phones, SmsRequest smsRequest) {
SendSmsRequest sendSmsRequest = new SendSmsRequest();
sendSmsRequest.setPhoneNumberSet(phones.toArray(new String[0]));
sendSmsRequest.setSmsSdkAppid(tencentSmsProperties.getAppId());
sendSmsRequest.setSign(tencentSmsProperties.getSign());
if (!StringUtils.hasLength(smsRequest.getTemplateCode())) {
throw new SmsRuntimeException("模板id不能为空");
}
Map<String, Object> paramsMap = smsRequest.getParamsMap();
Object template = paramsMap.get(SmsCommon.TEMPLATE_PARAM);
if (template == null) {
throw new SmsRuntimeException("参数不能为空");
}
List<String> lists = JSON.parseArray(JSON.toJSONString(template), String.class);
sendSmsRequest.setTemplateParamSet(lists.toArray(new String[0]));
if (paramsMap.containsKey(SmsCommon.SENDERID)) {
sendSmsRequest.setSenderId(paramsMap.get(SmsCommon.SENDERID).toString());
}
try {
smsClient.SendSms(sendSmsRequest);
} catch (TencentCloudSDKException e) {
throw new SmsRuntimeException("发送失败");
}
}
@Override
public SmsGranter getGranter(String typeName) {
if (TYPE_NAME.equals(typeName)) {
return this;
}
return null;
}
}

View File

@ -0,0 +1,138 @@
{
"groups": [
{
"name": "sms",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
},
{
"name": "sms.aliyun",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
},
{
"name": "sms.tencent",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
}
],
"properties": [
{
"name": "sms",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
},
{
"name": "sms.aliyun",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
},
{
"name": "sms.aliyun.enable",
"type": "java.lang.Boolean",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": false
},
{
"name": "sms.aliyun.accessKey",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": ""
},
{
"name": "sms.aliyun.accessSecret",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": ""
},
{
"name": "sms.aliyun.endpoint",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": ""
},
{
"name": "sms.aliyun.region",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": ""
},
{
"name": "sms.aliyun.templateCode",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": ""
},
{
"name": "sms.aliyun.maxSize",
"type": "java.lang.Integer",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": 200
},
{
"name": "sms.tencent",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
},
{
"name": "sms.tencent.enable",
"type": "java.lang.Boolean",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": false
},
{
"name": "sms.tencent.accessKey",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.accessSecret",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.endpoint",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.region",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.templateCode",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.sign",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.appId",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.senderId",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.maxSize",
"type": "java.lang.Integer",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": 200
}
]
}

View File

@ -0,0 +1,5 @@
#Generated by Maven
#Mon Jul 25 15:29:06 CST 2022
groupId=cn.zyjblogs.starter
artifactId=zyjblogs-sms-spring-boot-starter
version=1.0-SNAPSHOT

View File

@ -36,8 +36,20 @@
<dependency> <dependency>
<groupId>com.aliyun</groupId> <groupId>com.aliyun</groupId>
<artifactId>alibabacloud-dysmsapi20170525</artifactId> <artifactId>alibabacloud-dysmsapi20170525</artifactId>
<version>${alibabacloud-dysmsapi20170525.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java-sms</artifactId>
<!-- go to https://search.maven.org/search?q=tencentcloud-sdk-java and get the latest version. -->
<!-- 请到https://search.maven.org/search?q=tencentcloud-sdk-java查询所有版本最新版本如下 -->
<!-- <version>${tencentcloud-sdk-java.version}</version>-->
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.aliyun</groupId>-->
<!-- <artifactId>dysmsapi20170525</artifactId>-->
<!-- <version>${dysmsapi20170525.version}</version>-->
<!-- </dependency>-->
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@ -0,0 +1,138 @@
{
"groups": [
{
"name": "sms",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
},
{
"name": "sms.aliyun",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
},
{
"name": "sms.tencent",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
}
],
"properties": [
{
"name": "sms",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
},
{
"name": "sms.aliyun",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
},
{
"name": "sms.aliyun.enable",
"type": "java.lang.Boolean",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": false
},
{
"name": "sms.aliyun.accessKey",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": ""
},
{
"name": "sms.aliyun.accessSecret",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": ""
},
{
"name": "sms.aliyun.endpoint",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": ""
},
{
"name": "sms.aliyun.region",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": ""
},
{
"name": "sms.aliyun.templateCode",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": ""
},
{
"name": "sms.aliyun.maxSize",
"type": "java.lang.Integer",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$AliyunSmsProperties",
"defaultValue": 200
},
{
"name": "sms.tencent",
"type": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties"
},
{
"name": "sms.tencent.enable",
"type": "java.lang.Boolean",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": false
},
{
"name": "sms.tencent.accessKey",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.accessSecret",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.endpoint",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.region",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.templateCode",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.sign",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.appId",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.senderId",
"type": "java.lang.String",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": ""
},
{
"name": "sms.tencent.maxSize",
"type": "java.lang.Integer",
"sourceType": "cn.zyjblogs.starter.sms.config.SmsProperties$TencentSmsProperties",
"defaultValue": 200
}
]
}

View File

@ -1,2 +1,2 @@
#org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
# cn.zyjblogs.starter.minio.autoconfigure.MinioAutoConfiguration cn.zyjblogs.starter.sms.autoconfigure.SmsConfiguration

View File

@ -0,0 +1,5 @@
#Generated by Maven
#Mon Jul 25 15:29:06 CST 2022
groupId=cn.zyjblogs.starter
artifactId=zyjblogs-web-spring-boot-starter
version=1.0-SNAPSHOT