全国快递物流查询API:将1500+家快递公司的数据接口统一化、标准化
本文介绍了一个快递物流查询API,提供两个子接口:快递物流查询和快递公司列表获取。重点演示了如何使用C#调用快递物流查询接口,通过输入运单号自动识别快递公司并返回物流信息。代码示例展示了接口调用过程,包括URL构造、请求头和响应处理。接口返回数据包含快递公司信息、物流状态、全程耗时、快递员联系方式以及按时间倒序排列的详细物流轨迹。该API支持自动识别快递公司,简化了物流查询流程。
·
一、两个子接口,覆盖全场景
该API提供了两个子接口,满足不同业务需求:
| 接口 | 路径 | 功能 |
|---|---|---|
| 快递物流查询 | /exp/index |
输入运单号,自动识别快递公司,返回最新物流轨迹 |
| 获取快递公司列表 | /exp/com |
获取所有支持的快递公司编码及名称 |
本文以第一个接口——快递物流查询为例,演示如何查询单号78792812069699的物流信息。
实战演示:查询运单号 78792812069699 的物流信息
下面通过 C# 代码调用该接口
接口地址:https://market.aliyun.com/detail/cmapi00065859
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Security.Cryptography.X509Certificates;
public class ExpressQueryTest
{
private const string host = "https://market.aliyun.com/detail/cmapi00065859"#接口地址;
private const string path = "/exp/index";
private const string method = "GET";
private const string appcode = "你自己的AppCode"; // 替换为真实 AppCode
public static void Main(string[] args)
{
string querys = "no=78792812069699"; // 只需传入单号,可自动识别公司
string url = host + path;
if (!string.IsNullOrEmpty(querys))
{
url = url + "?" + querys;
}
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
if (host.Contains("https://"))
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = method;
httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
}
catch (WebException ex)
{
httpResponse = (HttpWebResponse)ex.Response;
}
Console.WriteLine(httpResponse.StatusCode);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
string result = reader.ReadToEnd();
Console.WriteLine(result);
}
public static bool CheckValidationResult(object sender, X509Certificate certificate,
X509Chain chain, SslPolicyErrors errors)
{
return true;
}
}
三、返回字段解析
| 字段 | 说明 |
|---|---|
company |
快递公司中文名称 |
com |
快递公司编码(如zto) |
no |
运单号 |
com_phone |
快递公司客服电话 |
com_url |
快递公司官网 |
take_time |
物流全程耗时 |
courier_phone |
快递员电话 |
status_desc |
签收状态文案(如“已签收”) |
status_detail |
状态节点码:1揽件,2运输中,3派送中,4已签收,5包裹异常/签收失败,10退回 |
list |
物流轨迹数组,按时间倒序排列 |
list[].datetime |
节点时间 |
list[].remark |
节点详细描述(含地点、动作、联系方式等) |
更多推荐

所有评论(0)