package com.ningdatech.pmapi.provincial;

import cn.hutool.crypto.SecureUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @Classname Test
 * @Description
 * @Date 2023/3/2 16:14
 * @Author PoffyZhang
 */
@Slf4j
public class Test {

    @org.junit.Test
    public void test() throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
//        Long timeStamp = System.currentTimeMillis()/1000;
        Long timeStamp = 1677750055L;
        String key = "7196317343a64e67895dc0375c098fe7";
        String url = "/api/v1/foreign/importantProView";
        String methed = "POST";
        String bytesToSign = methed + "\n" + url + "\n" + timeStamp + "\n" + key;

        log.info("" + bytesToSign);

        String secret  = "75152a97f20e4c4c854dc6301cf72ad4";
        String str = SecureUtil.hmacSha256(secret).digestBase64(bytesToSign,false);
        log.info("" + str);
    }
}
