查询物流信息
简介:
/****
* @Description:查询快递的物流信息
* @author: SX
* @param number 快递单号 必须
* @param mobile 收件人手机号 顺丰需要手机号码
* @return
*/
根据前端输入的订单号和物流公司查询相对于的物流信息
第三方Api接口地址
==购买后会生成appcode :在阿里云的云市场已经开启的购买的云服务下可以看到商品的appcode,替换原有代码中的appcode==
maven依赖
<!--快递接口-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.15</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.3.7.v20160115</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
请求url:
cli/shop/shop_logistics
请求方式
post
params
请求参数示例
http://localhost:8081/cli/shop/shop_logistics?number=75462079016926&type=zto
Java代码
- 工具类
/**
* @author SX
* @version 1.0
* @date 2021/5/10 17:40
*/
public class HttpUtils {
/**
* get
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @return
* @throws Exception
*/
public static HttpResponse doGet(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpGet request = new HttpGet(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return httpClient.execute(request);
}
}
- 快递物流查询接口Controller层代码.
/**
* @author SX
* @version 1.0
* @date 2021/5/10 17:29
* 快递接口Api
*/
@RestController
public class ExpressDeliveryController {
/****
* @Description:查询快递的物流信息
* @author: SX
* @param number 快递单号 必须
* @param mobile 收件人手机号 顺丰需要手机号码
* @return
*/
@PostMapping("/cli/shop/shop_logistics")
public String Querywuliu(String number, String mobile) {
String host = "https://jisukdcx.market.alicloudapi.com";
String path = "/express/query";
String method = "ANY";
//---------购买套餐后给的的AppCode-------
String appcode = "##################";
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
//根据API的要求,定义相对应的Content-Type
headers.put("Content-Type", "application/json; charset=UTF-8");
Map<String, String> querys = new HashMap<String, String>();
querys.put("number", number);
//自动识别快递公司
querys.put("type", "auto");
querys.put("mobile", mobile);
try {
HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
String s = EntityUtils.toString(response.getEntity(), "utf-8");
return s;
} catch (Exception e) {
e.printStackTrace();
}
return "查询物流失败";
}
}
请求参数说明
参数 | 是否必须 | 擦参数说明 |
---|---|---|
number | 是 | 快递单号 |
mobile | 否 | 收件人手机号(顺丰快递必须要收件人手机号) |
返回参数示例
{
"status": 0,
"msg": "ok",
"result": {
"number": "4303200322000",
"type": "yunda",
"typename": "韵达快运",
"logo": "https://api.jisuapi.com/express/static/images/logo/80/yunda.png",
"list": [
{
"time": "2019-12-30 20:24:51",
"status": "北京分拨中心进行装车扫描,发往:辽宁大连分拨中心"
},
{
"time": "2019-12-30 01:18:48",
"status": "北京分拨中心进行中转集包扫描,发往:辽宁大连分拨中心"
},
{
"time": "2019-12-30 01:09:00",
"status": "北京分拨中心在分拨中心进行称重扫描"
},
{
"time": "2019-12-29 20:34:28",
"status": "北京石景山区金顶街公司进行揽件扫描"
}
],
"deliverystatus": 3,
"issign": 1
}
}
返回参数说明
参数 | 类型 | 描述 |
---|---|---|
status | number | 状态 |
msg | string | 信息 |
result | object | 结果集合 |
number | string | 电话号码 |
type | string | 快递公司(英文) |
typename | string | 快递公司名称 |
logo | string | logo图片 |
list | object | 物流信息集合 |
time | string | 物流时间 |
status | string | 快递状态 |
deliverystatus | number | 物流状态(1在途中,2派件中,3已签收,4派送失败(拒签等)) |
issign | number | 是否签收 |
总结 :
查看官方文档对入参和返回结果进行分析.
评论