|
@@ -1,13 +1,21 @@
|
|
package com.caimei;
|
|
package com.caimei;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.aliyun.oss.OSS;
|
|
|
|
+import com.aliyun.oss.OSSClientBuilder;
|
|
|
|
+import com.aliyun.oss.model.ListObjectsRequest;
|
|
|
|
+import com.aliyun.oss.model.OSSObjectSummary;
|
|
|
|
+import com.aliyun.oss.model.ObjectListing;
|
|
import com.caimei.mapper.cmMapper.AuthMapper;
|
|
import com.caimei.mapper.cmMapper.AuthMapper;
|
|
import com.caimei.model.po.CmBrandAuthPo;
|
|
import com.caimei.model.po.CmBrandAuthPo;
|
|
import com.caimei.model.vo.RossAddressVo;
|
|
import com.caimei.model.vo.RossAddressVo;
|
|
import com.caimei.utils.ImageUtils;
|
|
import com.caimei.utils.ImageUtils;
|
|
import com.caimei.utils.OSSUtils;
|
|
import com.caimei.utils.OSSUtils;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
+import org.springframework.beans.factory.annotation.Configurable;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.core.io.ClassPathResource;
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
@@ -15,19 +23,46 @@ import javax.imageio.ImageIO;
|
|
import java.awt.*;
|
|
import java.awt.*;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
@SpringBootTest
|
|
@SpringBootTest
|
|
public class AdminApplicationTests {
|
|
public class AdminApplicationTests {
|
|
@Resource
|
|
@Resource
|
|
private AuthMapper authMapper;
|
|
private AuthMapper authMapper;
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void ossDelTest() {
|
|
|
|
+ OSS ossClient = new OSSClientBuilder().build("https://oss-cn-shenzhen.aliyuncs.com", "LTAI4GBL3o4YkWnbKYgf2Xia", "dBjAXqbYiEPP6Ukuk2ZsXQeET7FVkK");
|
|
|
|
+
|
|
|
|
+ // 列举文件。如果不设置keyPrefix,则列举存储空间下的所有文件。如果设置keyPrefix,则列举包含指定前缀的文件。
|
|
|
|
+ ObjectListing objectListing = ossClient.listObjects("caimei-oss");
|
|
|
|
+ List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
|
|
|
|
+ for (OSSObjectSummary s : sums) {
|
|
|
|
+ System.out.println("\t" + s.getKey());
|
|
|
|
+ }
|
|
|
|
+// ossClient.deleteObject("caimei-oss", "beta" + "/authFile/" + "a63c46a50d4c43ebaea5adec6cbdc61b.jpg");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 设置URL过期时间为1个小时
|
|
|
|
+ Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000);
|
|
|
|
+ String url = ossClient.generatePresignedUrl("caimei-oss", "beta" + "/authFile/" + "6f0f7adcf6d1491cb4167a3205f6545e.jpg", expiration).toString();
|
|
|
|
+ // 关闭OSSClient。
|
|
|
|
+ ossClient.shutdown();
|
|
|
|
+ System.out.println(url);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
- public void JWTToken(){
|
|
|
|
|
|
+ public void JWTToken() {
|
|
OSSUtils.deleteSingleFile("5dbb6eb668174438ae5f9b5a1d99f7cf.ppt");
|
|
OSSUtils.deleteSingleFile("5dbb6eb668174438ae5f9b5a1d99f7cf.ppt");
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void drawImage() throws IOException {
|
|
|
|
|
|
+ public void drawImage() throws IOException {
|
|
ClassPathResource classPathResource = new ClassPathResource("/images/pcWaterMark.png");
|
|
ClassPathResource classPathResource = new ClassPathResource("/images/pcWaterMark.png");
|
|
InputStream inputStreamImg = classPathResource.getInputStream();
|
|
InputStream inputStreamImg = classPathResource.getInputStream();
|
|
Image pcWaterMarkImg = ImageIO.read(inputStreamImg);
|
|
Image pcWaterMarkImg = ImageIO.read(inputStreamImg);
|