lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.rongyichuang.cos;
 
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
 
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
 
@SpringBootTest
public class CosUploadTest {
 
    @Test
    public void testTimeCalculation() {
        long currentTimeMillis = System.currentTimeMillis();
        Date currentDate = new Date();
        Date futureDate = new Date(currentTimeMillis + 15 * 60 * 1000);
        
        System.out.println("当前系统时间戳: " + currentTimeMillis);
        System.out.println("当前时间: " + currentDate);
        System.out.println("15分钟后: " + futureDate);
        System.out.println("当前时间Unix秒: " + (currentTimeMillis / 1000));
        System.out.println("15分钟后Unix秒: " + ((currentTimeMillis + 15 * 60 * 1000) / 1000));
        
        LocalDateTime now = LocalDateTime.now();
        System.out.println("LocalDateTime现在: " + now);
        
        Instant instant = Instant.now();
        System.out.println("Instant现在: " + instant);
        System.out.println("Instant Unix秒: " + instant.getEpochSecond());
    }
    
    @Test
    public void testCosUrlGeneration() {
        // 模拟COS URL生成
        String bucket = "ryc-1256886520";
        String region = "ap-chengdu";
        String key = "test/logo.jpg";
        
        long currentTime = System.currentTimeMillis() / 1000; // Unix秒
        long expireTime = currentTime + 15 * 60; // 15分钟后
        
        System.out.println("当前Unix时间: " + currentTime);
        System.out.println("过期Unix时间: " + expireTime);
        
        String baseUrl = String.format("https://%s.cos.%s.myqcloud.com/%s", bucket, region, key);
        System.out.println("基础URL: " + baseUrl);
    }
}