可以先参考阿里云的物流接口
阿里物流接口
看不懂可以看代码 直接复制粘贴就能用 (根据注释下载工具类和包)
public static ApiResult getLogisticsExpress(String oddNumber){
String host = "https://wuliu.market.alicloudapi.com";
String path = "/kdi";
String method = "GET";
// System.out.println("请先替换成自己的AppCode");
String appcode = "94655977740e45829e02e6ed5bb5a012"; // !!!替换填写自己的AppCode 在买家中心查看
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "APPCODE " + appcode); //格式为:Authorization:APPCODE 83359fd73fe11248385f570e3c139xxx
Map<String, String> querys = new HashMap<String, String>();
querys.put("no", oddNumber);// !!! 请求参数 快递单号 75320700137881 780098068058
querys.put("type", "zto");// !!! 请求参数 可填可不填
//JDK 1.8示例代码请在这里下载: http://code.fegine.com/Tools.zip
try {
/**
* 重要提示如下:
* HttpUtils请从
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun /api/gateway/demo/util/HttpUtils.java
* 或者直接下载:
* http://code.fegine.com/HttpUtils.zip
* 下载
*
* 相应的依赖请参照
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
* 相关jar包(非pom)直接下载:
* http://code.fegine.com/aliyun-jar.zip
*/
HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
//如不输出json, 请打开这行代码,打印调试头部状态码。
System.out.println("状态码:"+response.getStatusLine().getStatusCode());
//状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
//获取response的body
if(response.getStatusLine().getStatusCode()==200){
String a = EntityUtils.toString(response.getEntity());
return ApiResult.ok(JSON.parse(a));
}
} catch (Exception e) {
e.printStackTrace();
}
return ApiResult.fail("获取数据失败");
}