StampRequest.java 2.7 KB
package com.erry.iclear.dateInterface;

import com.arronlong.httpclientutil.HttpClientUtil;
import com.arronlong.httpclientutil.builder.HCB;
import com.arronlong.httpclientutil.common.HttpConfig;
import com.arronlong.httpclientutil.common.HttpHeader;
import com.arronlong.httpclientutil.common.SSLs;
import com.erry.iclear.dateInterface.api.response.IClearCheckResult;
import com.erry.iclear.dateInterface.api.response.StampResult;
import com.erry.iclear.dateInterface.util.FileUtils;
import com.erry.iclear.dateInterface.util.JsonToJava;
import com.erry.iclear.dateInterface.util.SHA256Util;
import org.apache.http.Header;

/**
 *  获取HSCODE接口地址
 *  fedex
 *  2022年4月14日17:55:55
 */
public class StampRequest {
    public static String url = "https://localhost:8780";
    //获取HSCODE接口地址
    public static String path = "/iknowU/stampQuery";
    //时间戳
    public static String timeStamp = "1649839249891";
    //APPID
    public static String appId = "DEMO1";
    //APPKEY
    public static String appKey = "iClearExportDemo1";
    //需要申请
    public static String security = "8c7f1108316abfb1";

    public static void main(String[] args) throws Exception{
        hscodeRequest();
    }

    /**
     * 获取HSCODE接口地址
     */
    public static void hscodeRequest() throws Exception{
        //hscode 编码可修改
        String json ="{\"consignmentCode\":\"aaaaaaaa\"}";

        String token = SHA256Util.getSHA256String(StampRequest.appId + StampRequest.appKey + StampRequest.security + StampRequest.timeStamp);
        System.out.println(token);
        //消息头
        Header[] headers = HttpHeader.custom()
                .other("Content-Type", "application/json")
                .other("Appid", StampRequest.appId)
                .other("appKey", StampRequest.appKey)
                .other("TimeStamp", StampRequest.timeStamp)
                .other("token", token)
                .build();
        //客户端配置
        HCB hcb = HCB.custom()
                .timeout(20000)
                .pool(100, 10)
                .sslpv(SSLs.SSLProtocolVersion.TLSv1_2)
                .ssl()
                .retry(3);
        //URL
        String url = StampRequest.url + StampRequest.path;
        //HTTP请求
        HttpConfig config = HttpConfig.custom()
                .headers(headers)
                .url(url)
                .encoding("utf-8")
                .client(hcb.build())
                .json(json);
        String result = HttpClientUtil.post(config);
        StampResult stampResult = JsonToJava.parseJson(result, StampResult.class);
        FileUtils.convertBase64ToFile(stampResult.getBase64Image(),"C:\\Users\\erry-Fedex\\Desktop\\电子章","bbbbbbb.png");
    }
}