All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.xiaoyuge5201.other.LogisticsUtil Maven / Gradle / Ivy

There is a newer version: 1.3.5
Show newest version
package com.github.xiaoyuge5201.other;

import com.github.xiaoyuge5201.http.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;

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

/**
 * 物流测试
 * 阿里云物流:免费使用100条
 *
 * @author 小余哥
 */
public class LogisticsUtil {
    private static Logger log = LoggerFactory.getLogger(LogisticsUtil.class);

    public static void main(String[] args) {
        String host = "https://wuliu.market.alicloudapi.com";
        String path = "/kdi";
        String method = "GET";
        String appcode = "1c1afdc7830546f1bd9c973a4247eb0f";
        Map headers = new HashMap(16);
        //格式为:Authorization:APPCODE 83359fd73fe11248385f570e3c139xxx
        headers.put("Authorization", "APPCODE " + appcode);
        Map querys = new HashMap(16);
        querys.put("no", "811947472893");
        querys.put("type", "SFEXPRESS");
        //JDK 1.8示例代码请在这里下载:  http://code.fegine.com/Tools.zip
        try {
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //log.info(response.toString());如不输出json, 请打开这行代码,打印调试头部状态码。
            //状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
            //获取response的body
            log.info(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            log.error("信息:" + e.toString(), e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy