Chinacom Express Track query interface

Time:2020-9-20

How to use the interface provided by express bird to query the logistics track of Zhongtong express.

Let’s take a look at the actual effect after the interface is completed

The following is the track information of Zhongtong logistics obtained by calling the express bird interface, and the display interface effect needs to be developed by ourselves:
Chinacom Express Track query interface

Now let’s do it!

First, prepare the resources you need,

Test merchant ID:

test1617571

Test API key:

554343b2-7252-439b-b4eb-1af42c8f2175 (this key is only used in test environment)

API test address:

http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json

I take C ා development as an example to explain the query interface of China Express

Next, let’s talk about request parameters

Description of request system level parameters:
Chinacom Express Track query interface
remarks:R-required, o-optional, and the parameter in c-message is optional under certain conditions

The system level parameters mentioned here are equivalent to public parameters. These parameters must be passed to each interface when calling.

Interface parameters:
Chinacom Express Track query interface

Interface parameters, also known as business parameters, request business interfaces are different, parameter fields, content is also different, is with the business change, here we implement the instant query interface, request instruction type: 1002, express bird official website requires that express company code and logistics order number must be passed, Zhongtong express code is ZTO

To view the codes of other express companies, click this link:

http://www.kdniao.com/documents

As the trajectory screenshot in front of me, it is the track data of Zhongtong. The code of Zhongtong express is ZTO, and the logistics order number is 78120038107849

The service parameter message combination is as follows:

{‘OrderCode’:”,’ShipperCode’:’ZTO’,’LogisticCode’:’78120038107849′}

Complete message of request:

RequestData=%7b%27OrderCode%27%3a%27%27%2c%27ShipperCode%27%3a%27ZTO%27%2c%27LogisticCode%27%3a%2778120038107849%27%7d&EBusinessID=1617571&RequestType=1002&DataSign=YzBmYTViYmExZmFhOGY1ZTY3MWY5OGFjYWRhNWVjNjU%3d&DataType=2

Message information returned:

`{

"LogisticCode": "78120038107849",
"ShipperCode": "ZTO",
"Traces": [
    {
        "Acceptstation": "Zhang Xia (18839032214) of Jiyuan City [Jiyuan] (0391-6965909) has taken over the project",
        "AcceptTime": "2020-01-16 18:30:33"
    },
    {
        "Acceptstation": "[Jiyuan City] express left [Jiyuan] has been sent to [Shenzhen Center]",
        "AcceptTime": "2020-01-16 18:36:41"
    },
    {
        "Acceptstation": "[Xinxiang City] Express has arrived at [Xinxiang transit]",
        "AcceptTime": "2020-01-16 22:45:49"
    },
    {
        "Acceptstation": "[Xinxiang City] express left [Xinxiang transit] has been sent to [Shenzhen Center]",
        "AcceptTime": "2020-01-16 22:47:48"
    },
    {
        "Acceptstation": "[Shenzhen City] Express has arrived at [Shenzhen Center]",
        "AcceptTime": "2020-01-18 04:05:46"
    },
    {
        "Acceptstation": "[Shenzhen City] Express has left [Shenzhen Center] and sent to [Shenzhen Longhua]",
        "AcceptTime": "2020-01-18 08:34:46"
    },
    {
        "Acceptstation": "[Shenzhen City] Express has arrived at [Shenzhen Longhua]",
        "AcceptTime": "2020-01-18 13:14:10"
    },
    {
        "Acceptstation": "Chen Zhilong Wang Ying (13923773902) of Shenzhen Longhua is sending the first delivery. Please keep the phone unblocked and wait patiently (95720 is the exclusive number of China Telecom express, please feel free to answer)",
        "AcceptTime": "2020-01-18 16:38:35"
    },
    {
        "Acceptstation": "[Shenzhen] Express has been signed and received by [Fengchao Xinmao garden area a (Fengchao intelligent express cabinet)]. If you have any questions, please call (13923773902 / 40006333318025858922), thank you for using China express and look forward to serving you again!",
        "AcceptTime": "2020-01-18 17:32:15"
    }
],
"State": "3",
"EBusinessID": "1617571",
"Success": true

}`

C ා key code:

`  string requestData = “{‘OrderCode’:”,’ShipperCode’:’ZTO’,’LogisticCode’:’78120038107849′}”;

  string dataSign = encrypt(requestData, “554343b2-7252-439b-b4eb-1af42c8f2175”, “UTF-8”);

/// <summary>

///Real time query of logistics track

    /// </summary>

    /// <param name=”url”>http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json</param>

    /// <param name=”eBusinessID”>test1617571</param>

    /// <param name=”appKey”>554343b2-7252-439b-b4eb-1af42c8f2175</param>

    /// <param name=”requestData”>{‘OrderCode’:”,’ShipperCode’:’ZTO’,’LogisticCode’:’78120038107849′}</param>

    /// <returns></returns>

    public string getOrderTracesByJson(string url,string eBusinessID, string appKey, string requestData)

    {

        Dictionary<string, string> param = new Dictionary<string, string>();

        param.Add(“RequestData”, HttpUtility.UrlEncode(requestData, Encoding.UTF8));

        param.Add(“EBusinessID”, eBusinessID);

        param.Add(“RequestType”, “1002”);

        string dataSign = encrypt(requestData, appKey, “UTF-8”);

        param.Add(“DataSign”, HttpUtility.UrlEncode(dataSign, Encoding.UTF8));

        param.Add(“DataType”, “2”);

        string result = sendPost(url, param);

        return result;

    }

    /// <summary>

///Submit data in post mode and return the source code of web page

    /// </summary>

///< param name = “URL” > the URL to send the request < / param >

///< param name = “param” > requested parameter set < / param >

///< returns > response results of remote resources < / returns >

    private string sendPost(string url, Dictionary<string, string> param)

    {

        string result = “”;

        StringBuilder postData = new StringBuilder();

        if (param != null && param.Count > 0)

        {

            foreach (var p in param)

            {

                if (postData.Length > 0)

                {

                    postData.Append(“&”);

                }

                postData.Append(p.Key);

                postData.Append(“=”);

                postData.Append(p.Value);

            }

        }

       // return postData.ToString();

        byte[] byteData = Encoding.GetEncoding(“UTF-8”).GetBytes(postData.ToString());

        try

        {

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.ContentType = “application/x-www-form-urlencoded”;

            request.Referer = url;

            request.Accept = “*/*”;

            request.Timeout = 30 * 1000;

            request.UserAgent = “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)”;

            request.Method = “POST”;

            request.ContentLength = byteData.Length;

            Stream stream = request.GetRequestStream();

            stream.Write(byteData, 0, byteData.Length);

            stream.Flush();

            stream.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream backStream = response.GetResponseStream();

            StreamReader sr = new StreamReader(backStream, Encoding.GetEncoding(“UTF-8”));

            result = sr.ReadToEnd();

            sr.Close();

            backStream.Close();

            response.Close();

            request.Abort();

        }

        catch (Exception ex)

        {

            result = ex.Message;

        }

        return result;

    }

///<summary>

///Signature of e-commerce sign

    ///</summary>

///< param name = “content” > content < / param >

    ///<param name=”keyValue”>Appkey</param>

///< param name = “charset” > URL encoding < / param >

///< returns > datasign signature < / returns >

    private string encrypt(String content, String keyValue, String charset)

    {

        if (keyValue != null)

        {

            return base64(MD5(content + keyValue, charset), charset);

        }

        return base64(MD5(content, charset), charset);

    }

    ///<summary>

///String MD5 encryption

    ///</summary>

///< param name = “STR” > string to encrypt < / param >

///< param name = “charset” > encoding mode < / param >

///< returns > ciphertext < / returns >

    private string MD5(string str, string charset)

    {

        byte[] buffer = System.Text.Encoding.GetEncoding(charset).GetBytes(str);

        try

        {

            System.Security.Cryptography.MD5CryptoServiceProvider check;

            check = new System.Security.Cryptography.MD5CryptoServiceProvider();

            byte[] somme = check.ComputeHash(buffer);

            string ret = “”;

            foreach (byte a in somme)

            {

                if (a < 16)

                    ret += “0” + a.ToString(“X”);

                else

                    ret += a.ToString(“X”);

            }

            return ret.ToLower();

        }

        catch

        {

            throw;

        }

    }

   /// <summary>

///Base64 encoding

    /// </summary>

///< param name = “STR” > content < / param >

///< param name = “charset” > encoding mode < / param >

    /// <returns></returns>

    private string base64(String str, String charset)

    {

        return Convert.ToBase64String(System.Text.Encoding.GetEncoding(charset).GetBytes(str));

    }

`

The detailed interface document is attached to you:

http://www.kdniao.com/documents

Recommended Today

DK7 switch’s support for string

Before JDK7, switch can only support byte, short, char, int or their corresponding encapsulation classes and enum types. After JDK7, switch supports string type. In the switch statement, the value of the expression cannot be null, otherwise NullPointerException will be thrown at runtime. Null cannot be used in the case clause, otherwise compilation errors will […]