package cn.ezhizao.project.business.company.util;

import cn.ezhizao.common.constant.Constants;
import cn.ezhizao.common.utils.http.HttpUtils;
import org.apache.commons.codec.digest.DigestUtils;

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


public class QiChaChaRequest {
    private static final String appkey = "appkey";
    private static final String secretKey = "secretKey";

    public static String getCompanyInfo(String companyName) {
        String path = "https://api.qichacha.com/ECIInfoVerify/Get";
        String paramStr = "keyword="+companyName;
        String status = "";
        Map<String, String> headers = new HashMap<String, String>();
        String[] autherHeader = RandomAuthentHeader();
//        reqHeader.setHeader("Token", autherHeader[0]);
//        reqHeader.setHeader("Timespan", autherHeader[1]);
        headers.put("Token", autherHeader[0]);
        headers.put("Timespan", autherHeader[1]);
        return HttpUtils.sendGet(path, paramStr, Constants.UTF8, headers);
    }

    // 获取Auth Code
    protected static final String[] RandomAuthentHeader() {
        String timeSpan = String.valueOf(System.currentTimeMillis() / 1000);
        return new String[] { DigestUtils.md5Hex(appkey.concat(timeSpan).concat(secretKey)).toUpperCase(), timeSpan };
    }
}
