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

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.yxcheng.token.utils.*;
import org.junit.Test;

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

public class FileManageTest {
    String accessKeyID = "bwgf-limit";
    static String accessKeySecret = "bw@2u9%5Ts#2";
//        static String host = "http://127.0.0.1:8767";
    static String host = "https://api.taxservices.cn";
//    static String host = "http://60.205.138.54:8767";
    @Test
    public void testHandApplyFile() throws Exception{
        String url = host + "/fileManage/handApplyMonthFile";
        System.out.println(url);
        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);

        Map param = new HashMap<>();
        param.put("accessKeyID",accessKeyID);
        param.put("signatureNonce",signatureNonce);
        param.put("timeStamp",timeStamp);
        param.put("version","1.0");
        param.put("signature", "twotest");
        param.put("taxno","91440116618416948F");

        param.put("forceApplyFlag","1");
        param.put("invSpec","0");

        List<String> monthList = Lists.newArrayList();
        monthList.add("202310");

        for(String month:monthList) {
            param.put("fileMonth",month);
            System.out.println(JSON.toJSONString(param));
            ResponseContent ret = HttpHelper.postJsonEntity(url,JSON.toJSONString(param));
            System.out.println(ret.getContent());
        }

    }

    @Test
    public void queryErrorFileList() throws Exception{
        String url = host + "/invoicefile/queryErrorFileList";
        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);

        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","91510100MA68FEQ27L");
        param.put("fileMonth","202111");

        System.out.println(JSON.toJSONString(param));
        String ret = HttpHelper.postWithJson(url,JSON.toJSONString(param));
        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;
    }
}
