package cn.sikey.mcdisk.util;

import java.util.Base64;
import java.util.Random;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author: qin
 * @Date: 2025/6/26
 * @Description: base64
 */
public class Base64GeneratorUtil {
    public static String generate(String appId) {
        // 生成时间戳 yyyyMMddHHmmssSSS
        String timestamp = LocalDateTime.now()
                .format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));

        // 生成3位随机数
        Random random = new Random();
        int randomNum = random.nextInt(900) + 100; // 100-999

        // 拼接字符串：appid_时间戳+随机数
        String originalStr = appId + "_" + timestamp + randomNum;

        // Base64编码
        return Base64.getEncoder()
                .encodeToString(originalStr.getBytes());
    }
}
