一、两个子接口,覆盖全场景

该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 节点详细描述(含地点、动作、联系方式等)
Logo

电商企业物流数字化转型必备!快递鸟 API 接口,72 小时快速完成物流系统集成。全流程实战1V1指导,营造开放的API技术生态圈。

更多推荐