Express bill No. query interface – Shentong express

Time:2020-5-28

Today, let’s talk about how to use the interface provided by express bird to query the logistics track of Shentong express.

Before the explanation, let’s take a look at the actual display effect after the interface is completed

The following is the Shentong logistics track information obtained by calling the express bird interface. The interface effect displayed needs to be developed by myself:
Express bill No. query interface - Shentong express
Now let’s talk about the implementation!

First of all, we are ready to use the resources,

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 will take C development as an example to explain,

1. Complete the preparatory work

1.1 go to express bird website to register an account for free

1.2. Obtain an apikey for free (required for interface permission verification)( http://kdniao.com/UserCenter/…

1.3 complete the real name certification process( http://kdniao.com/UserCenter/…

1.4, order a free package

Next, let’s talk about the request parameters

Request system level parameter description:

Express bill No. query interface - Shentong express
remarks:R-required, o-optional, c-optional under certain conditions

System level parameters are mentioned here, which are also common parameters. These parameters must be passed when every interface is called.

Interface parameters:
Express bill No. query interface - Shentong express

The interface parameters, also called business parameters, vary with the requested business interface and the fields and contents of the parameters. They vary with the business. Here we implement the real-time query interface. The request instruction type is 1002. The express company code and logistics number must be delivered to the official website of express bird. The code of Yuantong Express is yto

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

http://www.kdniao.com/documents

As shown in the screenshot above, the code of Shentong express is STO, and the logistics order number is 777007389359024

The service parameter message combination is as follows:

{‘OrderCode’:”,’ShipperCode’:’STO’,’LogisticCode’:’777007389359024′}

Complete message requested (after URL encoding):

RequestData=%0d%0a++++++++++++%7b%27OrderCode%27%3a%27%27%2c%27ShipperCode%27%3a%27STO%27%2c%27LogisticCode%27%3a%27777007389359024%27%7d%0d%0a++++++++&EBusinessID=1617571&RequestType=1002&DataSign=N2I4ZGEzYjkwMzhkZWY0YmM5ZGYxOGNkYjU5MmI2ZTU%3d&DataType=2

Uncoded request message:

`RequestData=
{‘OrderCode’:”,’ShipperCode’:’STO’,’LogisticCode’:’777007389359024′}&EBusinessID=1617571&RequestType=1002&DataSign=N2I4ZGEzYjkwMzhkZWY0YmM5ZGYxOGNkYjU5MmI2ZTU=&DataType=2
`
Message information returned:

`{

"LogisticCode": "777007389359024",
"ShipperCode": "STO",
"Traces": [
    {
        "Acceptstation": "your baby will be escorted by Shentong express (37 marketing departments of Jiangsu Province) in the whole process, and the carrier (Hongfeng Road). Due to the impact of epidemic prevention and control and traffic control, your express timeliness may be affected. We hope to get your understanding. For details, please consult the local network ",
        "AcceptTime": "2020-01-08 19:45:01"
    },
    {
        "Acceptstation": "the express has been scanned by [Jiangsu Sheyang company] and sent to [Jiangsu Yancheng transfer department], scanner [sun Xia]. Due to the impact of epidemic prevention and control and traffic control, your express timeliness may be affected. Please wait patiently, thank you for your understanding. ",
        "AcceptTime": "2020-01-09 15:28:36"
    },
    {
        "Acceptstation": "the express has been scanned by [Jiangsu Sheyang company] and sent to [Jiangsu Yancheng transfer department], scanner [Sheyang]. Due to the impact of epidemic prevention and control and traffic control, your express timeliness may be affected. Please wait patiently, thank you for your understanding. ",
        "AcceptTime": "2020-01-09 17:59:53"
    },
    {
        "Acceptstation": "arrived - Jiangsu Yancheng transfer department",
        "AcceptTime": "2020-01-09 19:57:22"
    },
    {
        "Acceptstation": "the express has been scanned by [Jiangsu Yancheng transfer department] and sent to [Jiangsu Jiangyin aviation department], scanner [Chen Jianqun]. Due to the impact of epidemic prevention and control and traffic control, your express timeliness may be affected. Please wait patiently, thank you for your understanding. ",
        "AcceptTime": "2020-01-09 20:16:29"
    },
    {
        "Acceptstation": "arrived - Jiangsu Jiangyin aviation department",
        "AcceptTime": "2020-01-10 02:28:24"
    },
    {
        "Acceptstation": "the express has been scanned by Jiangsu Jiangyin aviation department and sent to Guangdong Shenzhen transfer center by scanner [Zhang Huachen]. Due to the impact of epidemic prevention and control and traffic control, your express timeliness may be affected. Please wait patiently, thank you for your understanding. ",
        "AcceptTime": "2020-01-10 02:30:14"
    },
    {
        "Acceptstation": "arrived - Guangdong Shenzhen transfer center",
        "AcceptTime": "2020-01-11 00:48:28"
    },
    {
        "Acceptstation": "the express has been scanned by [Guangdong Shenzhen transfer center] and sent to [Guangdong Luohu Longhua Henglin branch], scanner [Shenzhen port entry automation center]. Due to the impact of epidemic prevention and control and traffic control, your express timeliness may be affected. Please wait patiently, thank you for your understanding. ",
        "AcceptTime": "2020-01-11 00:48:31"
    },
    {
        "Acceptstation": "the express has been scanned by [Guangdong Shenzhen transfer center] and sent to [Guangdong Luohu Longhua Henglin branch], scanner [Shenzhen port entry automation center]. Due to the impact of epidemic prevention and control and traffic control, your express timeliness may be affected. Please wait patiently, thank you for your understanding. ",
        "AcceptTime": "2020-01-11 00:49:01"
    },
    {
        "Acceptstation": "arrived - Longhua Henglin branch, Luohu, Guangdong",
        "AcceptTime": "2020-01-11 08:06:34"
    },
    {
        "Acceptstation": "arrived - Longhua Henglin branch, Luohu, Guangdong",
        "AcceptTime": "2020-01-11 10:33:36"
    },
    {
        "Acceptstation": "the epidemic is merciless, people have feelings, and brother Shentong has been sticking to it. Your express will be delivered by the dispatcher (Wang Zhongming) of (Longhua Henglin branch, Luohu, Guangdong). In order to ensure the safety of customers' delivery and reduce the direct contact of personnel, we suggest that you do a good job of safety protection when taking out the pieces. ",
        "AcceptTime": "2020-01-11 11:18:36"
    },
    {
        "Acceptstation": "the express delivery has been collected by Fengchao express cabinet at the gate of unit 1, basement 1, unit 1, building 2, zone a, Xinmao garden, Longhua District, Shenzhen city. Please pick up the delivery in time. If you have any questions, please contact 13925214311 ",
        "AcceptTime": "2020-01-11 12:55:57"
    },
    {
        "Acceptstation": "has been signed in, and the recipient shall take the customer's SMS to sign in",
        "AcceptTime": "2020-01-11 22:18:09"
    }
],
"State": "3",
"EBusinessID": "1617571",
"Success": true

}`

C ා key code:
`/// <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 the web page

    /// </summary>

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

///< param name = “param” > parameter set requested < / 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 method < / 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 method < / param >

    /// <returns></returns>

    private string base64(String str, String charset)

    {

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

    }`

Recommended Today

Statistics In PostgreSQL

This article is similar to the source reading of an article, a preliminary introduction to the PostgreSQL statistical information module. The reason why we choose PostgreSQL instead of other databases is that PostgreSQL always performs well in various papers when we see some comparison of design estimation. Statistics collected in PG In PostgreSQL, the collected […]