sysParam 获取值问题
This commit is contained in:
@@ -12,6 +12,9 @@ import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 验证码工具类
|
||||
*
|
||||
@@ -23,38 +26,24 @@ public class SmsServiceImpl implements SmsService {
|
||||
@Resource
|
||||
private SysParamsService sysParamsService;
|
||||
|
||||
/**
|
||||
* 阿里云key
|
||||
*/
|
||||
private String key;
|
||||
/**
|
||||
* 阿里云secret
|
||||
*/
|
||||
private String secret;
|
||||
/**
|
||||
* 短信模板id
|
||||
*/
|
||||
private String templateCode;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
key = sysParamsService.getSysParamValue(ParamCodeCst.AliYun.ALI_SMS_KEY);
|
||||
secret = sysParamsService.getSysParamValue(ParamCodeCst.AliYun.ALI_SMS_SECRET);
|
||||
templateCode = sysParamsService.getSysParamValue(ParamCodeCst.AliYun.ALI_SMS_TEMPLATE_CODE);
|
||||
log.info("短信工具类初始化完毕,key: {}, secret: {}, templateCode: {}", key, secret, templateCode);
|
||||
}
|
||||
|
||||
public Client createClient() throws Exception {
|
||||
public Client init() throws Exception {
|
||||
Config config = new Config();
|
||||
config.accessKeyId = key;
|
||||
config.accessKeySecret = secret;
|
||||
Map<String, String> aliOssKeys = sysParamsService.getParamsByMap("ali_oss_key_set", ParamCodeCst.ALI_OSS_KEY_SET);
|
||||
config.accessKeyId = aliOssKeys.get(ParamCodeCst.AliYun.ALI_SMS_KEY);
|
||||
config.accessKeySecret = aliOssKeys.get(ParamCodeCst.AliYun.ALI_SMS_SECRET);
|
||||
templateCode = aliOssKeys.get(ParamCodeCst.AliYun.ALI_SMS_TEMPLATE_CODE);
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCode(String phone, String checkCode) {
|
||||
try {
|
||||
Client client = createClient();
|
||||
Client client = init();
|
||||
// 1.发送短信
|
||||
com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
|
||||
.setSignName("陕西超掌柜科技")
|
||||
@@ -67,7 +56,7 @@ public class SmsServiceImpl implements SmsService {
|
||||
if (sendSmsResponse.getStatusCode() != 200) {
|
||||
throw new CzgException("短信发送失败");
|
||||
}
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
log.info("发送短信失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,12 +140,12 @@ public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams
|
||||
|
||||
@Cacheable(cacheNames = "params:entity", key = "#type")
|
||||
@Override
|
||||
public Map<String, String> getParamsByMap(String type, Set<String> keyList) throws CzgException{
|
||||
public Map<String, String> getParamsByMap(String type, Set<String> keyList) throws CzgException {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (String key : keyList) {
|
||||
SysParams sysParam = getSysParam(key);
|
||||
if (sysParam == null || StrUtil.isBlank(sysParam.getParamValue())) {
|
||||
throw new CzgException(key + "参数不存在");
|
||||
throw new CzgException("sysParam的类型" + type + " 的 " + key + "参数不存在");
|
||||
}
|
||||
map.put(key, sysParam.getParamValue());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user