From eb056c1cac152bf82bff5c7115186a66561bc73b Mon Sep 17 00:00:00 2001 From: liriming <1343021927@qq.com> Date: 星期三, 04 十二月 2024 13:24:24 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- /dev/null | 52 ------- shasteel-api/pom.xml | 22 --- shasteel-biz/src/main/resources/application-dev.yaml | 85 ++---------- shasteel-biz/pom.xml | 26 --- shasteel-biz/src/main/resources/application-test.yaml | 56 -------- shasteel-biz/src/main/resources/application.yaml | 4 pom.xml | 112 ++------------- shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/security/config/SecurityConfiguration.java | 16 +- 8 files changed, 41 insertions(+), 332 deletions(-) diff --git a/pom.xml b/pom.xml index 37b3502..600c853 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,8 @@ <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version> <flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version> <!-- 统一依赖管理 --> + <spring.framework.version>5.3.39</spring.framework.version> + <spring.security.version>5.8.14</spring.security.version> <spring.boot.version>2.7.18</spring.boot.version> <spring.cloud.version>2021.0.9</spring.cloud.version> <spring.cloud.alibaba.version>2021.0.6.1</spring.cloud.alibaba.version> @@ -82,24 +84,26 @@ <ip2region.version>2.7.0</ip2region.version> <bizlog-sdk.version>3.0.6</bizlog-sdk.version> <reflections.version>0.10.2</reflections.version> - <!-- 三方云服务相关 --> - <okio.version>3.5.0</okio.version> - <okhttp3.version>4.11.0</okhttp3.version> - <commons-io.version>2.15.1</commons-io.version> - <minio.version>8.5.7</minio.version> - <aliyun-java-sdk-core.version>4.6.4</aliyun-java-sdk-core.version> - <aliyun-java-sdk-dysmsapi.version>2.2.1</aliyun-java-sdk-dysmsapi.version> - <tencentcloud-sdk-java.version>3.1.880</tencentcloud-sdk-java.version> - <justauth.version>1.0.8</justauth.version> - <jimureport.version>1.6.6</jimureport.version> - <xercesImpl.version>2.12.2</xercesImpl.version> - <weixin-java.version>4.6.0</weixin-java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencyManagement> <dependencies> <!-- 统一依赖管理 --> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-framework-bom</artifactId> <!-- JDK8 版本独有:保证 Spring Framework 尽量高 --> + <version>${spring.framework.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-bom</artifactId> <!-- JDK8 版本独有:保证 Spring Security 尽量高 --> + <version>${spring.security.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> @@ -383,12 +387,6 @@ </dependency> <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>${commons-io.version}</version> - </dependency> - - <dependency> <groupId>org.apache.tika</groupId> <artifactId>tika-core</artifactId> <!-- 文件类型的识别 --> <version>${tika-core.version}</version> @@ -473,84 +471,6 @@ <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> <version>${reflections.version}</version> - </dependency> - - <!-- 三方云服务相关 --> - <dependency> - <groupId>com.squareup.okio</groupId> - <artifactId>okio</artifactId> - <version>${okio.version}</version> - </dependency> - <dependency> - <groupId>com.squareup.okhttp3</groupId> - <artifactId>okhttp</artifactId> - <version>${okhttp3.version}</version> - </dependency> - <dependency> - <groupId>io.minio</groupId> - <artifactId>minio</artifactId> - <version>${minio.version}</version> - </dependency> - - <dependency> - <groupId>com.github.binarywang</groupId> - <artifactId>weixin-java-pay</artifactId> - <version>${weixin-java.version}</version> - </dependency> - <dependency> - <groupId>com.github.binarywang</groupId> - <artifactId>wx-java-mp-spring-boot-starter</artifactId> - <version>${weixin-java.version}</version> - </dependency> - <dependency> - <groupId>com.github.binarywang</groupId> - <artifactId>wx-java-miniapp-spring-boot-starter</artifactId> - <version>${weixin-java.version}</version> - </dependency> - - <dependency> - <groupId>com.xingyuv</groupId> - <artifactId>spring-boot-starter-justauth</artifactId> <!-- 社交登陆(例如说,个人微信、企业微信等等) --> - <version>${justauth.version}</version> - <exclusions> - <exclusion> - <groupId>cn.hutool</groupId> - <artifactId>hutool-core</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>com.github.binarywang</groupId> - <artifactId>wx-java-miniapp-spring-boot-starter</artifactId> - <version>${weixin-java.version}</version> - </dependency> - - <!-- SMS SDK begin --> - <dependency> - <groupId>com.aliyun</groupId> - <artifactId>aliyun-java-sdk-core</artifactId> - <version>${aliyun-java-sdk-core.version}</version> - <exclusions> - <exclusion> - <artifactId>opentracing-api</artifactId> - <groupId>io.opentracing</groupId> - </exclusion> - <exclusion> - <artifactId>opentracing-util</artifactId> - <groupId>io.opentracing</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>com.aliyun</groupId> - <artifactId>aliyun-java-sdk-dysmsapi</artifactId> - <version>${aliyun-java-sdk-dysmsapi.version}</version> - </dependency> - <dependency> - <groupId>com.tencentcloudapi</groupId> - <artifactId>tencentcloud-sdk-java-sms</artifactId> - <version>${tencentcloud-sdk-java.version}</version> </dependency> </dependencies> diff --git a/shasteel-api/pom.xml b/shasteel-api/pom.xml index f33c1e3..127750c 100644 --- a/shasteel-api/pom.xml +++ b/shasteel-api/pom.xml @@ -45,26 +45,4 @@ </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-assembly-plugin</artifactId> - <version>3.3.0</version> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - </project> diff --git a/shasteel-biz/pom.xml b/shasteel-biz/pom.xml index 0166a9e..e18457a 100644 --- a/shasteel-biz/pom.xml +++ b/shasteel-biz/pom.xml @@ -110,32 +110,6 @@ <artifactId>spring-boot-starter-captcha-plus</artifactId> <!-- 验证码,一般用于登录使用 --> </dependency> - <!-- 三方云服务相关 --> - <dependency> - <groupId>com.xingyuv</groupId> - <artifactId>spring-boot-starter-justauth</artifactId> <!-- 社交登陆(例如说,个人微信、企业微信等等) --> - </dependency> - <dependency> - <groupId>com.github.binarywang</groupId> - <artifactId>wx-java-mp-spring-boot-starter</artifactId> <!-- 微信登录(公众号) --> - </dependency> - <dependency> - <groupId>com.github.binarywang</groupId> - <artifactId>wx-java-miniapp-spring-boot-starter</artifactId> <!-- 微信登录(小程序) --> - </dependency> - <dependency> - <groupId>com.aliyun</groupId> - <artifactId>aliyun-java-sdk-core</artifactId> <!-- 短信(阿里云) --> - </dependency> - <dependency> - <groupId>com.aliyun</groupId> - <artifactId>aliyun-java-sdk-dysmsapi</artifactId> <!-- 短信(阿里云) --> - </dependency> - <dependency> - <groupId>com.tencentcloudapi</groupId> - <artifactId>tencentcloud-sdk-java-sms</artifactId> <!-- 短信(腾讯云) --> - </dependency> - <!-- 定时任务 --> <dependency> <groupId>org.quartz-scheduler</groupId> diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/security/config/SecurityConfiguration.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/security/config/SecurityConfiguration.java index f752f65..0a210d4 100644 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/security/config/SecurityConfiguration.java +++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/security/config/SecurityConfiguration.java @@ -5,7 +5,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; +import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer; /** * System 模块的 Security 配置 @@ -18,18 +18,18 @@ return new AuthorizeRequestsCustomizer() { @Override - public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) { + public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) { // TODO iailab:这个每个项目都需要重复配置,得捉摸有没通用的方案 // Swagger 接口文档 - registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据 - .antMatchers("/swagger-ui.html").permitAll(); // Swagger UI + registry.requestMatchers("/v3/api-docs/**").permitAll() // 元数据 + .requestMatchers("/swagger-ui.html").permitAll(); // Swagger UI // Druid 监控 - registry.antMatchers("/druid/**").anonymous(); + registry.requestMatchers("/druid/**").anonymous(); // Spring Boot Actuator 的安全配置 - registry.antMatchers("/actuator").anonymous() - .antMatchers("/actuator/**").anonymous(); + registry.requestMatchers("/actuator").anonymous() + .requestMatchers("/actuator/**").anonymous(); // RPC 服务的安全配置 - registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll(); + registry.requestMatchers(ApiConstants.PREFIX + "/**").permitAll(); } }; diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/config/SmsCodeProperties.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/config/SmsCodeProperties.java deleted file mode 100644 index b8e3c86..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/config/SmsCodeProperties.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; - -import javax.validation.constraints.NotNull; -import java.time.Duration; - -@ConfigurationProperties(prefix = "iailab.sms-code") -@Validated -@Data -public class SmsCodeProperties { - - /** - * 过期时间 - */ - @NotNull(message = "过期时间不能为空") - private Duration expireTimes; - /** - * 短信发送频率 - */ - @NotNull(message = "短信发送频率不能为空") - private Duration sendFrequency; - /** - * 每日发送最大数量 - */ - @NotNull(message = "每日发送最大数量不能为空") - private Integer sendMaximumQuantityPerDay; - /** - * 验证码最小值 - */ - @NotNull(message = "验证码最小值不能为空") - private Integer beginCode; - /** - * 验证码最大值 - */ - @NotNull(message = "验证码最大值不能为空") - private Integer endCode; - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/config/SmsConfiguration.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/config/SmsConfiguration.java deleted file mode 100644 index 94fd5db..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/config/SmsConfiguration.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.config; - -import com.iailab.module.shasteel.framework.sms.core.client.SmsClientFactory; -import com.iailab.module.shasteel.framework.sms.core.client.impl.SmsClientFactoryImpl; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * 短信配置类,包括短信客户端、短信验证码两部分 - * - * @author iailab - */ -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties(SmsCodeProperties.class) -public class SmsConfiguration { - - @Bean - public SmsClientFactory smsClientFactory() { - return new SmsClientFactoryImpl(); - } - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/SmsClient.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/SmsClient.java deleted file mode 100644 index 4795cb6..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/SmsClient.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.client; - -import com.iailab.framework.common.core.KeyValue; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsReceiveRespDTO; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsSendRespDTO; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsTemplateRespDTO; - -import java.util.List; - -/** - * 短信客户端,用于对接各短信平台的 SDK,实现短信发送等功能 - * - * @author zzf - * @since 2021/1/25 14:14 - */ -public interface SmsClient { - - /** - * 获得渠道编号 - * - * @return 渠道编号 - */ - Long getId(); - - /** - * 发送消息 - * - * @param logId 日志编号 - * @param mobile 手机号 - * @param apiTemplateId 短信 API 的模板编号 - * @param templateParams 短信模板参数。通过 List 数组,保证参数的顺序 - * @return 短信发送结果 - */ - SmsSendRespDTO sendSms(Long logId, String mobile, String apiTemplateId, - List<KeyValue<String, Object>> templateParams) throws Throwable; - - /** - * 解析接收短信的接收结果 - * - * @param text 结果 - * @return 结果内容 - * @throws Throwable 当解析 text 发生异常时,则会抛出异常 - */ - List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) throws Throwable; - - /** - * 查询指定的短信模板 - * - * @param apiTemplateId 短信 API 的模板编号 - * @return 短信模板 - */ - SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) throws Throwable; - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/SmsClientFactory.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/SmsClientFactory.java deleted file mode 100644 index 44198b5..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/SmsClientFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.client; - -import com.iailab.module.shasteel.framework.sms.core.property.SmsChannelProperties; - -/** - * 短信客户端的工厂接口 - * - * @author zzf - * @since 2021/1/28 14:01 - */ -public interface SmsClientFactory { - - /** - * 获得短信 Client - * - * @param channelId 渠道编号 - * @return 短信 Client - */ - SmsClient getSmsClient(Long channelId); - - /** - * 获得短信 Client - * - * @param channelCode 渠道编码 - * @return 短信 Client - */ - SmsClient getSmsClient(String channelCode); - - /** - * 创建短信 Client - * - * @param properties 配置对象 - */ - void createOrUpdateSmsClient(SmsChannelProperties properties); - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/dto/SmsReceiveRespDTO.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/dto/SmsReceiveRespDTO.java deleted file mode 100644 index 9b6c822..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/dto/SmsReceiveRespDTO.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.client.dto; - -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 消息接收 Response DTO - * - * @author iailab - */ -@Data -public class SmsReceiveRespDTO { - - /** - * 是否接收成功 - */ - private Boolean success; - /** - * API 接收结果的编码 - */ - private String errorCode; - /** - * API 接收结果的说明 - */ - private String errorMsg; - - /** - * 手机号 - */ - private String mobile; - /** - * 用户接收时间 - */ - private LocalDateTime receiveTime; - - /** - * 短信 API 发送返回的序号 - */ - private String serialNo; - /** - * 短信日志编号 - * - * 对应 SysSmsLogDO 的编号 - */ - private Long logId; - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/dto/SmsSendRespDTO.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/dto/SmsSendRespDTO.java deleted file mode 100644 index ef42516..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/dto/SmsSendRespDTO.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.client.dto; - -import lombok.Data; - -/** - * 短信发送 Response DTO - * - * @author iailab - */ -@Data -public class SmsSendRespDTO { - - /** - * 是否成功 - */ - private Boolean success; - - /** - * API 请求编号 - */ - private String apiRequestId; - - // ==================== 成功时字段 ==================== - - /** - * 短信 API 发送返回的序号 - */ - private String serialNo; - - // ==================== 失败时字段 ==================== - - /** - * API 返回错误码 - * - * 由于第三方的错误码可能是字符串,所以使用 String 类型 - */ - private String apiCode; - /** - * API 返回提示 - */ - private String apiMsg; - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/dto/SmsTemplateRespDTO.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/dto/SmsTemplateRespDTO.java deleted file mode 100644 index b2c5595..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/dto/SmsTemplateRespDTO.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.client.dto; - -import com.iailab.module.shasteel.framework.sms.core.enums.SmsTemplateAuditStatusEnum; -import lombok.Data; - -/** - * 短信模板 Response DTO - * - * @author iailab - */ -@Data -public class SmsTemplateRespDTO { - - /** - * 模板编号 - */ - private String id; - /** - * 短信内容 - */ - private String content; - /** - * 审核状态 - * - * 枚举 {@link SmsTemplateAuditStatusEnum} - */ - private Integer auditStatus; - /** - * 审核未通过的理由 - */ - private String auditReason; - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/AbstractSmsClient.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/AbstractSmsClient.java deleted file mode 100644 index a9a026d..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/AbstractSmsClient.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.client.impl; - -import com.iailab.module.shasteel.framework.sms.core.client.SmsClient; -import com.iailab.module.shasteel.framework.sms.core.property.SmsChannelProperties; -import lombok.extern.slf4j.Slf4j; - -/** - * 短信客户端的抽象类,提供模板方法,减少子类的冗余代码 - * - * @author zzf - * @since 2021/2/1 9:28 - */ -@Slf4j -public abstract class AbstractSmsClient implements SmsClient { - - /** - * 短信渠道配置 - */ - protected volatile SmsChannelProperties properties; - - public AbstractSmsClient(SmsChannelProperties properties) { - this.properties = properties; - } - - /** - * 初始化 - */ - public final void init() { - doInit(); - log.debug("[init][配置({}) 初始化完成]", properties); - } - - /** - * 自定义初始化 - */ - protected abstract void doInit(); - - public final void refresh(SmsChannelProperties properties) { - // 判断是否更新 - if (properties.equals(this.properties)) { - return; - } - log.info("[refresh][配置({})发生变化,重新初始化]", properties); - this.properties = properties; - // 初始化 - this.init(); - } - - @Override - public Long getId() { - return properties.getId(); - } - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/AliyunSmsClient.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/AliyunSmsClient.java deleted file mode 100644 index 31489b2..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/AliyunSmsClient.java +++ /dev/null @@ -1,182 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.client.impl; - -import cn.hutool.core.lang.Assert; -import com.aliyuncs.DefaultAcsClient; -import com.aliyuncs.IAcsClient; -import com.aliyuncs.dysmsapi.model.v20170525.QuerySmsTemplateRequest; -import com.aliyuncs.dysmsapi.model.v20170525.QuerySmsTemplateResponse; -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; -import com.aliyuncs.profile.DefaultProfile; -import com.aliyuncs.profile.IClientProfile; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.VisibleForTesting; -import com.iailab.framework.common.core.KeyValue; -import com.iailab.framework.common.util.collection.MapUtils; -import com.iailab.framework.common.util.json.JsonUtils; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsReceiveRespDTO; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsSendRespDTO; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsTemplateRespDTO; -import com.iailab.module.shasteel.framework.sms.core.enums.SmsTemplateAuditStatusEnum; -import com.iailab.module.shasteel.framework.sms.core.property.SmsChannelProperties; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Objects; - -import static com.iailab.framework.common.util.collection.CollectionUtils.convertList; -import static com.iailab.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; -import static com.iailab.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT; - -/** - * 阿里短信客户端的实现类 - * - * @author zzf - * @since 2021/1/25 14:17 - */ -@Slf4j -public class AliyunSmsClient extends AbstractSmsClient { - - /** - * 调用成功 code - */ - public static final String API_CODE_SUCCESS = "OK"; - - /** - * REGION, 使用杭州 - */ - private static final String ENDPOINT = "cn-hangzhou"; - - /** - * 阿里云客户端 - */ - private volatile IAcsClient client; - - public AliyunSmsClient(SmsChannelProperties properties) { - super(properties); - Assert.notEmpty(properties.getApiKey(), "apiKey 不能为空"); - Assert.notEmpty(properties.getApiSecret(), "apiSecret 不能为空"); - } - - @Override - protected void doInit() { - IClientProfile profile = DefaultProfile.getProfile(ENDPOINT, properties.getApiKey(), properties.getApiSecret()); - client = new DefaultAcsClient(profile); - } - - @Override - public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId, - List<KeyValue<String, Object>> templateParams) throws Throwable { - // 构建请求 - SendSmsRequest request = new SendSmsRequest(); - request.setPhoneNumbers(mobile); - request.setSignName(properties.getSignature()); - request.setTemplateCode(apiTemplateId); - request.setTemplateParam(JsonUtils.toJsonString(MapUtils.convertMap(templateParams))); - request.setOutId(String.valueOf(sendLogId)); - // 执行请求 - SendSmsResponse response = client.getAcsResponse(request); - return new SmsSendRespDTO().setSuccess(Objects.equals(response.getCode(), API_CODE_SUCCESS)).setSerialNo(response.getBizId()) - .setApiRequestId(response.getRequestId()).setApiCode(response.getCode()).setApiMsg(response.getMessage()); - } - - @Override - public List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) { - List<SmsReceiveStatus> statuses = JsonUtils.parseArray(text, SmsReceiveStatus.class); - return convertList(statuses, status -> new SmsReceiveRespDTO().setSuccess(status.getSuccess()) - .setErrorCode(status.getErrCode()).setErrorMsg(status.getErrMsg()) - .setMobile(status.getPhoneNumber()).setReceiveTime(status.getReportTime()) - .setSerialNo(status.getBizId()).setLogId(Long.valueOf(status.getOutId()))); - } - - @Override - public SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) throws Throwable { - // 构建请求 - QuerySmsTemplateRequest request = new QuerySmsTemplateRequest(); - request.setTemplateCode(apiTemplateId); - // 执行请求 - QuerySmsTemplateResponse response = client.getAcsResponse(request); - if (response.getTemplateStatus() == null) { - return null; - } - return new SmsTemplateRespDTO().setId(response.getTemplateCode()).setContent(response.getTemplateContent()) - .setAuditStatus(convertSmsTemplateAuditStatus(response.getTemplateStatus())).setAuditReason(response.getReason()); - } - - @VisibleForTesting - Integer convertSmsTemplateAuditStatus(Integer templateStatus) { - switch (templateStatus) { - case 0: return SmsTemplateAuditStatusEnum.CHECKING.getStatus(); - case 1: return SmsTemplateAuditStatusEnum.SUCCESS.getStatus(); - case 2: return SmsTemplateAuditStatusEnum.FAIL.getStatus(); - default: throw new IllegalArgumentException(String.format("未知审核状态(%d)", templateStatus)); - } - } - - /** - * 短信接收状态 - * - * 参见 <a href="https://help.aliyun.com/document_detail/101867.html">文档</a> - * - * @author iailab - */ - @Data - public static class SmsReceiveStatus { - - /** - * 手机号 - */ - @JsonProperty("phone_number") - private String phoneNumber; - /** - * 发送时间 - */ - @JsonProperty("send_time") - @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) - private LocalDateTime sendTime; - /** - * 状态报告时间 - */ - @JsonProperty("report_time") - @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) - private LocalDateTime reportTime; - /** - * 是否接收成功 - */ - private Boolean success; - /** - * 状态报告说明 - */ - @JsonProperty("err_msg") - private String errMsg; - /** - * 状态报告编码 - */ - @JsonProperty("err_code") - private String errCode; - /** - * 发送序列号 - */ - @JsonProperty("biz_id") - private String bizId; - /** - * 用户序列号 - * - * 这里我们传递的是 SysSmsLogDO 的日志编号 - */ - @JsonProperty("out_id") - private String outId; - /** - * 短信长度,例如说 1、2、3 - * - * 140 字节算一条短信,短信长度超过 140 字节时会拆分成多条短信发送 - */ - @JsonProperty("sms_size") - private Integer smsSize; - - } - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/DebugDingTalkSmsClient.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/DebugDingTalkSmsClient.java deleted file mode 100644 index 680ac2f..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/DebugDingTalkSmsClient.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.client.impl; - -import cn.hutool.core.codec.Base64; -import cn.hutool.core.lang.Assert; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.crypto.digest.DigestUtil; -import cn.hutool.crypto.digest.HmacAlgorithm; -import cn.hutool.http.HttpUtil; -import com.iailab.framework.common.core.KeyValue; -import com.iailab.framework.common.util.collection.MapUtils; -import com.iailab.framework.common.util.json.JsonUtils; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsReceiveRespDTO; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsSendRespDTO; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsTemplateRespDTO; -import com.iailab.module.shasteel.framework.sms.core.enums.SmsTemplateAuditStatusEnum; -import com.iailab.module.shasteel.framework.sms.core.property.SmsChannelProperties; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * 基于钉钉 WebHook 实现的调试的短信客户端实现类 - * - * 考虑到省钱,我们使用钉钉 WebHook 模拟发送短信,方便调试。 - * - * @author iailab - */ -public class DebugDingTalkSmsClient extends AbstractSmsClient { - - public DebugDingTalkSmsClient(SmsChannelProperties properties) { - super(properties); - Assert.notEmpty(properties.getApiKey(), "apiKey 不能为空"); - Assert.notEmpty(properties.getApiSecret(), "apiSecret 不能为空"); - } - - @Override - protected void doInit() { - } - - @Override - public SmsSendRespDTO sendSms(Long sendLogId, String mobile, - String apiTemplateId, List<KeyValue<String, Object>> templateParams) throws Throwable { - // 构建请求 - String url = buildUrl("robot/send"); - Map<String, Object> params = new HashMap<>(); - params.put("msgtype", "text"); - String content = String.format("【模拟短信】\n手机号:%s\n短信日志编号:%d\n模板参数:%s", - mobile, sendLogId, MapUtils.convertMap(templateParams)); - params.put("text", MapUtil.builder().put("content", content).build()); - // 执行请求 - String responseText = HttpUtil.post(url, JsonUtils.toJsonString(params)); - // 解析结果 - Map<?, ?> responseObj = JsonUtils.parseObject(responseText, Map.class); - String errorCode = MapUtil.getStr(responseObj, "errcode"); - return new SmsSendRespDTO().setSuccess(Objects.equals(errorCode, "0")).setSerialNo(StrUtil.uuid()) - .setApiCode(errorCode).setApiMsg(MapUtil.getStr(responseObj, "errorMsg")); - } - - /** - * 构建请求地址 - * - * 参见 <a href="https://developers.dingtalk.com/document/app/custom-robot-access/title-nfv-794-g71">文档</a> - * - * @param path 请求路径 - * @return 请求地址 - */ - @SuppressWarnings("SameParameterValue") - private String buildUrl(String path) { - // 生成 timestamp - long timestamp = System.currentTimeMillis(); - // 生成 sign - String secret = properties.getApiSecret(); - String stringToSign = timestamp + "\n" + secret; - byte[] signData = DigestUtil.hmac(HmacAlgorithm.HmacSHA256, StrUtil.bytes(secret)).digest(stringToSign); - String sign = Base64.encode(signData); - // 构建最终 URL - return String.format("https://oapi.dingtalk.com/%s?access_token=%s×tamp=%d&sign=%s", - path, properties.getApiKey(), timestamp, sign); - } - - @Override - public List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) { - throw new UnsupportedOperationException("模拟短信客户端,暂时无需解析回调"); - } - - @Override - public SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) { - return new SmsTemplateRespDTO().setId(apiTemplateId).setContent("") - .setAuditStatus(SmsTemplateAuditStatusEnum.SUCCESS.getStatus()).setAuditReason(""); - } - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/SmsClientFactoryImpl.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/SmsClientFactoryImpl.java deleted file mode 100644 index de36e6d..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/SmsClientFactoryImpl.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.client.impl; - -import com.iailab.module.shasteel.framework.sms.core.client.SmsClient; -import com.iailab.module.shasteel.framework.sms.core.client.SmsClientFactory; -import com.iailab.module.shasteel.framework.sms.core.enums.SmsChannelEnum; -import com.iailab.module.shasteel.framework.sms.core.property.SmsChannelProperties; -import lombok.extern.slf4j.Slf4j; -import org.springframework.util.Assert; -import org.springframework.validation.annotation.Validated; - -import java.util.Arrays; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * 短信客户端工厂接口 - * - * @author zzf - */ -@Validated -@Slf4j -public class SmsClientFactoryImpl implements SmsClientFactory { - - /** - * 短信客户端 Map - * key:渠道编号,使用 {@link SmsChannelProperties#getId()} - */ - private final ConcurrentMap<Long, AbstractSmsClient> channelIdClients = new ConcurrentHashMap<>(); - - /** - * 短信客户端 Map - * key:渠道编码,使用 {@link SmsChannelProperties#getCode()} ()} - * - * 注意,一些场景下,需要获得某个渠道类型的客户端,所以需要使用它。 - * 例如说,解析短信接收结果,是相对通用的,不需要使用某个渠道编号的 {@link #channelIdClients} - */ - private final ConcurrentMap<String, AbstractSmsClient> channelCodeClients = new ConcurrentHashMap<>(); - - public SmsClientFactoryImpl() { - // 初始化 channelCodeClients 集合 - Arrays.stream(SmsChannelEnum.values()).forEach(channel -> { - // 创建一个空的 SmsChannelProperties 对象 - SmsChannelProperties properties = new SmsChannelProperties().setCode(channel.getCode()) - .setApiKey("default default").setApiSecret("default"); - // 创建 Sms 客户端 - AbstractSmsClient smsClient = createSmsClient(properties); - channelCodeClients.put(channel.getCode(), smsClient); - }); - } - - @Override - public SmsClient getSmsClient(Long channelId) { - return channelIdClients.get(channelId); - } - - @Override - public SmsClient getSmsClient(String channelCode) { - return channelCodeClients.get(channelCode); - } - - @Override - public void createOrUpdateSmsClient(SmsChannelProperties properties) { - AbstractSmsClient client = channelIdClients.get(properties.getId()); - if (client == null) { - client = this.createSmsClient(properties); - client.init(); - channelIdClients.put(client.getId(), client); - } else { - client.refresh(properties); - } - } - - private AbstractSmsClient createSmsClient(SmsChannelProperties properties) { - SmsChannelEnum channelEnum = SmsChannelEnum.getByCode(properties.getCode()); - Assert.notNull(channelEnum, String.format("渠道类型(%s) 为空", channelEnum)); - // 创建客户端 - switch (channelEnum) { - case ALIYUN: return new AliyunSmsClient(properties); - case DEBUG_DING_TALK: return new DebugDingTalkSmsClient(properties); - case TENCENT: return new TencentSmsClient(properties); - } - // 创建失败,错误日志 + 抛出异常 - log.error("[createSmsClient][配置({}) 找不到合适的客户端实现]", properties); - throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", properties)); - } - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/TencentSmsClient.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/TencentSmsClient.java deleted file mode 100644 index 140253a..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/client/impl/TencentSmsClient.java +++ /dev/null @@ -1,218 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.client.impl; - -import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.StrUtil; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.VisibleForTesting; -import com.iailab.framework.common.core.KeyValue; -import com.iailab.framework.common.util.collection.ArrayUtils; -import com.iailab.framework.common.util.json.JsonUtils; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsReceiveRespDTO; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsSendRespDTO; -import com.iailab.module.shasteel.framework.sms.core.client.dto.SmsTemplateRespDTO; -import com.iailab.module.shasteel.framework.sms.core.enums.SmsTemplateAuditStatusEnum; -import com.iailab.module.shasteel.framework.sms.core.property.SmsChannelProperties; -import com.tencentcloudapi.common.Credential; -import com.tencentcloudapi.sms.v20210111.SmsClient; -import com.tencentcloudapi.sms.v20210111.models.*; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Objects; - -import static com.iailab.framework.common.util.collection.CollectionUtils.convertList; -import static com.iailab.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; -import static com.iailab.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT; - -/** - * 腾讯云短信功能实现 - * - * 参见 <a href="https://cloud.tencent.com/document/product/382/52077">文档</a> - * - * @author shiwp - */ -public class TencentSmsClient extends AbstractSmsClient { - - /** - * 调用成功 code - */ - public static final String API_CODE_SUCCESS = "Ok"; - - /** - * REGION,使用南京 - */ - private static final String ENDPOINT = "ap-nanjing"; - - /** - * 是否国际/港澳台短信: - * - * 0:表示国内短信。 - * 1:表示国际/港澳台短信。 - */ - private static final long INTERNATIONAL_CHINA = 0L; - - private SmsClient client; - - public TencentSmsClient(SmsChannelProperties properties) { - super(properties); - Assert.notEmpty(properties.getApiSecret(), "apiSecret 不能为空"); - validateSdkAppId(properties); - } - - @Override - protected void doInit() { - // 实例化一个认证对象,入参需要传入腾讯云账户密钥对 secretId,secretKey - Credential credential = new Credential(getApiKey(), properties.getApiSecret()); - client = new SmsClient(credential, ENDPOINT); - } - - /** - * 参数校验腾讯云的 SDK AppId - * - * 原因是:腾讯云发放短信的时候,需要额外的参数 sdkAppId - * - * 解决方案:考虑到不破坏原有的 apiKey + apiSecret 的结构,所以将 secretId 拼接到 apiKey 字段中,格式为 "secretId sdkAppId"。 - * - * @param properties 配置 - */ - private static void validateSdkAppId(SmsChannelProperties properties) { - String combineKey = properties.getApiKey(); - Assert.notEmpty(combineKey, "apiKey 不能为空"); - String[] keys = combineKey.trim().split(" "); - Assert.isTrue(keys.length == 2, "腾讯云短信 apiKey 配置格式错误,请配置 为[secretId sdkAppId]"); - } - - private String getSdkAppId() { - return StrUtil.subAfter(properties.getApiKey(), " ", true); - } - - private String getApiKey() { - return StrUtil.subBefore(properties.getApiKey(), " ", true); - } - - @Override - public SmsSendRespDTO sendSms(Long sendLogId, String mobile, - String apiTemplateId, List<KeyValue<String, Object>> templateParams) throws Throwable { - // 构建请求 - SendSmsRequest request = new SendSmsRequest(); - request.setSmsSdkAppId(getSdkAppId()); - request.setPhoneNumberSet(new String[]{mobile}); - request.setSignName(properties.getSignature()); - request.setTemplateId(apiTemplateId); - request.setTemplateParamSet(ArrayUtils.toArray(templateParams, e -> String.valueOf(e.getValue()))); - request.setSessionContext(JsonUtils.toJsonString(new SessionContext().setLogId(sendLogId))); - // 执行请求 - SendSmsResponse response = client.SendSms(request); - SendStatus status = response.getSendStatusSet()[0]; - return new SmsSendRespDTO().setSuccess(Objects.equals(status.getCode(), API_CODE_SUCCESS)).setSerialNo(status.getSerialNo()) - .setApiRequestId(response.getRequestId()).setApiCode(status.getCode()).setApiMsg(status.getMessage()); - } - - @Override - public List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) { - List<SmsReceiveStatus> callback = JsonUtils.parseArray(text, SmsReceiveStatus.class); - return convertList(callback, status -> new SmsReceiveRespDTO() - .setSuccess(SmsReceiveStatus.SUCCESS_CODE.equalsIgnoreCase(status.getStatus())) - .setErrorCode(status.getErrCode()).setErrorMsg(status.getDescription()) - .setMobile(status.getMobile()).setReceiveTime(status.getReceiveTime()) - .setSerialNo(status.getSerialNo()).setLogId(status.getSessionContext().getLogId())); - } - - @Override - public SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) throws Throwable { - // 构建请求 - DescribeSmsTemplateListRequest request = new DescribeSmsTemplateListRequest(); - request.setTemplateIdSet(new Long[]{Long.parseLong(apiTemplateId)}); - request.setInternational(INTERNATIONAL_CHINA); - // 执行请求 - DescribeSmsTemplateListResponse response = client.DescribeSmsTemplateList(request); - DescribeTemplateListStatus status = response.getDescribeTemplateStatusSet()[0]; - if (status == null || status.getStatusCode() == null) { - return null; - } - return new SmsTemplateRespDTO().setId(status.getTemplateId().toString()).setContent(status.getTemplateContent()) - .setAuditStatus(convertSmsTemplateAuditStatus(status.getStatusCode().intValue())).setAuditReason(status.getReviewReply()); - } - - @VisibleForTesting - Integer convertSmsTemplateAuditStatus(int templateStatus) { - switch (templateStatus) { - case 1: return SmsTemplateAuditStatusEnum.CHECKING.getStatus(); - case 0: return SmsTemplateAuditStatusEnum.SUCCESS.getStatus(); - case -1: return SmsTemplateAuditStatusEnum.FAIL.getStatus(); - default: throw new IllegalArgumentException(String.format("未知审核状态(%d)", templateStatus)); - } - } - - @Data - private static class SmsReceiveStatus { - - /** - * 短信接受成功 code - */ - public static final String SUCCESS_CODE = "SUCCESS"; - - /** - * 用户实际接收到短信的时间 - */ - @JsonProperty("user_receive_time") - @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) - private LocalDateTime receiveTime; - - /** - * 国家(或地区)码 - */ - @JsonProperty("nationcode") - private String nationCode; - - /** - * 手机号码 - */ - private String mobile; - - /** - * 实际是否收到短信接收状态,SUCCESS(成功)、FAIL(失败) - */ - @JsonProperty("report_status") - private String status; - - /** - * 用户接收短信状态码错误信息 - */ - @JsonProperty("errmsg") - private String errCode; - - /** - * 用户接收短信状态描述 - */ - @JsonProperty("description") - private String description; - - /** - * 本次发送标识 ID(与发送接口返回的SerialNo对应) - */ - @JsonProperty("sid") - private String serialNo; - - /** - * 用户的 session 内容(与发送接口的请求参数 SessionContext 一致) - */ - @JsonProperty("ext") - private SessionContext sessionContext; - - } - - @VisibleForTesting - @Data - static class SessionContext { - - /** - * 发送短信记录id - */ - private Long logId; - - } - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/enums/SmsChannelEnum.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/enums/SmsChannelEnum.java deleted file mode 100644 index bc088ee..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/enums/SmsChannelEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.enums; - -import cn.hutool.core.util.ArrayUtil; -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 短信渠道枚举 - * - * @author zzf - * @since 2021/1/25 10:56 - */ -@Getter -@AllArgsConstructor -public enum SmsChannelEnum { - - DEBUG_DING_TALK("DEBUG_DING_TALK", "调试(钉钉)"), - ALIYUN("ALIYUN", "阿里云"), - TENCENT("TENCENT", "腾讯云"), -// HUA_WEI("HUA_WEI", "华为云"), - ; - - /** - * 编码 - */ - private final String code; - /** - * 名字 - */ - private final String name; - - public static SmsChannelEnum getByCode(String code) { - return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); - } - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/enums/SmsTemplateAuditStatusEnum.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/enums/SmsTemplateAuditStatusEnum.java deleted file mode 100644 index 0925126..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/enums/SmsTemplateAuditStatusEnum.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 短信模板的审核状态枚举 - * - * @author iailab - */ -@AllArgsConstructor -@Getter -public enum SmsTemplateAuditStatusEnum { - - CHECKING(1), - SUCCESS(2), - FAIL(3); - - private final Integer status; - -} diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/property/SmsChannelProperties.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/property/SmsChannelProperties.java deleted file mode 100644 index 55e1fd0..0000000 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/sms/core/property/SmsChannelProperties.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.iailab.module.shasteel.framework.sms.core.property; - -import com.iailab.module.shasteel.framework.sms.core.enums.SmsChannelEnum; -import lombok.Data; -import org.springframework.validation.annotation.Validated; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -/** - * 短信渠道配置类 - * - * @author zzf - * @since 2021/1/25 17:01 - */ -@Data -@Validated -public class SmsChannelProperties { - - /** - * 渠道编号 - */ - @NotNull(message = "短信渠道 ID 不能为空") - private Long id; - /** - * 短信签名 - */ - @NotEmpty(message = "短信签名不能为空") - private String signature; - /** - * 渠道编码 - * - * 枚举 {@link SmsChannelEnum} - */ - @NotEmpty(message = "渠道编码不能为空") - private String code; - /** - * 短信 API 的账号 - */ - @NotEmpty(message = "短信 API 的账号不能为空") - private String apiKey; - /** - * 短信 API 的密钥 - */ - @NotEmpty(message = "短信 API 的密钥不能为空") - private String apiSecret; - /** - * 短信发送回调 URL - */ - private String callbackUrl; - -} diff --git a/shasteel-biz/src/main/resources/application-dev.yaml b/shasteel-biz/src/main/resources/application-dev.yaml index e1e4598..691e0c9 100644 --- a/shasteel-biz/src/main/resources/application-dev.yaml +++ b/shasteel-biz/src/main/resources/application-dev.yaml @@ -36,17 +36,8 @@ datasource: master: url: jdbc:mysql://172.16.8.100:3306/iailab_expert_tenant_shasteel?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 - # url: jdbc:mysql://127.0.0.1:3306/iailab_expert_tenant_shasteel?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # MySQL Connector/J 5.X 连接的示例 - # url: jdbc:postgresql://127.0.0.1:5432/iailab_expert_tenant_shasteel # PostgreSQL 连接的示例 - # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 - # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=iailab_expert_tenant_shasteel # SQLServer 连接的示例 - # url: jdbc:dm://10.211.55.4:5236?schema=IAILAB_FAST # DM 连接的示例 username: root password: 123456 - # username: sa # SQL Server 连接的示例 - # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W # SQL Server 连接的示例 - # username: SYSDBA # DM 连接的示例 - # password: SYSDBA # DM 连接的示例 slave: # 模拟从库,可根据自己需要修改 lazy: true # 开启懒加载,保证启动速度 url: jdbc:mysql://127.0.0.1:3306/iailab_expert_tenant_shasteel?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true @@ -55,40 +46,27 @@ # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: - host: 127.0.0.1 # 地址 + host: 172.16.8.100 # 地址 port: 6379 # 端口 database: 8 # 数据库索引 password: 123456 # 密码,建议生产环境开启 ---- #################### 定时任务相关配置 #################### +--- #################### MQ 消息队列相关配置 #################### -xxl: - job: - enabled: true # 是否开启调度中心,默认为 true 开启 - admin: - addresses: http://172.16.8.100:9090/xxl-job-admin # 调度中心部署跟地址 +# rocketmq 配置项,对应 RocketMQProperties 配置类 +rocketmq: + name-server: 127.0.0.1:9876 # RocketMQ Namesrv ---- #################### 微信公众号、小程序相关配置 #################### -wx: - mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档 - # app-id: wx041349c6f39b268b - # secret: 5abee519483bc9f8cb37ce280e814bd0 - app-id: wx5b23ba7a5589ecbb # 测试号 - secret: 2a7b3b20c537e52e74afd395eb85f61f - # 存储配置,解决 AccessToken 的跨节点的共享 - config-storage: - type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 - key-prefix: wx # Redis Key 的前缀 - http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 - miniapp: # 小程序配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md 文档 - # appid: wx62056c0d5e8db250 - # secret: 333ae72f41552af1e998fe1f54e1584a - appid: wx63c280fe3248a3e7 # wenhualian的接口测试号 - secret: 6f270509224a7ae1296bbf1c8cb97aed - config-storage: - type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 - key-prefix: wa # Redis Key 的前缀 - http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 +spring: + # RabbitMQ 配置项,对应 RabbitProperties 配置类 + rabbitmq: + host: 172.16.8.200 # RabbitMQ 服务的地址 + port: 5672 # RabbitMQ 服务的端口 + username: admin # RabbitMQ 服务的账号 + password: admin123 # RabbitMQ 服务的密码 + # Kafka 配置项,对应 KafkaProperties 配置类 + kafka: + bootstrap-servers: 127.0.0.1:9092 # 指定 Kafka Broker 地址,可以设置多个,以逗号分隔 --- #################### 平台相关配置 #################### @@ -103,36 +81,3 @@ access-log: # 访问日志的配置项 enable: false - sms-code: # 短信验证码相关的配置项 - expire-times: 10m - send-frequency: 1m - send-maximum-quantity-per-day: 10 - begin-code: 9999 # 这里配置 9999 的原因是,测试方便。 - end-code: 9999 # 这里配置 9999 的原因是,测试方便。 - -justauth: - enabled: true - type: - DINGTALK: # 钉钉 - client-id: dingvrnreaje3yqvzhxg - client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI - ignore-check-redirect-uri: true - WECHAT_ENTERPRISE: # 企业微信 - client-id: wwd411c69a39ad2e54 - client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw - agent-id: 1000004 - ignore-check-redirect-uri: true - # noinspection SpringBootApplicationYaml - WECHAT_MINI_APP: # 微信小程序 - client-id: ${wx.miniapp.appid} - client-secret: ${wx.miniapp.secret} - ignore-check-redirect-uri: true - ignore-check-state: true # 微信小程序,不会使用到 state,所以不进行校验 - WECHAT_MP: # 微信公众号 - client-id: ${wx.mp.app-id} - client-secret: ${wx.mp.secret} - ignore-check-redirect-uri: true - cache: - type: REDIS - prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE:: - timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟 diff --git a/shasteel-biz/src/main/resources/application-test.yaml b/shasteel-biz/src/main/resources/application-test.yaml index 18e3652..ceedec6 100644 --- a/shasteel-biz/src/main/resources/application-test.yaml +++ b/shasteel-biz/src/main/resources/application-test.yaml @@ -60,36 +60,6 @@ database: 8 # 数据库索引 password: 123456 # 密码,建议生产环境开启 ---- #################### 定时任务相关配置 #################### - -xxl: - job: - enabled: true # 是否开启调度中心,默认为 true 开启 - admin: - addresses: http://172.16.8.100:9090/xxl-job-admin # 调度中心部署跟地址 - ---- #################### 微信公众号、小程序相关配置 #################### -wx: - mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档 - # app-id: wx041349c6f39b268b - # secret: 5abee519483bc9f8cb37ce280e814bd0 - app-id: wx5b23ba7a5589ecbb # 测试号 - secret: 2a7b3b20c537e52e74afd395eb85f61f - # 存储配置,解决 AccessToken 的跨节点的共享 - config-storage: - type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 - key-prefix: wx # Redis Key 的前缀 - http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 - miniapp: # 小程序配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md 文档 - # appid: wx62056c0d5e8db250 - # secret: 333ae72f41552af1e998fe1f54e1584a - appid: wx63c280fe3248a3e7 # wenhualian的接口测试号 - secret: 6f270509224a7ae1296bbf1c8cb97aed - config-storage: - type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 - key-prefix: wa # Redis Key 的前缀 - http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 - --- #################### 平台相关配置 #################### # 平台配置项,设置当前项目所有自定义的配置 @@ -110,29 +80,3 @@ begin-code: 9999 # 这里配置 9999 的原因是,测试方便。 end-code: 9999 # 这里配置 9999 的原因是,测试方便。 -justauth: - enabled: true - type: - DINGTALK: # 钉钉 - client-id: dingvrnreaje3yqvzhxg - client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI - ignore-check-redirect-uri: true - WECHAT_ENTERPRISE: # 企业微信 - client-id: wwd411c69a39ad2e54 - client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw - agent-id: 1000004 - ignore-check-redirect-uri: true - # noinspection SpringBootApplicationYaml - WECHAT_MINI_APP: # 微信小程序 - client-id: ${wx.miniapp.appid} - client-secret: ${wx.miniapp.secret} - ignore-check-redirect-uri: true - ignore-check-state: true # 微信小程序,不会使用到 state,所以不进行校验 - WECHAT_MP: # 微信公众号 - client-id: ${wx.mp.app-id} - client-secret: ${wx.mp.secret} - ignore-check-redirect-uri: true - cache: - type: REDIS - prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE:: - timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟 diff --git a/shasteel-biz/src/main/resources/application.yaml b/shasteel-biz/src/main/resources/application.yaml index e1a2920..d96caf2 100644 --- a/shasteel-biz/src/main/resources/application.yaml +++ b/shasteel-biz/src/main/resources/application.yaml @@ -4,11 +4,11 @@ name: shasteel-server profiles: - active: test + active: dev cloud: nacos: - server-addr: 172.16.8.100:8848 # Nacos 服务器地址 + server-addr: localhost:8848 # Nacos 服务器地址 username: nacos password: nacos discovery: # 【配置中心】配置项 -- Gitblit v1.9.3