上传临时凭证

This commit is contained in:
2025-02-25 15:03:00 +08:00
parent 2e7b44402c
commit 65d5936980
3 changed files with 50 additions and 1 deletions

View File

@@ -35,6 +35,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>sts20150401</artifactId>
<version>1.1.4</version>
</dependency>
</dependencies>

View File

@@ -1,12 +1,16 @@
package com.czg.controller.admin;
import com.aliyun.sts20150401.models.AssumeRoleResponse;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.system.dto.VersionDTO;
import com.czg.system.enums.SysParamCodeEnum;
import com.czg.system.service.SysParamsService;
import com.czg.system.service.VersionService;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -20,10 +24,13 @@ import java.util.List;
public class VersionController {
@Resource
private VersionService versionService;
@DubboReference
private SysParamsService paramsService;
/**
* 新增版本
*
* @param versionDTO 版本信息
* @return Long id
*/
@@ -35,6 +42,7 @@ public class VersionController {
/**
* 更新版本
*
* @param versionDTO 版本信息
* @return Long id
*/
@@ -46,6 +54,7 @@ public class VersionController {
/**
* 删除版本
*
* @param id 版本id
* @return Long id
*/
@@ -57,8 +66,9 @@ public class VersionController {
/**
* 获取版本信息
*
* @param source 渠道
* @param type 类型
* @param type 类型
* @return VersionDTO
*/
@GetMapping("/{source}/{type}")
@@ -69,6 +79,7 @@ public class VersionController {
/**
* 获取版本列表
*
* @return List<VersionDTO>
*/
@GetMapping("/list")
@@ -76,4 +87,33 @@ public class VersionController {
public CzgResult<List<VersionDTO>> getVersionList() {
return versionService.getVersionList();
}
/**
* 获取上传临时凭证
*/
@GetMapping(value = "/getCredentials")
public CzgResult<Object> getCredentials() {
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
.setAccessKeyId(paramsService.getSysParamValue(SysParamCodeEnum.ALI_OSS_ACCESS_KEY.getCode()))
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret(paramsService.getSysParamValue(SysParamCodeEnum.ALI_OSS_ACCESS_SECRET.getCode()));
// Endpoint 请参考 https://api.aliyun.com/product/Sts
config.endpoint = paramsService.getSysParamValue(SysParamCodeEnum.ALI_OSS_ENDPOINT.getCode());
com.aliyun.sts20150401.Client client = new com.aliyun.sts20150401.Client(config);
com.aliyun.sts20150401.models.AssumeRoleRequest assumeRoleRequest = new com.aliyun.sts20150401.models.AssumeRoleRequest();
assumeRoleRequest.setRoleArn(paramsService.getSysParamValue(SysParamCodeEnum.ALI_OSS_ROLE_ARN.getCode()));
assumeRoleRequest.setRoleSessionName("test");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
// 复制代码运行请自行打印 API 的返回值
AssumeRoleResponse response = client.assumeRoleWithOptions(assumeRoleRequest, runtime);
return CzgResult.success(response.getBody().getCredentials());
} catch (Exception error) {
return CzgResult.failure(error.getMessage());
}
}
}

View File

@@ -12,6 +12,10 @@ public enum SysParamCodeEnum {
PAY_CZG_DOMAIN("pay_czg_domain", "超掌柜支付域名"),
PAY_CZG_NOTIFY_URL("pay_czg_notify_url", "超掌柜支付回调地址"),
PAY_CZG_REFUND_NOTIFY_URL("pay_czg_refund_notify_url", "超掌柜退款回调地址"),
ALI_OSS_ACCESS_KEY("ali_oss_access_key", "阿里云oss_ACCESS_KEY"),
ALI_OSS_ACCESS_SECRET("ali_oss_access_secret", "阿里云oss_secret"),
ALI_OSS_ENDPOINT("ali_oss_endpoint", "阿里云endpoint"),
ALI_OSS_ROLE_ARN("ali_oss_role_arn", "阿里云roleArn"),
;
private final String code;