简单物流API接口调用

直接进入正题,我使用的物流API接口是阿里的全国快递物流查询接口。

链接:https://market.aliyun.com/products/57126001/cmapi011120.html?spm=5176.8216963.738024.3.126e67934tEsYf#sku=yuncode512000008

上面会有一些说明文档,可以参考。

下面开始贴代码:

publicstaticvoid main(String[] args) {

String host ="http://jisukdcx.market.alicloudapi.com";

String path ="/express/query";

String method ="GET";

String appcode ="你自己的AppCode";

Map headers =newHashMap();//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105

headers.put("Authorization","APPCODE "+ appcode);

Map querys =newHashMap();

querys.put("number","1202516745301");

querys.put("type","YUNDA");

try{/**

* 重要提示如下:

* HttpUtils请从

* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java

* 下载

* 相应的依赖请参照

* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml

*/

HttpResponse response1 = HttpUtils.doGet(host, path, method, headers, querys); System.out.println(response1.toString()); //获取response的body String json=EntityUtils.toString(response1.getEntity()); //System.out.println(json);

 JSONObject jsonOb=JSONObject.fromObject(json); MapclassMap=new HashMap();

classMap.put("result",Result.class );

classMap.put("list", ListCon.class);

WuLiu wuLiu=(WuLiu) JSONObject.toBean(jsonOb,WuLiu.class,classMap);

System.out.println(wuLiu.getResult().toString());

}catch(Exceptione) {

e.printStackTrace();

}

}

推荐阅读更多精彩内容