This commit is contained in:
2025-11-28 16:23:32 +08:00
commit a9e0e16c29
826 changed files with 89805 additions and 0 deletions

58
blade-starter-sms/pom.xml Normal file
View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>BladeX-Tool</artifactId>
<groupId>org.springblade</groupId>
<version>${revision}</version>
</parent>
<artifactId>blade-starter-sms</artifactId>
<name>${project.artifactId}</name>
<version>${project.parent.version}</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-tool</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-redis</artifactId>
</dependency>
<dependency>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.qcloudsms</groupId>
<artifactId>qcloudsms</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.yunpian.sdk</groupId>
<artifactId>yunpian-java-sdk</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-auto</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,119 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.model.SmsCode;
import org.springblade.core.sms.model.SmsData;
import org.springblade.core.sms.model.SmsResponse;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.http.HttpStatus;
import java.time.Duration;
import java.util.Collection;
import java.util.Map;
/**
* 阿里云短信发送类
*
* @author Chill
*/
@AllArgsConstructor
public class AliSmsTemplate implements SmsTemplate {
private static final int SUCCESS = 200;
private static final String FAIL = "fail";
private static final String OK = "ok";
private static final String DOMAIN = "dysmsapi.aliyuncs.com";
private static final String VERSION = "2017-05-25";
private static final String ACTION = "SendSms";
private final SmsProperties smsProperties;
private final IAcsClient acsClient;
private final BladeRedis bladeRedis;
@Override
public SmsResponse sendMessage(SmsData smsData, Collection<String> phones) {
CommonRequest request = new CommonRequest();
request.setSysMethod(MethodType.POST);
request.setSysDomain(DOMAIN);
request.setSysVersion(VERSION);
request.setSysAction(ACTION);
request.putQueryParameter("PhoneNumbers", StringUtil.join(phones));
request.putQueryParameter("TemplateCode", smsProperties.getTemplateId());
request.putQueryParameter("TemplateParam", JsonUtil.toJson(smsData.getParams()));
request.putQueryParameter("SignName", smsProperties.getSignName());
try {
CommonResponse response = acsClient.getCommonResponse(request);
Map<String, Object> data = JsonUtil.toMap(response.getData());
String code = FAIL;
if (data != null) {
code = String.valueOf(data.get("Code"));
}
return new SmsResponse(response.getHttpStatus() == SUCCESS && code.equalsIgnoreCase(OK), response.getHttpStatus(), response.getData());
} catch (ClientException e) {
e.printStackTrace();
return new SmsResponse(Boolean.FALSE, HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
}
}
@Override
public SmsCode sendValidate(SmsData smsData, String phone) {
SmsCode smsCode = new SmsCode();
boolean temp = sendSingle(smsData, phone);
if (temp && StringUtil.isNotBlank(smsData.getKey())) {
String id = StringUtil.randomUUID();
String value = smsData.getParams().get(smsData.getKey());
bladeRedis.setEx(cacheKey(phone, id), value, Duration.ofMinutes(30));
smsCode.setId(id).setValue(value);
} else {
smsCode.setSuccess(Boolean.FALSE);
}
return smsCode;
}
@Override
public boolean validateMessage(SmsCode smsCode) {
String id = smsCode.getId();
String value = smsCode.getValue();
String phone = smsCode.getPhone();
String cache = bladeRedis.get(cacheKey(phone, id));
if (StringUtil.isNotBlank(value) && StringUtil.equalsIgnoreCase(cache, value)) {
bladeRedis.del(cacheKey(phone, id));
return true;
}
return false;
}
}

View File

@@ -0,0 +1,94 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.sms.SmsManager;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.model.SmsCode;
import org.springblade.core.sms.model.SmsData;
import org.springblade.core.sms.model.SmsResponse;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.http.HttpStatus;
import java.time.Duration;
import java.util.Collection;
/**
* 七牛云短信发送类
*
* @author Chill
*/
@AllArgsConstructor
public class QiniuSmsTemplate implements SmsTemplate {
private final SmsProperties smsProperties;
private final SmsManager smsManager;
private final BladeRedis bladeRedis;
@Override
public SmsResponse sendMessage(SmsData smsData, Collection<String> phones) {
try {
Response response = smsManager.sendMessage(smsProperties.getTemplateId(), StringUtil.toStringArray(phones), smsData.getParams());
return new SmsResponse(response.isOK(), response.statusCode, response.toString());
} catch (QiniuException e) {
e.printStackTrace();
return new SmsResponse(Boolean.FALSE, HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
}
}
@Override
public SmsCode sendValidate(SmsData smsData, String phone) {
SmsCode smsCode = new SmsCode();
boolean temp = sendSingle(smsData, phone);
if (temp && StringUtil.isNotBlank(smsData.getKey())) {
String id = StringUtil.randomUUID();
String value = smsData.getParams().get(smsData.getKey());
bladeRedis.setEx(cacheKey(phone, id), value, Duration.ofMinutes(30));
smsCode.setId(id).setValue(value);
} else {
smsCode.setSuccess(Boolean.FALSE);
}
return smsCode;
}
@Override
public boolean validateMessage(SmsCode smsCode) {
String id = smsCode.getId();
String value = smsCode.getValue();
String phone = smsCode.getPhone();
String cache = bladeRedis.get(cacheKey(phone, id));
if (StringUtil.isNotBlank(value) && StringUtil.equalsIgnoreCase(cache, value)) {
bladeRedis.del(cacheKey(phone, id));
return true;
}
return false;
}
}

View File

@@ -0,0 +1,120 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms;
import org.springblade.core.sms.model.SmsCode;
import org.springblade.core.sms.model.SmsData;
import org.springblade.core.sms.model.SmsInfo;
import org.springblade.core.sms.model.SmsResponse;
import org.springblade.core.tool.utils.StringPool;
import org.springframework.util.StringUtils;
import java.util.Collection;
import java.util.Collections;
import static org.springblade.core.sms.constant.SmsConstant.CAPTCHA_KEY;
/**
* 短信通用封装
*
* @author Chill
*/
public interface SmsTemplate {
/**
* 缓存键值
*
* @param phone 手机号
* @param id 键值
* @return 缓存键值返回
*/
default String cacheKey(String phone, String id) {
return CAPTCHA_KEY + phone + StringPool.COLON + id;
}
/**
* 发送短信
*
* @param smsInfo 短信信息
* @return 发送返回
*/
default boolean send(SmsInfo smsInfo) {
return sendMulti(smsInfo.getSmsData(), smsInfo.getPhones());
}
/**
* 发送短信
*
* @param smsData 短信内容
* @param phone 手机号
* @return 发送返回
*/
default boolean sendSingle(SmsData smsData, String phone) {
if (StringUtils.isEmpty(phone)) {
return Boolean.FALSE;
}
return sendMulti(smsData, Collections.singletonList(phone));
}
/**
* 发送短信
*
* @param smsData 短信内容
* @param phones 手机号列表
* @return 发送返回
*/
default boolean sendMulti(SmsData smsData, Collection<String> phones) {
SmsResponse response = sendMessage(smsData, phones);
return response.isSuccess();
}
/**
* 发送短信
*
* @param smsData 短信内容
* @param phones 手机号列表
* @return 发送返回
*/
SmsResponse sendMessage(SmsData smsData, Collection<String> phones);
/**
* 发送验证码
*
* @param smsData 短信内容
* @param phone 手机号
* @return 发送返回
*/
SmsCode sendValidate(SmsData smsData, String phone);
/**
* 校验验证码
*
* @param smsCode 验证码内容
* @return 是否校验成功
*/
boolean validateMessage(SmsCode smsCode);
}

View File

@@ -0,0 +1,110 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms;
import com.github.qcloudsms.SmsMultiSender;
import com.github.qcloudsms.SmsMultiSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.model.SmsCode;
import org.springblade.core.sms.model.SmsData;
import org.springblade.core.sms.model.SmsResponse;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.http.HttpStatus;
import java.io.IOException;
import java.time.Duration;
import java.util.Collection;
/**
* 腾讯云短信发送类
*
* @author Chill
*/
@AllArgsConstructor
public class TencentSmsTemplate implements SmsTemplate {
private static final int SUCCESS = 0;
private static final String NATION_CODE = "86";
private final SmsProperties smsProperties;
private final SmsMultiSender smsSender;
private final BladeRedis bladeRedis;
@Override
public SmsResponse sendMessage(SmsData smsData, Collection<String> phones) {
try {
Collection<String> values = smsData.getParams().values();
String[] params = StringUtil.toStringArray(values);
SmsMultiSenderResult senderResult = smsSender.sendWithParam(
NATION_CODE,
StringUtil.toStringArray(phones),
Func.toInt(smsProperties.getTemplateId()),
params,
smsProperties.getSignName(),
StringPool.EMPTY, StringPool.EMPTY
);
return new SmsResponse(senderResult.result == SUCCESS, senderResult.result, senderResult.toString());
} catch (HTTPException | IOException e) {
e.printStackTrace();
return new SmsResponse(Boolean.FALSE, HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
}
}
@Override
public SmsCode sendValidate(SmsData smsData, String phone) {
SmsCode smsCode = new SmsCode();
boolean temp = sendSingle(smsData, phone);
if (temp && StringUtil.isNotBlank(smsData.getKey())) {
String id = StringUtil.randomUUID();
String value = smsData.getParams().get(smsData.getKey());
bladeRedis.setEx(cacheKey(phone, id), value, Duration.ofMinutes(30));
smsCode.setId(id).setValue(value);
} else {
smsCode.setSuccess(Boolean.FALSE);
}
return smsCode;
}
@Override
public boolean validateMessage(SmsCode smsCode) {
String id = smsCode.getId();
String value = smsCode.getValue();
String phone = smsCode.getPhone();
String cache = bladeRedis.get(cacheKey(phone, id));
if (StringUtil.isNotBlank(value) && StringUtil.equalsIgnoreCase(cache, value)) {
bladeRedis.del(cacheKey(phone, id));
return true;
}
return false;
}
}

View File

@@ -0,0 +1,100 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms;
import com.yunpian.sdk.YunpianClient;
import com.yunpian.sdk.constant.Code;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsBatchSend;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.model.SmsCode;
import org.springblade.core.sms.model.SmsData;
import org.springblade.core.sms.model.SmsResponse;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.PlaceholderUtil;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.StringUtil;
import java.time.Duration;
import java.util.Collection;
import java.util.Map;
/**
* 云片短信发送类
*
* @author Chill
*/
@AllArgsConstructor
public class YunpianSmsTemplate implements SmsTemplate {
private final SmsProperties smsProperties;
private final YunpianClient client;
private final BladeRedis bladeRedis;
@Override
public SmsResponse sendMessage(SmsData smsData, Collection<String> phones) {
String templateId = smsProperties.getTemplateId();
// 云片短信模板内容替换, 占位符格式为官方默认的 #code#
String templateText = PlaceholderUtil.getResolver(StringPool.HASH, StringPool.HASH).resolveByMap(
templateId, Kv.create().setAll(smsData.getParams())
);
Map<String, String> param = client.newParam(2);
param.put(YunpianClient.MOBILE, StringUtil.join(phones));
param.put(YunpianClient.TEXT, templateText);
Result<SmsBatchSend> result = client.sms().multi_send(param);
return new SmsResponse(result.getCode() == Code.OK, result.getCode(), result.toString());
}
@Override
public SmsCode sendValidate(SmsData smsData, String phone) {
SmsCode smsCode = new SmsCode();
boolean temp = sendSingle(smsData, phone);
if (temp && StringUtil.isNotBlank(smsData.getKey())) {
String id = StringUtil.randomUUID();
String value = smsData.getParams().get(smsData.getKey());
bladeRedis.setEx(cacheKey(phone, id), value, Duration.ofMinutes(30));
smsCode.setId(id).setValue(value);
} else {
smsCode.setSuccess(Boolean.FALSE);
}
return smsCode;
}
@Override
public boolean validateMessage(SmsCode smsCode) {
String id = smsCode.getId();
String value = smsCode.getValue();
String phone = smsCode.getPhone();
String cache = bladeRedis.get(cacheKey(phone, id));
if (StringUtil.isNotBlank(value) && StringUtil.equalsIgnoreCase(cache, value)) {
bladeRedis.del(cacheKey(phone, id));
return true;
}
return false;
}
}

View File

@@ -0,0 +1,63 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.config;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.AliSmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
/**
* 阿里云短信配置类
*
* @author Chill
*/
@AutoConfiguration
@AllArgsConstructor
@ConditionalOnClass(IAcsClient.class)
@EnableConfigurationProperties(SmsProperties.class)
@ConditionalOnProperty(value = "sms.name", havingValue = "aliyun")
public class AliSmsConfiguration {
private final BladeRedis bladeRedis;
@Bean
public AliSmsTemplate aliSmsTemplate(SmsProperties smsProperties) {
IClientProfile profile = DefaultProfile.getProfile(smsProperties.getRegionId(), smsProperties.getAccessKey(), smsProperties.getSecretKey());
IAcsClient acsClient = new DefaultAcsClient(profile);
return new AliSmsTemplate(smsProperties, acsClient, bladeRedis);
}
}

View File

@@ -0,0 +1,61 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.config;
import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.QiniuSmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
/**
* 阿里云短信配置类
*
* @author Chill
*/
@AutoConfiguration
@AllArgsConstructor
@ConditionalOnClass(SmsManager.class)
@EnableConfigurationProperties(SmsProperties.class)
@ConditionalOnProperty(value = "sms.name", havingValue = "qiniu")
public class QiniuSmsConfiguration {
private final BladeRedis bladeRedis;
@Bean
public QiniuSmsTemplate qiniuSmsTemplate(SmsProperties smsProperties) {
Auth auth = Auth.create(smsProperties.getAccessKey(), smsProperties.getSecretKey());
SmsManager smsManager = new SmsManager(auth);
return new QiniuSmsTemplate(smsProperties, smsManager, bladeRedis);
}
}

View File

@@ -0,0 +1,42 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.config;
import lombok.AllArgsConstructor;
import org.springblade.core.sms.props.SmsProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
/**
* Sms配置类
*
* @author Chill
*/
@AutoConfiguration
@AllArgsConstructor
@EnableConfigurationProperties(SmsProperties.class)
public class SmsConfiguration {
}

View File

@@ -0,0 +1,60 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.config;
import com.github.qcloudsms.SmsMultiSender;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.TencentSmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.tool.utils.Func;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
/**
* 腾讯云短信配置类
*
* @author Chill
*/
@AutoConfiguration
@AllArgsConstructor
@ConditionalOnClass(SmsMultiSender.class)
@EnableConfigurationProperties(SmsProperties.class)
@ConditionalOnProperty(value = "sms.name", havingValue = "tencent")
public class TencentSmsConfiguration {
private final BladeRedis bladeRedis;
@Bean
public TencentSmsTemplate tencentSmsTemplate(SmsProperties smsProperties) {
SmsMultiSender smsSender = new SmsMultiSender(Func.toInt(smsProperties.getAccessKey()), smsProperties.getSecretKey());
return new TencentSmsTemplate(smsProperties, smsSender, bladeRedis);
}
}

View File

@@ -0,0 +1,59 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.config;
import com.yunpian.sdk.YunpianClient;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.YunpianSmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
/**
* 云片短信配置类
*
* @author Chill
*/
@AutoConfiguration
@AllArgsConstructor
@ConditionalOnClass(YunpianClient.class)
@EnableConfigurationProperties(SmsProperties.class)
@ConditionalOnProperty(value = "sms.name", havingValue = "yunpian")
public class YunpianSmsConfiguration {
private final BladeRedis bladeRedis;
@Bean
public YunpianSmsTemplate yunpianSmsTemplate(SmsProperties smsProperties) {
YunpianClient client = new YunpianClient(smsProperties.getAccessKey()).init();
return new YunpianSmsTemplate(smsProperties, client, bladeRedis);
}
}

View File

@@ -0,0 +1,40 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.constant;
/**
* 短信服务常量
*
* @author Chill
*/
public interface SmsConstant {
/**
* 通用缓存key
*/
String CAPTCHA_KEY = "blade:sms::captcha:";
}

View File

@@ -0,0 +1,89 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Sms枚举类
*
* @author Chill
*/
@Getter
@AllArgsConstructor
public enum SmsEnum {
/**
* yunpian
*/
YUNPIAN("yunpian", 1),
/**
* qiniu
*/
QINIU("qiniu", 2),
/**
* ali
*/
ALI("ali", 3),
/**
* tencent
*/
TENCENT("tencent", 4),
;
/**
* 名称
*/
final String name;
/**
* 类型
*/
final int category;
/**
* 匹配枚举值
*
* @param name 名称
* @return OssEnum
*/
public static SmsEnum of(String name) {
if (name == null) {
return null;
}
SmsEnum[] values = SmsEnum.values();
for (SmsEnum smsEnum : values) {
if (smsEnum.name.equals(name)) {
return smsEnum;
}
}
return null;
}
}

View File

@@ -0,0 +1,55 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Sms类型枚举
*
* @author Chill
*/
@Getter
@AllArgsConstructor
public enum SmsStatusEnum {
/**
* 关闭
*/
DISABLE(1),
/**
* 启用
*/
ENABLE(2),
;
/**
* 类型编号
*/
final int num;
}

View File

@@ -0,0 +1,68 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serial;
import java.io.Serializable;
/**
* 校验信息
*
* @author Chill
*/
@Data
@Accessors(chain = true)
public class SmsCode implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 是否成功
*/
private boolean success = Boolean.TRUE;
/**
* 变量phone,用于redis进行比对
*/
private String phone;
/**
* 变量id,用于redis进行比对
*/
private String id;
/**
* 变量值,用于redis进行比对
*/
@JsonIgnore
private String value;
}

View File

@@ -0,0 +1,66 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.model;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serial;
import java.io.Serializable;
import java.util.Map;
/**
* 通知内容
*
* @author Chill
*/
@Data
@Accessors(chain = true)
public class SmsData implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 构造器
*
* @param params 参数列表
*/
public SmsData(Map<String, String> params) {
this.params = params;
}
/**
* 变量key,用于从参数列表获取变量值
*/
private String key;
/**
* 参数列表
*/
private Map<String, String> params;
}

View File

@@ -0,0 +1,56 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.model;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serial;
import java.io.Serializable;
import java.util.Collection;
/**
* 通知信息
*
* @author Chill
*/
@Data
@Accessors(chain = true)
public class SmsInfo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 通知内容
*/
private SmsData smsData;
/**
* 号码列表
*/
private Collection<String> phones;
}

View File

@@ -0,0 +1,61 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 短信返回集合
*
* @author Chill
*/
@Data
@AllArgsConstructor
public class SmsResponse implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 是否成功
*/
private boolean success;
/**
* 状态码
*/
private Integer code;
/**
* 返回消息
*/
private String msg;
}

View File

@@ -0,0 +1,75 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.core.sms.props;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* 云短信配置
*
* @author Chill
*/
@Data
@ConfigurationProperties(prefix = "sms")
public class SmsProperties {
/**
* 是否启用
*/
private Boolean enabled;
/**
* 短信服务名称
*/
private String name;
/**
* 短信模板ID
*/
private String templateId;
/**
* regionId
*/
private String regionId = "cn-hangzhou";
/**
* accessKey
*/
private String accessKey;
/**
* secretKey
*/
private String secretKey;
/**
* 短信签名
*/
private String signName;
}