From d9e10b14a982e83edf22c55e4e1420ba58ae7e24 Mon Sep 17 00:00:00 2001 From: xyc <3422692813@qq.com> Date: Fri, 25 Apr 2025 10:16:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9ECOS=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/cos/CosStsController.java | 36 ++++++++ .../src/main/resources/application.yml | 8 ++ ruoyi-common/pom.xml | 11 ++- .../ruoyi/system/service/CosStsService.java | 82 +++++++++++++++++++ 4 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/cos/CosStsController.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/CosStsService.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/cos/CosStsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/cos/CosStsController.java new file mode 100644 index 0000000..529f860 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/cos/CosStsController.java @@ -0,0 +1,36 @@ +package com.ruoyi.web.controller.cos; + +import com.ruoyi.system.service.CosStsService; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.security.PermitAll; +import java.util.Map; + +/** + * @Description: sts + * @Author: 86187 + * @Date: 2025/03/20 16:34 + * @Version: 1.0 + */ +@RestController +@RequestMapping("/cos") +@RequiredArgsConstructor +public class CosStsController { + + private final CosStsService cosStsService; + + /** + * 获取cos临时密钥 + * + * @return sts + */ + @GetMapping("/sts") + @PermitAll + public Map getCosSts() { + return cosStsService.getTempKeys(); + } +} diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index c2c809f..6d45895 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -173,3 +173,11 @@ dl-rights: # 每月发布通告额度 addNotice: 3 report: 5 + #################### 腾讯COS相关配置 #################### +cos: + baseUrl: notice-1348525010.cos.ap-beijing.myqcloud.com + accessKey: AKIDDbyY3Wr9D4i9LK6f085pLfleJlz60hAP + secretKey: 82kJfnu11ulW5TghV5TecVYP3TghXAZl + regionName: ap-beijing + bucketName: notice-1348525010 + folderPrefix: /files diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index e985d7a..664dbd6 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -70,13 +70,13 @@ org.apache.commons commons-lang3 - + com.fasterxml.jackson.core jackson-databind - + com.alibaba.fastjson2 @@ -165,7 +165,12 @@ mybatis-plus 3.3.0 + + com.qcloud + cos-sts_api + 3.1.0 + - \ No newline at end of file + diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/CosStsService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/CosStsService.java new file mode 100644 index 0000000..7570b14 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/CosStsService.java @@ -0,0 +1,82 @@ +package com.ruoyi.system.service; + +import com.tencent.cloud.CosStsClient; +import com.tencent.cloud.Response; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +/** + * @Description: sts + * @Author: 86187 + * @Date: 2025/03/20 16:18 + * @Version: 1.0 + */ +@Service +public class CosStsService { + // 你的腾讯云账号的 SecretId 和 SecretKey + @Value("${cos.accessKey}") + private String SECRET_ID; + @Value("${cos.secretKey}") + private String SECRET_KEY; + + // 存储桶所属的地域,例如 "ap-shanghai" + @Value("${cos.regionName}") + private String REGION; + + // 你的存储桶名,例如 "example-1250000000" + @Value("${cos.bucketName}") + private String BUCKET; + + // 临时密钥有效期(单位秒),最长不超过 2 小时(7200 秒) + private static final int DURATION_SECONDS = 1800; + + public Map getTempKeys() { + TreeMap config = new TreeMap(); + + try { + // 云 api 密钥 SecretId + config.put("secretId", SECRET_ID); + // 云 api 密钥 SecretKey + config.put("secretKey", SECRET_KEY); + // 临时密钥有效时长,单位是秒 + config.put("durationSeconds", 1800); + // 换成你的 bucket + config.put("bucket", BUCKET); + // 换成 bucket 所在地区 + config.put("region", REGION); + + // 可以通过 allowPrefixes 指定前缀数组, 例子: a.jpg 或者 a/* 或者 * (使用通配符*存在重大安全风险, 请谨慎评估使用) + config.put("allowPrefixes", new String[] { + "*" + }); + + // 密钥的权限列表。简单上传和分片需要以下的权限,其他权限列表请看 https://cloud.tencent.com/document/product/436/31923 + String[] allowActions = new String[] { + // 简单上传 + "name/cos:PutObject", + "name/cos:PostObject", + // 分片上传 + "name/cos:InitiateMultipartUpload", + "name/cos:ListMultipartUploads", + "name/cos:ListParts", + "name/cos:UploadPart", + "name/cos:CompleteMultipartUpload" + }; + config.put("allowActions", allowActions); + + Response response = CosStsClient.getCredential(config); + Map result= new HashMap<>(); + result.put("credentials", response.credentials); + result.put("startTime", response.startTime); + result.put("expiredTime", response.expiredTime); + return result; + } catch (Exception e) { + e.printStackTrace(); + throw new IllegalArgumentException("no valid secret !"); + } + } +} From b3da9251f8a08cb7ec70ee75b2a7df45423a0f2f Mon Sep 17 00:00:00 2001 From: PQZ Date: Fri, 25 Apr 2025 10:23:36 +0800 Subject: [PATCH 2/2] 1 --- .../member/service/impl/MemberPointsServiceImpl.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberPointsServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberPointsServiceImpl.java index cf3a3a8..245a9c6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberPointsServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberPointsServiceImpl.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.base.domain.BaseCategory; +import com.ruoyi.base.service.IBaseCategoryService; import com.ruoyi.common.config.DlRightsConfig; import com.ruoyi.common.core.domain.DlBaseEntity; import com.ruoyi.member.domain.MemberPoints; @@ -25,6 +27,8 @@ import java.util.List; public class MemberPointsServiceImpl extends ServiceImpl implements IMemberPointsService { @Autowired private MemberPointsMapper memberPointsMapper; + @Autowired + private IBaseCategoryService categoryService; /** @@ -50,6 +54,12 @@ public class MemberPointsServiceImpl extends ServiceImpl categoryList = categoryService.selectByCode(memberPoints.getFromCode()); + BaseCategory category = categoryList.get(0); + memberPoints.setPoints(Integer.parseInt(category.getContent())); + memberPoints.setTitle(category.getTitle()); + } //查询当前用户最近变动记录 LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.eq(DlBaseEntity::getDelFlag,0) @@ -62,7 +72,7 @@ public class MemberPointsServiceImpl extends ServiceImpl