This commit is contained in:
徐唯轩
2023-11-14 16:32:59 +08:00
parent 441dad9ef6
commit 751ed76e37
298 changed files with 10073 additions and 3527 deletions

View File

@ -8,6 +8,10 @@ import co.yixiang.yshop.framework.sms.core.client.impl.tencent.TencentSmsClient;
import co.yixiang.yshop.framework.sms.core.enums.SmsChannelEnum;
import co.yixiang.yshop.framework.sms.core.property.SmsChannelProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
@ -22,6 +26,7 @@ import java.util.concurrent.ConcurrentMap;
*/
@Validated
@Slf4j
@Component
public class SmsClientFactoryImpl implements SmsClientFactory {
/**
@ -30,6 +35,12 @@ public class SmsClientFactoryImpl implements SmsClientFactory {
*/
private final ConcurrentMap<Long, AbstractSmsClient> channelIdClients = new ConcurrentHashMap<>();
@Value("${yshop.sms-code.api-key}")
private String apiKey = "LTAI5tBBPdRd4f2YZt5UhVjF";
@Value("${yshop.sms-code.api-secret}")
private String apiSecret = "iVP7EsjX309epI7MqsScziGhcrEHiT";
/**
* 短信客户端 Map
* key渠道编码使用 {@link SmsChannelProperties#getCode()} ()}
@ -44,7 +55,7 @@ public class SmsClientFactoryImpl implements SmsClientFactory {
Arrays.stream(SmsChannelEnum.values()).forEach(channel -> {
// 创建一个空的 SmsChannelProperties 对象
SmsChannelProperties properties = new SmsChannelProperties().setCode(channel.getCode())
.setApiKey("default default").setApiSecret("default");
.setApiKey(apiKey).setApiSecret(apiSecret);
// 创建 Sms 客户端
AbstractSmsClient smsClient = createSmsClient(properties);
channelCodeClients.put(channel.getCode(), smsClient);
@ -78,13 +89,15 @@ public class SmsClientFactoryImpl implements SmsClientFactory {
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);
case ALIYUN: return new AliyunSmsClient(properties);
// case DEBUG_DING_TALK: return new DebugDingTalkSmsClient(properties);
// case TENCENT: return new TencentSmsClient(properties);
default: return new AliyunSmsClient(properties);
}
// 创建失败,错误日志 + 抛出异常
log.error("[createSmsClient][配置({}) 找不到合适的客户端实现]", properties);
throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", properties));
// log.error("[createSmsClient][配置({}) 找不到合适的客户端实现]", properties);
// throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", properties));
}
}

View File

@ -17,7 +17,7 @@ public enum SmsChannelEnum {
DEBUG_DING_TALK("DEBUG_DING_TALK", "调试(钉钉)"),
ALIYUN("ALIYUN", "阿里云"),
TENCENT("TENCENT", "腾讯云"),
// HUA_WEI("HUA_WEI", "华为云"),
HUA_WEI("HUA_WEI", "华为云"),
;
/**