Browse Source

获取签名

wangyunpeng 3 weeks ago
parent
commit
c6333725be

+ 31 - 3
api-module/src/main/java/com/tzld/piaoquan/api/controller/FileController.java

@@ -6,9 +6,11 @@ import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
 import com.tzld.piaoquan.api.common.exception.CommonException;
 import com.tzld.piaoquan.api.common.exception.CommonException;
 import com.tzld.piaoquan.api.config.AliOssConfig;
 import com.tzld.piaoquan.api.config.AliOssConfig;
 import com.tzld.piaoquan.api.model.param.FileUploadParam;
 import com.tzld.piaoquan.api.model.param.FileUploadParam;
-import com.tzld.piaoquan.api.model.param.contentplatform.OssUploadSignParam;
+import com.tzld.piaoquan.api.model.param.OssUploadSignParam;
+import com.tzld.piaoquan.api.model.param.contentplatform.StsTokenParam;
 import com.tzld.piaoquan.api.model.vo.FileInfo;
 import com.tzld.piaoquan.api.model.vo.FileInfo;
-import com.tzld.piaoquan.api.model.vo.contentplatform.SignatureVO;
+import com.tzld.piaoquan.api.model.vo.SignatureVO;
+import com.tzld.piaoquan.api.model.vo.StsTokenVO;
 import com.tzld.piaoquan.api.util.AliOssFileTool;
 import com.tzld.piaoquan.api.util.AliOssFileTool;
 import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
 import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
@@ -21,6 +23,7 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
+import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.io.IOException;
 
 
 @RestController
 @RestController
@@ -48,7 +51,7 @@ public class FileController {
         fileInfo.setFileUrl(fileUrl);
         fileInfo.setFileUrl(fileUrl);
         String bucketName = AliOssConfig.getBucket(EnumPublicBuckets.PUBBUCKET.getBucketName());
         String bucketName = AliOssConfig.getBucket(EnumPublicBuckets.PUBBUCKET.getBucketName());
         boolean isExistFile = AliOssFileTool.getOssClient().doesObjectExist(bucketName, param.getFileUri());
         boolean isExistFile = AliOssFileTool.getOssClient().doesObjectExist(bucketName, param.getFileUri());
-        if (!isExistFile){
+        if (!isExistFile) {
             throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "上传文件不存在!!");
             throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "上传文件不存在!!");
         }
         }
         return CommonResponse.create(fileInfo);
         return CommonResponse.create(fileInfo);
@@ -68,4 +71,29 @@ public class FileController {
         }
         }
         return CommonResponse.success(signatureVO);
         return CommonResponse.success(signatureVO);
     }
     }
+
+    /**
+     * 尽量控制前端获取oss权限,降低安全风险
+     * 有效期为15分钟,getStsToken接口为1小时
+     *
+     * @param stsTokenParam
+     * @param request
+     * @return
+     * @throws Exception
+     */
+    @CrossOrigin(origins = "*")
+    @PostMapping("/getTempStsToken")
+    @ApiOperation(value = "获取STS临时令牌")
+    public CommonResponse<StsTokenVO> getTempStsToken(StsTokenParam stsTokenParam, HttpServletRequest request) throws Exception {
+        log.info("获取STS临时令牌 param" + JSON.toJSONString(stsTokenParam));
+        StsTokenVO stsTokenVO;
+        try {
+            String fileName = AliOssFileTool.getRandomObjectKey(stsTokenParam.getFileType());
+            stsTokenVO = AliOssFileTool.getStsToken(fileName, 15 * 60L);
+        } catch (Exception e) {
+            log.error("获取STS临时令牌", e);
+            return CommonResponse.create(ExceptionEnum.SYSTEM_ERROR.getCode(), "获取STS临时令牌失败");
+        }
+        return CommonResponse.success(stsTokenVO);
+    }
 }
 }

+ 2 - 2
api-module/src/main/java/com/tzld/piaoquan/api/job/wecom/thirdpart/WeComCreateRoomJob.java

@@ -149,7 +149,7 @@ public class WeComCreateRoomJob {
                                List<ThirdPartWeComStaffUser> staffUserList,
                                List<ThirdPartWeComStaffUser> staffUserList,
                                Integer roomNum) {
                                Integer roomNum) {
         Iterator<ThirdPartWeComStaffUser> iterator = staffUserList.iterator();
         Iterator<ThirdPartWeComStaffUser> iterator = staffUserList.iterator();
-        // todo 暂时每次任务仅创建一个群
+        // todo createRoom 暂时每次任务仅创建一个群
         //while (iterator.hasNext()) {
         //while (iterator.hasNext()) {
         List<Long> vids = new ArrayList<>();
         List<Long> vids = new ArrayList<>();
         List<ThirdPartWeComStaffUser> addUserList = new ArrayList<>();
         List<ThirdPartWeComStaffUser> addUserList = new ArrayList<>();
@@ -206,7 +206,7 @@ public class WeComCreateRoomJob {
             setRoomAntiRequest.setAntiIds(antiSpamRuleList.stream().map(AntiSpamRuleResponse.AntiSpamRule::getId).collect(Collectors.toList()));
             setRoomAntiRequest.setAntiIds(antiSpamRuleList.stream().map(AntiSpamRuleResponse.AntiSpamRule::getId).collect(Collectors.toList()));
             apiClient.setRoomAnti(setRoomAntiRequest);
             apiClient.setRoomAnti(setRoomAntiRequest);
         }
         }
-        // todo 设置管理员
+        // todo createRoom 设置管理员
         //apiClient.addRoomAdmins();
         //apiClient.addRoomAdmins();
     }
     }
 
 

+ 2 - 1
api-module/src/main/java/com/tzld/piaoquan/api/model/param/contentplatform/OssUploadSignParam.java → api-module/src/main/java/com/tzld/piaoquan/api/model/param/OssUploadSignParam.java

@@ -1,5 +1,6 @@
-package com.tzld.piaoquan.api.model.param.contentplatform;
+package com.tzld.piaoquan.api.model.param;
 
 
+import com.tzld.piaoquan.api.model.param.contentplatform.VideoApiBaseParam;
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.Data;
 
 

+ 19 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/param/contentplatform/StsTokenParam.java

@@ -0,0 +1,19 @@
+package com.tzld.piaoquan.api.model.param.contentplatform;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.hibernate.validator.constraints.NotEmpty;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+public class StsTokenParam extends VideoApiBaseParam {
+	
+	@NotEmpty(message = "fileType不能为空")
+	@NotNull(message = "fileType不能为空")
+	@ApiModelProperty(value = "文件类型:(1:PICTURE, 2:VIDEO, 3:VOICE, 4:FILE, 5:GIF)")
+	private Integer fileType;
+	@ApiModelProperty(value = "第一次获取token时返回的唯一标识字符串,用来在上传大文件时若签名快失效时重新获取对应文件的token")
+	private String uploadId;
+
+}

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/model/vo/contentplatform/SignatureVO.java → api-module/src/main/java/com/tzld/piaoquan/api/model/vo/SignatureVO.java

@@ -1,4 +1,4 @@
-package com.tzld.piaoquan.api.model.vo.contentplatform;
+package com.tzld.piaoquan.api.model.vo;
 
 
 import com.tzld.piaoquan.api.config.AliOssConfig;
 import com.tzld.piaoquan.api.config.AliOssConfig;
 import lombok.Data;
 import lombok.Data;

+ 20 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/vo/StsTokenVO.java

@@ -0,0 +1,20 @@
+package com.tzld.piaoquan.api.model.vo;
+
+import lombok.Data;
+
+@Data
+public class StsTokenVO {
+    private String Expiration;
+    private String AccessKeyId;
+    private String AccessKeySecret;
+    private String SecurityToken;
+    private String RequestId;
+    private String FileName;
+    private String Host;
+    private String[] Hosts;
+    private String Bucket;
+    private String Region;
+    private Boolean Cname;
+    private Long serverTimestamp;
+
+}

+ 2 - 2
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/impl/ContentPlatformSettingServiceImpl.java

@@ -30,7 +30,7 @@ public class ContentPlatformSettingServiceImpl implements ContentPlatformSetting
     @Override
     @Override
     public WxBaseUserInfoVO wxLoginByWeb(WxWebLoginParam param) {
     public WxBaseUserInfoVO wxLoginByWeb(WxWebLoginParam param) {
         ContentPlatformAccount user = LoginUserContext.getUser();
         ContentPlatformAccount user = LoginUserContext.getUser();
-        // todo 调用webLogin接口 登录/注册 票圈用户
+        // todo uploadVideo 调用webLogin接口 登录/注册 票圈用户
         WxBaseUserInfoVO wxBaseUserInfoVO = new WxBaseUserInfoVO();
         WxBaseUserInfoVO wxBaseUserInfoVO = new WxBaseUserInfoVO();
         ContentPlatformPqAccountRel pqAccountRel = getPqAccountRel(user.getId());
         ContentPlatformPqAccountRel pqAccountRel = getPqAccountRel(user.getId());
         if (Objects.nonNull(pqAccountRel)) {
         if (Objects.nonNull(pqAccountRel)) {
@@ -54,7 +54,7 @@ public class ContentPlatformSettingServiceImpl implements ContentPlatformSetting
     }
     }
 
 
     private void asyncUpdatePqAccountTelNum(Long uid, String telNum) {
     private void asyncUpdatePqAccountTelNum(Long uid, String telNum) {
-        // todo 修改票圈用户手机号
+        // todo uploadVideo 修改票圈用户手机号
     }
     }
 
 
     private ContentPlatformPqAccountRel getPqAccountRel(Long accountId) {
     private ContentPlatformPqAccountRel getPqAccountRel(Long accountId) {

+ 5 - 5
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/impl/ContentPlatformUploadContentServiceImpl.java

@@ -36,7 +36,7 @@ public class ContentPlatformUploadContentServiceImpl implements ContentPlatformU
     @Override
     @Override
     public UploadVideoItemVO publishVideo(PublishVideoParam param) {
     public UploadVideoItemVO publishVideo(PublishVideoParam param) {
         ContentPlatformAccount user = LoginUserContext.getUser();
         ContentPlatformAccount user = LoginUserContext.getUser();
-        // todo 调用视频发布 获取videoId
+        // todo uploadVideo 调用视频发布 获取videoId
         Long videoId = null;
         Long videoId = null;
         ContentPlatformUploadVideo uploadVideo = new ContentPlatformUploadVideo();
         ContentPlatformUploadVideo uploadVideo = new ContentPlatformUploadVideo();
         uploadVideo.setVideoId(videoId);
         uploadVideo.setVideoId(videoId);
@@ -63,7 +63,7 @@ public class ContentPlatformUploadContentServiceImpl implements ContentPlatformU
         uploadVideo.setAuditStatus(UploadVideoAuditStatusEnum.AUDITING.getVal());
         uploadVideo.setAuditStatus(UploadVideoAuditStatusEnum.AUDITING.getVal());
         uploadVideo.setUpdateTimestamp(System.currentTimeMillis());
         uploadVideo.setUpdateTimestamp(System.currentTimeMillis());
         uploadVideoMapper.updateByPrimaryKeySelective(uploadVideo);
         uploadVideoMapper.updateByPrimaryKeySelective(uploadVideo);
-        // todo 调用修改视频接口
+        // todo uploadVideo 调用修改视频接口
         return UploadVideoItemVO.convert(uploadVideo);
         return UploadVideoItemVO.convert(uploadVideo);
     }
     }
 
 
@@ -86,7 +86,7 @@ public class ContentPlatformUploadContentServiceImpl implements ContentPlatformU
         uploadVideo.setIsDelete(1);
         uploadVideo.setIsDelete(1);
         uploadVideo.setUpdateTimestamp(System.currentTimeMillis());
         uploadVideo.setUpdateTimestamp(System.currentTimeMillis());
         uploadVideoMapper.updateByPrimaryKeySelective(uploadVideo);
         uploadVideoMapper.updateByPrimaryKeySelective(uploadVideo);
-        // todo 调用删除视频接口
+        // todo uploadVideo 调用删除视频接口
     }
     }
 
 
     @Override
     @Override
@@ -95,9 +95,9 @@ public class ContentPlatformUploadContentServiceImpl implements ContentPlatformU
         if (uploadVideo == null) {
         if (uploadVideo == null) {
             return;
             return;
         }
         }
-        // todo 转化审核状态
+        // todo uploadVideo 转化审核状态
         uploadVideo.setAuditStatus(param.getAuditStatus());
         uploadVideo.setAuditStatus(param.getAuditStatus());
-        // todo 更改审核失败原因
+        // todo uploadVideo 更改审核失败原因
         uploadVideo.setAuditReason(param.getAuditReason());
         uploadVideo.setAuditReason(param.getAuditReason());
         uploadVideo.setUpdateTimestamp(System.currentTimeMillis());
         uploadVideo.setUpdateTimestamp(System.currentTimeMillis());
         uploadVideoMapper.updateByPrimaryKeySelective(uploadVideo);
         uploadVideoMapper.updateByPrimaryKeySelective(uploadVideo);

+ 100 - 7
api-module/src/main/java/com/tzld/piaoquan/api/util/AliOssFileTool.java

@@ -29,7 +29,8 @@ import com.stuuudy.commons.util.exception.CommonsException;
 import com.stuuudy.commons.util.exception.EnumErrorException;
 import com.stuuudy.commons.util.exception.EnumErrorException;
 import com.tzld.piaoquan.api.common.enums.EnumUploadFileType;
 import com.tzld.piaoquan.api.common.enums.EnumUploadFileType;
 import com.tzld.piaoquan.api.config.AliOssConfig;
 import com.tzld.piaoquan.api.config.AliOssConfig;
-import com.tzld.piaoquan.api.model.vo.contentplatform.SignatureVO;
+import com.tzld.piaoquan.api.model.vo.SignatureVO;
+import com.tzld.piaoquan.api.model.vo.StsTokenVO;
 import com.tzld.piaoquan.growth.common.utils.DateUtils;
 import com.tzld.piaoquan.growth.common.utils.DateUtils;
 import com.tzld.piaoquan.growth.common.utils.RandomUtil;
 import com.tzld.piaoquan.growth.common.utils.RandomUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.CollectionUtils;
@@ -1140,7 +1141,7 @@ public class AliOssFileTool extends AliOssConfig {
 //		Date expiration = new Date(new Date().getTime() +( 60) * 1000);
 //		Date expiration = new Date(new Date().getTime() +( 60) * 1000);
         // 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
         // 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
 
 
-        URL url = getOssReadOnlyClient().generatePresignedUrl(PropertiesUtils.getVideoBucket(),
+        URL url = getOssReadOnlyClient().generatePresignedUrl(BasePropertiesUtils.getVideoBucket(),
                 filePath, expiration, HttpMethod.GET);
                 filePath, expiration, HttpMethod.GET);
         String path = url.getFile();
         String path = url.getFile();
         if (StringUtils.startsWith(path, "/")) {
         if (StringUtils.startsWith(path, "/")) {
@@ -1152,7 +1153,7 @@ public class AliOssFileTool extends AliOssConfig {
 
 
     public static String saveObjectFromInternal(InputStream inputStream, String fullKey)
     public static String saveObjectFromInternal(InputStream inputStream, String fullKey)
             throws OSSException, ClientException, IOException {
             throws OSSException, ClientException, IOException {
-        String bucketName = PropertiesUtils.getVideoBucket();
+        String bucketName = BasePropertiesUtils.getVideoBucket();
         getInternalOssClient().putObject(bucketName, fullKey, inputStream);
         getInternalOssClient().putObject(bucketName, fullKey, inputStream);
         return fullKey;
         return fullKey;
     }
     }
@@ -1219,7 +1220,7 @@ public class AliOssFileTool extends AliOssConfig {
             try {
             try {
                 ossInternalClient.restoreObject(bucket, srckey);
                 ossInternalClient.restoreObject(bucket, srckey);
             } catch (Exception e) {
             } catch (Exception e) {
-                // TODO Auto-generated catch blockvideo-common/src/main/java/com/weiqu/video/common/enums/ExceptionCodeEnum.java
+                // TODO OSS Auto-generated catch blockvideo-common/src/main/java/com/weiqu/video/common/enums/ExceptionCodeEnum.java
 //				e.printStackTrace();
 //				e.printStackTrace();
                 logger.error("视频可能在解冻中");
                 logger.error("视频可能在解冻中");
             }
             }
@@ -1241,7 +1242,7 @@ public class AliOssFileTool extends AliOssConfig {
         try {
         try {
             isRestoreCompleted = objectMetadata.isRestoreCompleted();
             isRestoreCompleted = objectMetadata.isRestoreCompleted();
         } catch (Exception e) {
         } catch (Exception e) {
-            // TODO Auto-generated catch block
+            // TODO OSS Auto-generated catch block
 //			e.printStackTrace();
 //			e.printStackTrace();
             logger.error("视频可能在解冻中");
             logger.error("视频可能在解冻中");
         }
         }
@@ -1261,7 +1262,7 @@ public class AliOssFileTool extends AliOssConfig {
             return -1;
             return -1;
         }
         }
         String realPath = path.replace(PropertiesUtils.getDownloadDomain(), "");
         String realPath = path.replace(PropertiesUtils.getDownloadDomain(), "");
-        String bucketName = PropertiesUtils.getVideoBucket();
+        String bucketName = BasePropertiesUtils.getVideoBucket();
         ObjectMetadata objectMetadata = null;
         ObjectMetadata objectMetadata = null;
         try {
         try {
             objectMetadata = getInternalOssClient().getObjectMetadata(bucketName, realPath);
             objectMetadata = getInternalOssClient().getObjectMetadata(bucketName, realPath);
@@ -1295,7 +1296,7 @@ public class AliOssFileTool extends AliOssConfig {
 
 
 
 
     public static Map<String, Object> getMediaAllInfo(String inPath) {
     public static Map<String, Object> getMediaAllInfo(String inPath) {
-        return getMediaAllInfo(inPath, PropertiesUtils.getVideoBucket());
+        return getMediaAllInfo(inPath, BasePropertiesUtils.getVideoBucket());
     }
     }
 
 
     public static Map<String, Object> getMediaAllInfo(String inPath, String bucketName) {
     public static Map<String, Object> getMediaAllInfo(String inPath, String bucketName) {
@@ -1379,5 +1380,97 @@ public class AliOssFileTool extends AliOssConfig {
         return getInternalOssClient().copyObject(request);
         return getInternalOssClient().copyObject(request);
     }
     }
 
 
+    public static String getRandomObjectKey(Integer fileType) {
+        String env = PropertiesUtils.getProjectEnv();
+        if (StringUtils.isEmpty(env)) {
+            env = "qa";
+        }
+        String fileName = RandomUtil.generate18String();
+        if (EnumUploadFileType.VIDEO.getIntType().equals(fileType)) {
+            fileName = "/video/" + env + "/" + DateUtils.dateToStringyyyyMMdd(new Date()) + "/" + fileName;
+        } else if (EnumUploadFileType.VOICE.getIntType().equals(fileType)) {
+            fileName = "/voice/" + env + "/" + DateUtils.dateToStringyyyyMMdd(new Date()) + "/" + fileName;
+        } else {
+            fileName = "/pic/" + env + "/" + DateUtils.dateToStringyyyyMMdd(new Date()) + "/" + fileName;
+        }
+        return getProjectName() + fileName;
+    }
+
+    public static StsTokenVO getStsToken(String fileName, Long durationSeconds) {
+
+        String endpoint = BasePropertiesUtils.getLongvideoStsEndpoint();
+        String accessKeyId = BasePropertiesUtils.getLongvideoStsAccessKeyId();
+        String accessKeySecret = BasePropertiesUtils.getLongvideoStsAccessKeySecret();
+        String roleArn = BasePropertiesUtils.getLongvideoStsRoleArn();
+        String roleSessionName = BasePropertiesUtils.getLongvideoStsSessionName();
+        StsTokenVO result = new StsTokenVO();
+        try {
+            String region = "cn-hangzhou";
+            DefaultProfile.addEndpoint("", "", "Sts", endpoint);
+            IClientProfile profile = DefaultProfile.getProfile("", accessKeyId, accessKeySecret);
+            DefaultAcsClient client = new DefaultAcsClient(profile);
+            final AssumeRoleRequest request = new AssumeRoleRequest();
+            request.setMethod(MethodType.POST);
+            request.setRoleArn(roleArn);
+            request.setRoleSessionName(roleSessionName);
+            //设置过期时间 临时访问凭证的有效时间,单位为秒。最小值为900,最大值以当前角色设定的最大会话时间为准。角色最大会话时间取值范围为3600秒~43200秒
+            if (Objects.nonNull(durationSeconds)) {
+                request.setDurationSeconds(durationSeconds);
+            }
+            JSONObject policy = getUploadFileStsPolicy(BasePropertiesUtils.getVideoBucket(), fileName);
+            request.setPolicy(policy.toJSONString());
+
+            final AssumeRoleResponse response = client.getAcsResponse(request);
+            result.setExpiration(response.getCredentials().getExpiration());
+            result.setAccessKeyId(response.getCredentials().getAccessKeyId());
+            result.setAccessKeySecret(response.getCredentials().getAccessKeySecret());
+            result.setSecurityToken(response.getCredentials().getSecurityToken());
+            result.setRequestId(response.getRequestId());
+            result.setFileName(fileName);
+            result.setHost(AliOssConfig.getUploadDomain());
+
+            String host0 = BasePropertiesUtils.getOssaccelerateUploadDomain();
+            String host1 = "https://" + AliOssConfig.getBucket(EnumPublicBuckets.PUBBUCKET.getBucketName()) + "." + AliOssConfig.getOssEndPoint() + "/";
+            result.setHosts(new String[]{host0, host1});
+
+            result.setBucket(BasePropertiesUtils.getVideoBucket());
+            result.setRegion(region);
+            result.setCname(true);
+
+            // 返回服务器当前时间
+            result.setServerTimestamp(System.currentTimeMillis());
+
+        } catch (com.aliyuncs.exceptions.ClientException e) {
+            logger.error(String.format("获取临时令牌失败,errorCode:%s;errorMessage:%s;requestId:%s",
+                    e.getErrCode(), e.getErrMsg(), e.getRequestId()));
+        } catch (Exception e) {
+            logger.error("获取临时令牌失败", e);
+        }
+        return result;
+    }
+
+    private static JSONObject getUploadFileStsPolicy(String bucketName, String fileName) {
+
+        JSONObject policy = new JSONObject();
+        policy.put("Version", "1");
+
+        JSONArray statements = new JSONArray();
+        JSONObject statement = new JSONObject();
+        statement.put("Effect", "Allow");
+
+        JSONArray action = new JSONArray();
+        action.add("oss:PutObject");
+
+        statement.put("Action", action);
+        JSONArray resource = new JSONArray();
+        resource.add("acs:oss:*:1894469520484605:" + bucketName + "/" + fileName);
+        statement.put("Resource", resource);
+
+        statements.add(statement);
+        policy.put("Statement", statements);
+
+        logger.info(String.format("Policy:%s", JSON.toJSONString(policy)));
+        return policy;
+    }
 
 
 }
 }

+ 72 - 0
api-module/src/main/java/com/tzld/piaoquan/api/util/BasePropertiesUtils.java

@@ -0,0 +1,72 @@
+package com.tzld.piaoquan.api.util;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+@Slf4j
+public class BasePropertiesUtils {
+
+    public static Properties properties;
+
+    static {
+        Properties mainProperties = new Properties();
+        properties = new Properties();
+        try {
+            InputStream mainStream = BasePropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");
+            mainProperties.load(mainStream);
+            // 先通过虚拟机参数 -Denv=value去取配置文件的值
+            // 如果没有设置-Denv的虚拟机参数则说明是本地开发环境,则读取application.properties文件中spring.profiles.active的值
+            String env = System.getProperty("env");
+            if (StringUtils.isEmpty(env)) {
+                env = mainProperties.getProperty("spring.profiles.active");
+            }
+            if (StringUtils.isEmpty(env)) {
+                log.error("设置spring.profiles.active or 设置虚拟机启动参数 -Denv错误!!!");
+                System.exit(1);
+            }
+            InputStream activeStream = BasePropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");
+            properties.load(activeStream);
+            log.info("开发环境为: " + env);
+        } catch (IOException e) {
+            log.error(e.getMessage());
+            System.exit(1);
+        }
+    }
+
+    public static Properties getProperties() {
+        return properties;
+    }
+
+    public static String getVideoBucket() {
+        return getProperties().getProperty("oss.video.bucket");
+    }
+
+    public static String getLongvideoStsEndpoint() {
+        return getProperties().getProperty("oss.longvideo.video.sts.endpoint");
+    }
+
+    public static String getLongvideoStsAccessKeyId() {
+        return getProperties().getProperty("oss.longvideo.video.sts.accessKeyId");
+    }
+
+    public static String getLongvideoStsAccessKeySecret() {
+        return getProperties().getProperty("oss.longvideo.video.sts.accessKeySecret");
+    }
+
+    public static String getLongvideoStsRoleArn() {
+        return getProperties().getProperty("oss.longvideo.video.sts.roleArn");
+    }
+
+    public static String getLongvideoStsSessionName() {
+        return getProperties().getProperty("oss.longvideo.video.sts.roleSessionName");
+    }
+
+    public static String getOssaccelerateUploadDomain() {
+        return getProperties().getProperty("ossaccelerate.upload.domain");
+    }
+
+}

+ 8 - 1
api-module/src/main/resources/application.properties

@@ -88,4 +88,11 @@ oss.growth.priBucket=private:art-pribucket,privateVideo:art-privideo,privateVide
 oss.growth.priEndPoint=pricdn.yishihui.com
 oss.growth.priEndPoint=pricdn.yishihui.com
 oss.growth.needPress=true
 oss.growth.needPress=true
 oss.growth.internal.endPoint=oss-cn-hangzhou.aliyuncs.com
 oss.growth.internal.endPoint=oss-cn-hangzhou.aliyuncs.com
-cdn.upload.domain=https://weappupload.piaoquantv.com/
+cdn.upload.domain=https://weappupload.piaoquantv.com/
+oss.longvideo.video.sts.endpoint=sts.cn-hangzhou.aliyuncs.com
+oss.longvideo.video.sts.accessKeyId=LTAIfZYdxeQpq3YI
+oss.longvideo.video.sts.accessKeySecret=1yISVWe5Gws2VAdTMc9XWIHpjPd7ja
+oss.longvideo.video.sts.roleArn=acs:ram::1894469520484605:role/oss-sts
+oss.longvideo.video.sts.roleSessionName=session-name
+ossaccelerate.upload.domain=https://ossaccelerateupload.piaoquantv.com/
+oss.video.bucket=art-pubbucket