mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-13 02:57:13 +08:00
fix(system/sms): 修复短信配置加载错误,移除 SmsSupplierEnum
Closes #IC4D7F
This commit is contained in:
@@ -16,21 +16,18 @@
|
||||
|
||||
package top.continew.admin.system.config.sms;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.sms4j.provider.config.BaseConfig;
|
||||
import org.dromara.sms4j.provider.factory.BaseProviderFactory;
|
||||
import org.dromara.sms4j.provider.factory.ProviderFactoryHolder;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import top.continew.admin.system.model.resp.SmsConfigResp;
|
||||
import top.continew.starter.json.jackson.util.JSONUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 短信配置工具类
|
||||
@@ -42,47 +39,41 @@ import top.continew.admin.system.model.resp.SmsConfigResp;
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class SmsConfigUtil {
|
||||
|
||||
private static final TypeReference<Map<String, Object>> CONFIG_MAP_TYPE = new TypeReference<Map<String, Object>>() {};
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
/**
|
||||
* 将本地配置对象转换为 BaseConfig
|
||||
* 将本地配置转换为 SMS4J 配置
|
||||
*
|
||||
* @param smsConfig 本地配置对象
|
||||
* @return SMS4j 配置基类
|
||||
*/
|
||||
* @return SMS4J 配置基类
|
||||
*/
|
||||
public static BaseConfig from(SmsConfigResp smsConfig) {
|
||||
if (Objects.isNull(smsConfig))
|
||||
if (smsConfig == null) {
|
||||
return null;
|
||||
|
||||
String supplierName = smsConfig.getSupplier();
|
||||
BaseProviderFactory<?, ?> providerFactory = ProviderFactoryHolder.requireForSupplier(supplierName);
|
||||
if (Objects.isNull(providerFactory))
|
||||
}
|
||||
String supplier = smsConfig.getSupplier();
|
||||
BaseProviderFactory<?, ?> providerFactory = ProviderFactoryHolder.requireForSupplier(supplier);
|
||||
if (providerFactory == null) {
|
||||
return null;
|
||||
|
||||
Map<String, Object> configInfo = new HashMap<>();
|
||||
}
|
||||
// 构建配置
|
||||
Map<String, Object> configInfo = MapUtil.newHashMap();
|
||||
configInfo.put("configId", smsConfig.getId().toString());
|
||||
configInfo.put("accessKeyId", smsConfig.getAccessKey());
|
||||
configInfo.put("accessKeySecret", smsConfig.getSecretKey());
|
||||
configInfo.put("signature", smsConfig.getSignature());
|
||||
configInfo.put("templateId", smsConfig.getTemplateId());
|
||||
if (Objects.nonNull(smsConfig.getWeight()))
|
||||
if (smsConfig.getWeight() != null) {
|
||||
configInfo.put("weight", smsConfig.getWeight());
|
||||
if (Objects.nonNull(smsConfig.getRetryInterval()))
|
||||
configInfo.put("retryInterval", smsConfig.getRetryInterval());
|
||||
if (Objects.nonNull(smsConfig.getMaxRetries()))
|
||||
configInfo.put("maxRetries", smsConfig.getMaxRetries());
|
||||
|
||||
if (Objects.nonNull(smsConfig.getSupplierConfig())) {
|
||||
Map<String, Object> supplierInfo = OBJECT_MAPPER.convertValue(smsConfig
|
||||
.getSupplierConfig(), CONFIG_MAP_TYPE);
|
||||
configInfo.putAll(supplierInfo);
|
||||
}
|
||||
|
||||
BaseConfig config = (BaseConfig)OBJECT_MAPPER.convertValue(configInfo, providerFactory.getConfigClass());
|
||||
return config;
|
||||
if (smsConfig.getRetryInterval() != null) {
|
||||
configInfo.put("retryInterval", smsConfig.getRetryInterval());
|
||||
}
|
||||
if (smsConfig.getMaxRetries() != null) {
|
||||
configInfo.put("maxRetries", smsConfig.getMaxRetries());
|
||||
}
|
||||
if (StrUtil.isNotBlank(smsConfig.getSupplierConfig())) {
|
||||
configInfo.putAll(JSONUtils.toBean(smsConfig.getSupplierConfig(), Map.class));
|
||||
}
|
||||
return (BaseConfig)BeanUtil.toBean(configInfo, providerFactory.getConfigClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -61,6 +61,6 @@ public class SmsReadConfigDatabaseImpl implements SmsReadConfig {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return List.of();
|
||||
}
|
||||
return list.stream().map(smsConfig -> SmsConfigUtil.from(smsConfig)).toList();
|
||||
return list.stream().map(SmsConfigUtil::from).toList();
|
||||
}
|
||||
}
|
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.sms4j.aliyun.config.AlibabaConfig;
|
||||
import org.dromara.sms4j.cloopen.config.CloopenConfig;
|
||||
import org.dromara.sms4j.comm.constant.SupplierConstant;
|
||||
import org.dromara.sms4j.ctyun.config.CtyunConfig;
|
||||
import org.dromara.sms4j.provider.config.BaseConfig;
|
||||
import top.continew.admin.system.model.resp.SmsConfigResp;
|
||||
import top.continew.starter.core.enums.BaseEnum;
|
||||
|
||||
/**
|
||||
* 短信厂商枚举
|
||||
*
|
||||
* @author luoqiz
|
||||
* @author Charles7c
|
||||
* @since 2025/03/15 22:15
|
||||
*
|
||||
* @deprecated 使用数据字典`sms_supplier_type`动态维护
|
||||
*/
|
||||
@Deprecated
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum SmsSupplierEnum implements BaseEnum<String> {
|
||||
|
||||
/**
|
||||
* 阿里云
|
||||
*/
|
||||
ALIBABA(SupplierConstant.ALIBABA, "阿里云") {
|
||||
@Override
|
||||
public BaseConfig toBaseConfig(SmsConfigResp smsConfig) {
|
||||
AlibabaConfig config = new AlibabaConfig();
|
||||
config.setConfigId(smsConfig.getId().toString());
|
||||
config.setAccessKeyId(smsConfig.getAccessKey());
|
||||
config.setAccessKeySecret(smsConfig.getSecretKey());
|
||||
config.setSignature(smsConfig.getSignature());
|
||||
config.setTemplateId(smsConfig.getTemplateId());
|
||||
return config;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 容联云
|
||||
*/
|
||||
CLOOPEN(SupplierConstant.CLOOPEN, "容联云") {
|
||||
@Override
|
||||
public BaseConfig toBaseConfig(SmsConfigResp smsConfig) {
|
||||
CloopenConfig config = new CloopenConfig();
|
||||
config.setConfigId(smsConfig.getId().toString());
|
||||
config.setAccessKeyId(smsConfig.getAccessKey());
|
||||
config.setAccessKeySecret(smsConfig.getSecretKey());
|
||||
config.setSignature(smsConfig.getSignature());
|
||||
config.setTemplateId(smsConfig.getTemplateId());
|
||||
return config;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 天翼云
|
||||
*/
|
||||
CTYUN(SupplierConstant.CTYUN, "天翼云") {
|
||||
@Override
|
||||
public BaseConfig toBaseConfig(SmsConfigResp smsConfig) {
|
||||
CtyunConfig config = new CtyunConfig();
|
||||
config.setConfigId(smsConfig.getId().toString());
|
||||
config.setAccessKeyId(smsConfig.getAccessKey());
|
||||
config.setAccessKeySecret(smsConfig.getSecretKey());
|
||||
config.setSignature(smsConfig.getSignature());
|
||||
config.setTemplateId(smsConfig.getTemplateId());
|
||||
return config;
|
||||
}
|
||||
},
|
||||
// EMAY(SupplierConstant.EMAY, "亿美软通"), HUAWEI(SupplierConstant.HUAWEI, "华为云短信"),
|
||||
// JDCLOUD(SupplierConstant.JDCLOUD, "京东云短信"), NETEASE(SupplierConstant.NETEASE, "网易云信"),
|
||||
// TENCENT(SupplierConstant.TENCENT, "腾讯云短信"), UNISMS(SupplierConstant.UNISMS, "合一短信"),
|
||||
// YUNPIAN(SupplierConstant.YUNPIAN, "云片短信"), ZHUTONG(SupplierConstant.ZHUTONG, "助通短信"),
|
||||
// LIANLU(SupplierConstant.LIANLU, "联麓短信"), DINGZHONG(SupplierConstant.DINGZHONG, "鼎众短信"),
|
||||
// QINIU(SupplierConstant.QINIU, "七牛云短信"), CHUANGLAN(SupplierConstant.CHUANGLAN, "创蓝短信"),
|
||||
// JIGUANG(SupplierConstant.JIGUANG, "极光短信"), BUDING_V2(SupplierConstant.BUDING_V2, "布丁云V2"),
|
||||
// MAS(SupplierConstant.MAS, "中国移动 云MAS"), BAIDU(SupplierConstant.BAIDU, "百度云短信"),
|
||||
// LUO_SI_MAO(SupplierConstant.LUO_SI_MAO, "螺丝帽短信"), MY_SUBMAIL(SupplierConstant.MY_SUBMAIL, "SUBMAIL短信"),
|
||||
// DAN_MI(SupplierConstant.DAN_MI, "单米短信"), YIXINTONG(SupplierConstant.YIXINTONG, "亿信通"),
|
||||
;
|
||||
|
||||
private final String value;
|
||||
private final String description;
|
||||
|
||||
/**
|
||||
* 转换为 BaseConfig
|
||||
*
|
||||
* @param smsConfig 短信配置
|
||||
* @return BaseConfig
|
||||
*/
|
||||
public abstract BaseConfig toBaseConfig(SmsConfigResp smsConfig);
|
||||
}
|
@@ -53,8 +53,7 @@ public class SmsConfigResp extends BaseDetailResp {
|
||||
|
||||
/**
|
||||
* 厂商
|
||||
* 对齐 sms4j 短信服务商常量类
|
||||
*
|
||||
*
|
||||
* @see org.dromara.sms4j.comm.constant.SupplierConstant
|
||||
*/
|
||||
@Schema(description = "厂商", example = "cloopen")
|
||||
|
@@ -17,11 +17,9 @@
|
||||
package top.continew.admin.system.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||
import org.dromara.sms4j.provider.config.BaseConfig;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import top.continew.admin.system.config.sms.SmsConfigUtil;
|
||||
import top.continew.admin.system.mapper.SmsConfigMapper;
|
||||
import top.continew.admin.system.model.entity.SmsConfigDO;
|
||||
@@ -32,7 +30,6 @@ import top.continew.admin.system.service.SmsConfigService;
|
||||
import top.continew.starter.extension.crud.service.BaseServiceImpl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 短信配置业务实现
|
||||
@@ -72,10 +69,10 @@ public class SmsConfigServiceImpl extends BaseServiceImpl<SmsConfigMapper, SmsCo
|
||||
*/
|
||||
private void load(SmsConfigDO entity) {
|
||||
SmsConfigResp smsConfig = this.get(entity.getId());
|
||||
|
||||
BaseConfig config = SmsConfigUtil.from(smsConfig);
|
||||
if (Objects.nonNull(config))
|
||||
if (config != null) {
|
||||
SmsFactory.createSmsBlend(config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user