获取临时上传凭证

This commit is contained in:
2024-09-05 17:32:00 +08:00
parent 72a3057126
commit 81b6454557
4 changed files with 61 additions and 15 deletions

View File

@@ -21,6 +21,7 @@ import cn.ysk.cashier.service.dto.QiniuQueryCriteria;
import com.dianguang.cloud.ossservice.config.CloudStorageConfig;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import com.aliyun.teaopenapi.models.Config;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@@ -41,6 +42,8 @@ public interface QiNiuService {
CloudStorageConfig findCloud();
Config findTempCloud();
/**
* 修改配置
* @param qiniuConfig 配置

View File

@@ -1,23 +1,9 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* 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 cn.ysk.cashier.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.ysk.cashier.domain.QiniuConfig;
import cn.ysk.cashier.exception.BadRequestException;
import com.aliyun.teaopenapi.models.Config;
import com.dianguang.cloud.ossservice.config.CloudStorageConfig;
import com.dianguang.cloud.ossservice.service.OSSFactory;
import com.qiniu.common.QiniuException;
@@ -93,6 +79,25 @@ public class QiNiuServiceImpl implements QiNiuService {
return null;
}
@Override
public Config findTempCloud() {
Optional<QiniuConfig> qiniuConfig = qiNiuConfigRepository.findById(1L);
QiniuConfig config= qiniuConfig.orElseGet(QiniuConfig::new);
if(ObjectUtil.isNotEmpty(config)){
com.aliyun.teaopenapi.models.Config config1 = new com.aliyun.teaopenapi.models.Config()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
// .setAccessKeyId(System.getenv("LTAI5tPdEfYSZcqHbjCrtPRD"))
.setAccessKeyId(qiniuConfig.get().getAccessKey())
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret(qiniuConfig.get().getSecretKey());
// Endpoint 请参考 https://api.aliyun.com/product/Sts
config1.endpoint = "sts.cn-hangzhou.aliyuncs.com";
return config1;
}
return null;
}
@Override
@CachePut(key = "'config'")
@Transactional(rollbackFor = Exception.class)