parent
659df35446
commit
3858e21e39
@ -0,0 +1,74 @@
|
|||||||
|
package com.ruoyi.file.controller;
|
||||||
|
|
||||||
|
import com.aliyun.oss.common.utils.BinaryUtil;
|
||||||
|
import com.aliyun.oss.model.MatchMode;
|
||||||
|
import com.aliyun.oss.model.PolicyConditions;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.file.utils.OssClient;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
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 java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.ruoyi.file.utils.OssClient.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* oss服务控制器
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-15
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("oss")
|
||||||
|
@Api(tags = "OSS管理")
|
||||||
|
@Log4j2
|
||||||
|
public class OssController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
OssClient ossClient;
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/policy")
|
||||||
|
public R policy() {
|
||||||
|
String host = HTTPS + bucketName + DOT + endpoint;
|
||||||
|
String dir = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||||
|
|
||||||
|
Map<String, String> respMap = null;
|
||||||
|
try {
|
||||||
|
//10分钟过期
|
||||||
|
long expireTime = 600;
|
||||||
|
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
|
||||||
|
Date expiration = new Date(expireEndTime);
|
||||||
|
PolicyConditions policyConds = new PolicyConditions();
|
||||||
|
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1048576000);
|
||||||
|
policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
|
||||||
|
|
||||||
|
String postPolicy = ossClient.getOssClient().generatePostPolicy(expiration, policyConds);
|
||||||
|
byte[] binaryData = postPolicy.getBytes(StandardCharsets.UTF_8);
|
||||||
|
String encodedPolicy = BinaryUtil.toBase64String(binaryData);
|
||||||
|
String postSignature = ossClient.getOssClient().calculatePostSignature(postPolicy);
|
||||||
|
|
||||||
|
respMap = new LinkedHashMap<>();
|
||||||
|
respMap.put("accessid", keyId);
|
||||||
|
respMap.put("policy", encodedPolicy);
|
||||||
|
respMap.put("signature", postSignature);
|
||||||
|
respMap.put("dir", dir);
|
||||||
|
respMap.put("host", host);
|
||||||
|
respMap.put("expire", String.valueOf(expireEndTime / 1000));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return R.ok(respMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package com.ruoyi.file.utils;
|
||||||
|
|
||||||
|
import com.aliyun.oss.OSS;
|
||||||
|
import com.aliyun.oss.OSSClientBuilder;
|
||||||
|
import com.ruoyi.file.config.AliyunOssProperties;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取ossClient
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-03-15
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class OssClient implements BeanPostProcessor {
|
||||||
|
|
||||||
|
public static final String HTTPS = "https://";
|
||||||
|
|
||||||
|
public static final String DOT = ".";
|
||||||
|
|
||||||
|
public static final String SLASH = "/";
|
||||||
|
|
||||||
|
public static String endpoint;
|
||||||
|
public static String keyId;
|
||||||
|
public static String keySecret;
|
||||||
|
public static String bucketName;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AliyunOssProperties aliyunOssProperties;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||||
|
OssClient.endpoint = aliyunOssProperties.getEndpoint();
|
||||||
|
OssClient.keyId = aliyunOssProperties.getKeyId();
|
||||||
|
OssClient.keySecret = aliyunOssProperties.getKeySecret();
|
||||||
|
OssClient.bucketName = aliyunOssProperties.getBucketName();
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取oss实例
|
||||||
|
*
|
||||||
|
* @return OSS
|
||||||
|
*/
|
||||||
|
public OSS getOssClient() {
|
||||||
|
String endpoint = aliyunOssProperties.getEndpoint();
|
||||||
|
String keyId = aliyunOssProperties.getKeyId();
|
||||||
|
String keySecret = aliyunOssProperties.getKeySecret();
|
||||||
|
return new OSSClientBuilder().build(endpoint,
|
||||||
|
keyId, keySecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>xjs-project-mall</artifactId>
|
|
||||||
<groupId>com.xjs</groupId>
|
|
||||||
<version>3.3.0</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<name>第三方服务</name>
|
|
||||||
|
|
||||||
<artifactId>mall-third-party</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!--阿里云存储-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alicloud-oss</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,29 +0,0 @@
|
|||||||
package com.xjs.mall.thirdparty;
|
|
||||||
|
|
||||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
|
|
||||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
|
||||||
import com.ruoyi.common.security.annotation.EnableCustomConfig;
|
|
||||||
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
|
||||||
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
|
|
||||||
import io.seata.spring.boot.autoconfigure.SeataAutoConfiguration;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 商城Product启动器
|
|
||||||
* @author xiejs
|
|
||||||
* @since 2022-03-15
|
|
||||||
*/
|
|
||||||
@SpringBootApplication(exclude ={DataSourceAutoConfiguration.class,
|
|
||||||
SeataAutoConfiguration.class,
|
|
||||||
MybatisPlusAutoConfiguration.class,
|
|
||||||
DynamicDataSourceAutoConfiguration.class} )
|
|
||||||
@EnableCustomConfig
|
|
||||||
@EnableCustomSwagger2
|
|
||||||
@EnableRyFeignClients
|
|
||||||
public class MallThirdPartyApp {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(MallThirdPartyApp.class, args);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
# Tomcat
|
|
||||||
server:
|
|
||||||
port: 9986
|
|
||||||
|
|
||||||
# Spring
|
|
||||||
spring:
|
|
||||||
application:
|
|
||||||
# 应用名称
|
|
||||||
name: xjs-mall-third-party
|
|
||||||
profiles:
|
|
||||||
# 环境配置
|
|
||||||
active: dev
|
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
discovery:
|
|
||||||
# 服务注册地址
|
|
||||||
server-addr: 127.0.0.1:8848
|
|
||||||
config:
|
|
||||||
# 配置中心地址
|
|
||||||
server-addr: 127.0.0.1:8848
|
|
||||||
# 配置文件格式
|
|
||||||
file-extension: yml
|
|
||||||
# 共享配置
|
|
||||||
shared-configs:
|
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
||||||
#配置组
|
|
||||||
group: xjs
|
|
||||||
#命名空间
|
|
||||||
namespace: xjs-666
|
|
@ -1,81 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
|
||||||
<!-- 日志存放路径 -->
|
|
||||||
<property name="log.path" value="logs/xjs-mall/third-party"/>
|
|
||||||
<!-- 日志输出格式 -->
|
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
|
||||||
|
|
||||||
<!-- 控制台输出 -->
|
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统日志输出 -->
|
|
||||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/info.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>INFO</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/error.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>ERROR</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统模块日志级别控制 -->
|
|
||||||
<logger name="com.xjs" level="info" />
|
|
||||||
<!--打印feign DEBUG日志-->
|
|
||||||
<logger name="com.xjs.common.client" level="debug"/>
|
|
||||||
<!-- Spring日志级别控制 -->
|
|
||||||
<logger name="org.springframework" level="warn" />
|
|
||||||
|
|
||||||
<!-- 打开 Bean Searcher 的 SQL 日志 -->
|
|
||||||
<logger name="com.ejlchina.searcher.implement.DefaultSqlExecutor" level="DEBUG" additivity="false">
|
|
||||||
<appender-ref ref="console" />
|
|
||||||
</logger>
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="console" />
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!--系统操作日志-->
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="file_info" />
|
|
||||||
<appender-ref ref="file_error" />
|
|
||||||
</root>
|
|
||||||
</configuration>
|
|
@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
|
|
||||||
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
|
|
||||||
-->
|
|
||||||
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
|
|
||||||
|
|
||||||
<id>mall-third-party</id>
|
|
||||||
|
|
||||||
<classpath>
|
|
||||||
<dir name="D:/Dev/IdeaPerject/GitHub/Cloud/xjs-business/xjs-project-mall/mall-third-party/target/classes">
|
|
||||||
</dir>
|
|
||||||
</classpath>
|
|
||||||
|
|
||||||
</application>
|
|
Loading…
Reference in new issue