package top.tqx.demo_1;

import top.tqx.demo_1.util.Sha256Util;

import java.util.UUID;

/**
 * 文件上传测试类
 * 展示 tempstring 拼接过程和第三方接口描述
 */
public class FileUploadTest {

    public static void main(String[] args) {
        // 模拟数据
        String xFile = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // 空字符串的 SHA256
        Long userId = 12345L;
        String xTime = "1712937600000"; // 2024-04-12 00:00:00
        String xNonce = "550e8400e29b41d4a716446655440000";
        String xKey = "password123";

        // 拼接 tempString
        String tempString = "file=" + xFile + "&userid=" + userId + "&time=" + xTime + "&nonce=" + xNonce + "&x-key=" + xKey;
        System.out.println("=== tempString 拼接结果 ===");
        System.out.println(tempString);
        System.out.println();

        // 计算签名
        String xSign = Sha256Util.hash(tempString);
        System.out.println("=== xSign 计算结果 ===");
        System.out.println(xSign);
        System.out.println();

        // 第三方接口描述
        System.out.println("=== 第三方接口详细描述 ===");
        System.out.println("接口地址: http://192.168.137.73:8080/totop");
        System.out.println("请求方式: POST");
        System.out.println("Content-Type: multipart/form-data");
        System.out.println("请求参数:");
        System.out.println("  1. file: 文件 (MultipartFile)");
        System.out.println("  2. userId: 上传用户ID (String)");
        System.out.println("  3. x-file: 文件哈希值 (String)");
        System.out.println("  4. x-time: 时间戳 (String)");
        System.out.println("  5. x-nonce: 随机串 (String)");
        System.out.println("  6. x-sign: 签名 (String)");
        System.out.println();
        System.out.println("签名计算规则:");
        System.out.println("  tempString = \"file={x-file}&userid={userId}&time={x-time}&nonce={x-nonce}&x-key={x-key}\"");
        System.out.println("  x-sign = SHA256(tempString)");
        System.out.println();
        System.out.println("返回格式: JSON");
        System.out.println("返回示例:");
        System.out.println("{");
        System.out.println("  \"code\": 200,");
        System.out.println("  \"message\": \"success\",");
        System.out.println("  \"data\": {");
        System.out.println("    \"fileId\": \"12345\",");
        System.out.println("    \"fileName\": \"example.pdf\",");
        System.out.println("    \"status\": \"uploaded\"");
        System.out.println("  }");
        System.out.println("}");
    }
}
