package com.search.supersearch.util;

import cn.hutool.crypto.digest.DigestUtil;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class TestUtil {

    final static String APP_ID = "AK20231008FBTXHK";
    final static String APP_KEY = "7547f868ab124ecf51350d6dc6b1ea76";
    final static String CONTENT_TYPE = "application/json";
    final static String HOST = "https://10.80.1.254:5443/open";

    /**
     * @param args
     */
    public static void main(String[] args) {
        String uri = String.format("/auth/v1/app/inscope/token?app_id=%s&scope=%s", APP_ID, "file_preview");
        String body = null;
        String contentMd5 = DigestUtil.md5Hex(Optional.ofNullable(body).orElse(""));
        String dateStr = ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneId.of("GMT")));
        String xAuth = String.format("WPS-3:%s:%s", APP_ID, DigestUtil.sha1Hex(APP_KEY+contentMd5+uri+CONTENT_TYPE+dateStr));
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-type", CONTENT_TYPE);
        headers.put("X-Auth", xAuth);
        headers.put("Date", dateStr);
        headers.put("Content-Md5", contentMd5);
        System.out.println(headers);
        System.out.println(HOST + uri);
    }

}
