package com.yxcheng.file.web.controller.test;

import com.alibaba.fastjson.JSON;
import com.yxcheng.token.utils.*;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class FileTest {
    String accessKeyID = "bwgf-limit";
    static String accessKeySecret = "bw@2u9%5Ts#2";
   // static String host = "http://47.94.208.133:8765";
    static String host = "http://bwtoken.invservice.cn:7779";


    @Test
    public void testGetTaxInfo() throws Exception{
        String url = host + "/invoicefile/getTaxInfo";
        String signStr = "AccessKeyID=%s&SignatureNonce=%s&TimeStamp=%s&Version=1.0";

        String signatureNonce = UUIDGenerator.generate();
        long time = System.currentTimeMillis();

        String timeStamp = DateUtils.formatDate(time,DateUtils.yyyymmddthhmmssz);

        signStr = String.format(signStr,accessKeyID,signatureNonce, timeStamp);

        //url += "&taxno=9111010856577744XT&dqdm=3700";
        Map param = new HashMap<>();
        param.put("AccessKeyID",accessKeyID);
        param.put("SignatureNonce",signatureNonce);
        param.put("TimeStamp",timeStamp);
        param.put("Version","1.0");
        param.put("Signature",getSign(signStr));
        param.put("taxno","91120110MA05KEUD6Q");
        System.out.println(url);
        String ret = HttpHelper.postWithJson(url,JSON.toJSONString(param));
//        ResponseContent ret = HttpHelper.getUrlRespContent(url);
        System.out.println(ret);
    }



    public static String getSign(String data){
        try {
            return Security.getSignature(data.getBytes("UTF-8"),accessKeySecret.getBytes("UTF-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
