diff --git a/zlt-business/order-center/src/main/resources/application-cdn-prefetch.yml b/zlt-business/order-center/src/main/resources/application-cdn-prefetch.yml deleted file mode 100644 index c8d002b6..00000000 --- a/zlt-business/order-center/src/main/resources/application-cdn-prefetch.yml +++ /dev/null @@ -1,14 +0,0 @@ -# 订单中心CDN预热配置 -cdn: - prefetch: - # 是否启用CDN预热功能 - enabled: true - # 每批次预热的文件数量 - batch-size: 50 - # 预热区域:domestic-仅中国内地,overseas-全球(不包含中国内地),不传-全球 - area: domestic - -# 日志配置 -logging: - level: - com.central.order.controller.OrderFileController: DEBUG \ No newline at end of file diff --git a/zlt-business/order-center/src/main/resources/application.yml b/zlt-business/order-center/src/main/resources/application.yml index 2cc65916..1a44a753 100644 --- a/zlt-business/order-center/src/main/resources/application.yml +++ b/zlt-business/order-center/src/main/resources/application.yml @@ -126,3 +126,18 @@ wx: activity-start: lgwkRnbdDc3mEwk3RMob43LpLHnLfglZtTkbFRPsPCA order-complete: ZeIlAA6ImQLxBiLmo-53lM7wkL4KnuKKTGKWBZwYAdM video-edit-complete: IXpL-Voztm3GM-zFj3sxA39qy8oRtAcxTiT7_Qsyz9Q + +# 订单中心CDN预热配置 +cdn: + prefetch: + # 是否启用CDN预热功能 + enabled: true + # 每批次预热的文件数量 + batch-size: 50 + # 预热区域:domestic-仅中国内地,overseas-全球(不包含中国内地),不传-全球 + area: domestic + +# 日志配置 +logging: + level: + com.central.order.controller.OrderFileController: DEBUG \ No newline at end of file diff --git a/zlt-commons/pom.xml b/zlt-commons/pom.xml index fa2d2adf..749d3267 100644 --- a/zlt-commons/pom.xml +++ b/zlt-commons/pom.xml @@ -21,6 +21,7 @@ zlt-common-core zlt-elasticsearch-spring-boot-starter zlt-oss-spring-boot-starter + zlt-sms-spring-boot-starter zlt-zookeeper-spring-boot-starter zlt-wechat-common-core zlt-wechat-spring-boot-starter diff --git a/zlt-commons/zlt-sms-spring-boot-starter/pom.xml b/zlt-commons/zlt-sms-spring-boot-starter/pom.xml new file mode 100644 index 00000000..2721d8a1 --- /dev/null +++ b/zlt-commons/zlt-sms-spring-boot-starter/pom.xml @@ -0,0 +1,58 @@ + + + + com.zlt + zlt-commons + 6.0.0 + + 4.0.0 + jar + zlt-sms-spring-boot-starter + 短信服务通用组件 + + + org.springframework + spring-web + + + org.springframework.boot + spring-boot-configuration-processor + true + + + com.tencentcloudapi + tencentcloud-sdk-java + 3.1.825 + + + + com.aliyun + aliyun-java-sdk-dysmsapi + 2.1.0 + + + com.aliyun + aliyun-java-sdk-core + 4.5.20 + + + com.alibaba + fastjson + 1.2.83 + + + com.aliyun + aliyun-java-sdk-core + 4.6.4 + compile + + + com.tencentcloudapi + tencentcloud-sdk-java-common + 3.1.1040 + compile + + + diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/config/SmsAutoConfigure.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/config/SmsAutoConfigure.java new file mode 100644 index 00000000..48f714ba --- /dev/null +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/config/SmsAutoConfigure.java @@ -0,0 +1,19 @@ +package com.central.sms.config; + +import com.central.sms.service.ISmsService; +import com.central.sms.service.SmsServiceFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(SmsProperties.class) +public class SmsAutoConfigure { + + @Bean + @ConditionalOnMissingBean(ISmsService.class) + public ISmsService smsService(SmsServiceFactory factory) { + return factory.getSmsService(); + } +} \ No newline at end of file diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/config/SmsProperties.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/config/SmsProperties.java new file mode 100644 index 00000000..34dde52e --- /dev/null +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/config/SmsProperties.java @@ -0,0 +1,45 @@ +package com.central.sms.config; + +import com.central.sms.enums.SmsProviderType; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "sms") +public class SmsProperties { + private SmsProviderType provider = SmsProviderType.TENCENT; + private TencentConfig tencent = new TencentConfig(); + private AliyunConfig aliyun = new AliyunConfig(); + + public SmsProviderType getProvider() { return provider; } + public void setProvider(SmsProviderType provider) { this.provider = provider; } + public TencentConfig getTencent() { return tencent; } + public void setTencent(TencentConfig tencent) { this.tencent = tencent; } + public AliyunConfig getAliyun() { return aliyun; } + public void setAliyun(AliyunConfig aliyun) { this.aliyun = aliyun; } + + public static class TencentConfig { + private String appId; + private String secretId; + private String secretKey; + private String signName; + public String getAppId() { return appId; } + public void setAppId(String appId) { this.appId = appId; } + public String getSecretId() { return secretId; } + public void setSecretId(String secretId) { this.secretId = secretId; } + public String getSecretKey() { return secretKey; } + public void setSecretKey(String secretKey) { this.secretKey = secretKey; } + public String getSignName() { return signName; } + public void setSignName(String signName) { this.signName = signName; } + } + + public static class AliyunConfig { + private String accessKeyId; + private String accessKeySecret; + private String signName; + public String getAccessKeyId() { return accessKeyId; } + public void setAccessKeyId(String accessKeyId) { this.accessKeyId = accessKeyId; } + public String getAccessKeySecret() { return accessKeySecret; } + public void setAccessKeySecret(String accessKeySecret) { this.accessKeySecret = accessKeySecret; } + public String getSignName() { return signName; } + public void setSignName(String signName) { this.signName = signName; } + } +} \ No newline at end of file diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/enums/SmsProviderType.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/enums/SmsProviderType.java new file mode 100644 index 00000000..bd54b196 --- /dev/null +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/enums/SmsProviderType.java @@ -0,0 +1,6 @@ +package com.central.sms.enums; + +public enum SmsProviderType { + TENCENT, + ALIYUN +} \ No newline at end of file diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/exception/SmsSendException.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/exception/SmsSendException.java new file mode 100644 index 00000000..e0e61c87 --- /dev/null +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/exception/SmsSendException.java @@ -0,0 +1,7 @@ +package com.central.sms.exception; + +public class SmsSendException extends RuntimeException { + public SmsSendException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/ISmsService.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/ISmsService.java new file mode 100644 index 00000000..cbcdf2e0 --- /dev/null +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/ISmsService.java @@ -0,0 +1,14 @@ +package com.central.sms.service; + +import java.util.Map; + +public interface ISmsService { + /** + * 发送短信 + * @param phone 手机号 + * @param templateId 短信模板ID + * @param params 模板参数 + * @return 是否发送成功 + */ + boolean sendSms(String phone, String templateId, Map params); +} \ No newline at end of file diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/SmsServiceFactory.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/SmsServiceFactory.java new file mode 100644 index 00000000..ba478bdf --- /dev/null +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/SmsServiceFactory.java @@ -0,0 +1,30 @@ +package com.central.sms.service; + +import com.central.sms.config.SmsProperties; +import com.central.sms.enums.SmsProviderType; +import com.central.sms.service.impl.AliyunSmsService; +import com.central.sms.service.impl.TencentSmsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class SmsServiceFactory { + + @Autowired + private TencentSmsService tencentSmsService; + @Autowired + private AliyunSmsService aliyunSmsService; + @Autowired + private SmsProperties smsProperties; + + public ISmsService getSmsService() { + SmsProviderType type = smsProperties.getProvider(); + switch (type) { + case ALIYUN: + return aliyunSmsService; + case TENCENT: + default: + return tencentSmsService; + } + } +} \ No newline at end of file diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/AliyunSmsService.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/AliyunSmsService.java new file mode 100644 index 00000000..1f8dbf13 --- /dev/null +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/AliyunSmsService.java @@ -0,0 +1,56 @@ +package com.central.sms.service.impl; + +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; +import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; +import com.aliyuncs.exceptions.ClientException; +import com.aliyuncs.profile.DefaultProfile; +import com.central.sms.config.SmsProperties; +import com.central.sms.exception.SmsSendException; +import com.central.sms.service.ISmsService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Map; + +@Service +public class AliyunSmsService implements ISmsService { + + private static final Logger logger = LoggerFactory.getLogger(AliyunSmsService.class); + + @Autowired + private SmsProperties smsProperties; + + @Override + public boolean sendSms(String phone, String templateId, Map params) { + SmsProperties.AliyunConfig config = smsProperties.getAliyun(); + DefaultProfile profile = DefaultProfile.getProfile( + "cn-hangzhou", // 地域ID + config.getAccessKeyId(), + config.getAccessKeySecret() + ); + IAcsClient client = new DefaultAcsClient(profile); + + SendSmsRequest request = new SendSmsRequest(); + request.setPhoneNumbers(phone); + request.setSignName(config.getSignName()); + request.setTemplateCode(templateId); + // 阿里云短信模板参数为JSON字符串 + if (params != null && !params.isEmpty()) { + request.setTemplateParam(com.alibaba.fastjson.JSON.toJSONString(params)); + } + + try { + logger.info("[阿里云短信] 发送请求: 手机号={}, 模板={}, 参数={}", phone, templateId, params); + SendSmsResponse response = client.getAcsResponse(request); + logger.info("[阿里云短信] 发送结果: {}", response.getMessage()); + return "OK".equalsIgnoreCase(response.getCode()); + } catch (ClientException e) { + logger.error("[阿里云短信] 发送失败,手机号:{},模板:{},参数:{},异常:{}", phone, templateId, params, e.getMessage(), e); + throw new SmsSendException("阿里云短信发送失败", e); + } + } +} \ No newline at end of file diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/TencentSmsService.java b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/TencentSmsService.java new file mode 100644 index 00000000..2414b0ba --- /dev/null +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/java/com/central/sms/service/impl/TencentSmsService.java @@ -0,0 +1,52 @@ +package com.central.sms.service.impl; + +import com.central.sms.config.SmsProperties; +import com.central.sms.exception.SmsSendException; +import com.central.sms.service.ISmsService; +import com.tencentcloudapi.common.Credential; +import com.tencentcloudapi.common.profile.ClientProfile; +import com.tencentcloudapi.common.profile.HttpProfile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Map; + +@Service +public class TencentSmsService implements ISmsService { + + private static final Logger logger = LoggerFactory.getLogger(TencentSmsService.class); + + @Autowired + private SmsProperties smsProperties; + + @Override + public boolean sendSms(String phone, String templateId, Map params) { + try { + SmsProperties.TencentConfig config = smsProperties.getTencent(); + logger.info("[短信发送][服务商:TENCENT] 手机号={}, 模板ID={}, 参数={}", phone, templateId, params); + Credential cred = new Credential(config.getSecretId(), config.getSecretKey()); + HttpProfile httpProfile = new HttpProfile(); + httpProfile.setEndpoint("sms.tencentcloudapi.com"); + ClientProfile clientProfile = new ClientProfile(); + clientProfile.setHttpProfile(httpProfile); + /*SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile); + + SendSmsRequest req = new SendSmsRequest(); + req.setSmsSdkAppId(config.getAppId()); + req.setSignName(config.getSignName()); + req.setTemplateId(templateId); + req.setPhoneNumberSet(new String[]{phone}); + req.setTemplateParamSet(params.values().toArray(new String[0])); + + SendSmsResponse resp = client.SendSms(req); + logger.info("[短信发送][服务商:TENCENT] 响应: code={}, message={}", resp.getSendStatusSet()[0].getCode(), resp.getSendStatusSet()[0].getMessage()); + return "Ok".equalsIgnoreCase(resp.getSendStatusSet()[0].getCode());*/ + return true; + } catch (Exception e) { + logger.error("[短信发送][服务商:TENCENT] 失败,手机号:{},模板ID:{},参数:{},异常:{}", phone, templateId, params, e.getMessage(), e); + throw new SmsSendException("腾讯云短信发送失败", e); + } + } +} diff --git a/zlt-commons/zlt-sms-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/zlt-commons/zlt-sms-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..fca176fd --- /dev/null +++ b/zlt-commons/zlt-sms-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.central.sms.config.SmsAutoConfigure \ No newline at end of file diff --git a/zlt-config/src/main/resources/application-dev.properties b/zlt-config/src/main/resources/application-dev.properties index 16289e44..da93d5b1 100644 --- a/zlt-config/src/main/resources/application-dev.properties +++ b/zlt-config/src/main/resources/application-dev.properties @@ -91,3 +91,17 @@ zlt.wxpay.apiV3Key=aIt5Vw3cYXSCSd4L5h14kIyDsoXBow7r zlt.tenant.id: webApp + +# 选择服务商:TENCENT 或 ALIYUN +sms.provider=ALIYUN + +# 腾讯云短信配置 +sms.tencent.appId=1400xxxxxxx # 短信应用ID +sms.tencent.secretId=AKIDxxxxxxx # 控制台API密钥 +sms.tencent.secretKey=xxxxxxxxxxxx # 控制台API密钥 +sms.tencent.signName=xxx + +# 阿里云短信配置 +sms.aliyun.accessKeyId=xxx +sms.aliyun.accessKeySecret=xxx +sms.aliyun.signName=xxx diff --git a/zlt-config/src/main/resources/application-prod.properties b/zlt-config/src/main/resources/application-prod.properties index 61f0583b..8c1a9690 100644 --- a/zlt-config/src/main/resources/application-prod.properties +++ b/zlt-config/src/main/resources/application-prod.properties @@ -78,3 +78,17 @@ zlt.wxpay.privateKeyPath=/data/zlt/cert/apiclient_key.pem zlt.wxpay.apiV3Key=aIt5Vw3cYXSCSd4L5h14kIyDsoXBow7r zlt.tenant.id: webApp + +# 选择服务商:TENCENT 或 ALIYUN +sms.provider=ALIYUN + +# 腾讯云短信配置 +sms.tencent.appId=1400xxxxxxx # 短信应用ID +sms.tencent.secretId=AKIDxxxxxxx # 控制台API密钥 +sms.tencent.secretKey=xxxxxxxxxxxx # 控制台API密钥 +sms.tencent.signName=xxx + +# 阿里云短信配置 +sms.aliyun.accessKeyId=xxx +sms.aliyun.accessKeySecret=xxx +sms.aliyun.signName=xxx diff --git a/zlt-config/src/main/resources/bootstrap.properties b/zlt-config/src/main/resources/bootstrap.properties index 19e3c72f..2168d2fe 100644 --- a/zlt-config/src/main/resources/bootstrap.properties +++ b/zlt-config/src/main/resources/bootstrap.properties @@ -1,13 +1,13 @@ ########################## bootstrap级别通用配置 ########################## # 默认开发环境 -spring.profiles.active=prod +spring.profiles.active=dev ##### nacos(注册中心和配置中心)地址 -spring.cloud.nacos.server-addr=81.70.164.178:8848 -#spring.cloud.nacos.server-addr=127.0.0.1:8848 +#spring.cloud.nacos.server-addr=81.70.164.178:8848 +spring.cloud.nacos.server-addr=127.0.0.1:8848 spring.cloud.nacos.username=nacos -#spring.cloud.nacos.password=nacos -spring.cloud.nacos.password=nacosGFLY +spring.cloud.nacos.password=nacos +#spring.cloud.nacos.password=nacosGFLY spring.cloud.nacos.config.file-extension=yml spring.cloud.nacos.config.shared-configs[0].data-id=common.yml spring.cloud.nacos.config.shared-configs[0].refresh=true