Polar rabbit Express – Express bill No. query API docking version C

Time:2020-4-27

Provide source code, copy to your project, you can quickly complete the express bird’s polar rabbit Express query API interface.

The following details the implementation process

1. Complete the preparatory work

1.1 express bird account

1.2. Apikey (required for interface permission verification)

1.3 complete real name certification

2. API interface

2.1, test call address: http://sandboxapi.kdniao.com: 8080 / kdniaosandbox / gateway / extrafaceinvoke.json_

2.2, official call address: “http://api.kdniao.com/api/dist”_

2.3. Request mode: “post”_

2.4, UTF-8: _application / x-www-form-urlencoded; charset = UTF-8_

2.5, return type: _json_

3. Request parameters (headers)

RequestData=%7b%27OrderCode%27%3a%27%27%2c%27ShipperCode%27%3a%27JTSD%27%2c%27LogisticCode%27%3a%27jt0000052600488%27%7d&EBusinessID=1264783
&RequestType=1002&DataSign=MTYyMDU4NWQ2NmU1ZDI2MDEzNGE5YmV
lM2YxYzEzMTM%3d&DataType=2

4. Successful return message (example)

{
    "LogisticCode": "JT0000052600488",
    "ShipperCode": "JTSD",
    "Traces": [
        {
            "Acceptstation": "Deng Yongjun of [Wuhu City] [Wuhu Jinghu branch] has taken 17855364213 pieces",
            "AcceptTime": "2020-03-16 16:26:13"
        },
        {
            "Acceptstation": "Deng Yongjun of [Wuhu City] [Wuhu Jinghu branch] has taken 17855364213 pieces",
            "AcceptTime": "2020-03-16 16:41:33"
        },
        {
            "Acceptstation": "[Wuhu City] [Wuhu Jinghu branch] received",
            "AcceptTime": "2020-03-16 17:39:21"
        },
        {
            "Acceptstation": "[Wuhu City] express left [Wuhu Jinghu branch] and sent to [Wuhu transfer center]",
            "AcceptTime": "2020-03-16 17:40:27"
        },
        {
            "Acceptstation": "[Wuhu City] express to [Wuhu transfer center]",
            "AcceptTime": "2020-03-16 19:36:32"
        },
        {
            "Acceptstation": "[Wuhu City] Express has left [Wuhu transfer center] and sent to [Hefei transfer center]",
            "AcceptTime": "2020-03-16 20:47:03"
        },
        {
            "Acceptstation": "[Hefei city] express to [Hefei transfer center]",
            "AcceptTime": "2020-03-16 23:40:10"
        },
        {
            "Acceptstation": "[Hefei city] Express has left [Hefei transfer center] and sent to [Guangzhou Huadu transfer center]",
            "AcceptTime": "2020-03-17 00:10:48"
        },
        {
            "Acceptstation": "[Guangzhou City] express to [Guangzhou Huadu transfer center]",
            "AcceptTime": "2020-03-17 20:45:00"
        },
        {
            "Acceptstation": "[Guangzhou City] express leaving [Guangzhou Huadu transfer center] has sent to [Shenzhen Bao'an transfer center]",
            "AcceptTime": "2020-03-18 00:17:55"
        },
        {
            "Acceptstation": "[Shenzhen City] express to [Shenzhen Bao'an transfer center]",
            "AcceptTime": "2020-03-18 03:00:17"
        },
        {
            "Acceptstation": "[Shenzhen City] Express has left [Shenzhen Bao'an transfer center] and sent to [Shenzhen Futian branch]",
            "AcceptTime": "2020-03-18 04:44:39"
        },
        {
            "Acceptstation": "Zou Junlin of [Shenzhen City] [Shenzhen Futian branch] is sending a document in 17679495647",
            "AcceptTime": "2020-03-18 08:10:09"
        },
        {
            "Acceptstation": "Zhao Kai 15919817730 of [Shenzhen City], [Shenzhen Futian branch] is sending a document",
            "AcceptTime": "2020-03-18 09:55:19"
        },
        {
            "Acceptstation": "[Shenzhen City] Express has been signed by [collection agent], if you have any questions, please contact: 15919817730, looking forward to serving you again",
            "AcceptTime": "2020-03-18 14:53:54"
        }
    ],
    "State": "3",
    "EBusinessID": "1264783",
    "Success": true}

4. Step by step explanation (version C)

4.1 request packet structure
Polar rabbit Express - Express bill No. query API docking version C

4.2, C call code example

//E-commerce ID
string eEBusinessID = "test1617571";
 //E-commerce encrypts private key, which is provided by express bird. Please take care of it and don't disclose it
string appKey= "554343b2-7252-439b-b4eb-1af42c8f2175";
 //Request URL
string reqURL = "http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json";
//Request instruction 
string reqType="1002";
//2-json 
string dataType = "2"; 
//UTF-8 for character encoding 
string charset = "UTF-8"; 
//JSON string 
string jsonStr = 
"{\"OrderCode\":\"\",\"ShipperCode\":\"JTSD\",\"LogisticCode\":\"JT0000052600488\"}" ;
//MD5 encryption of (jsonstr + apikey)
string md5Str=MD5(jsonStr + apiKey, charset);
//Base 64 coding md5str
string base64Str=base64(md5Str,charset);
//URL encoding (UTF-8)
string datasign = HttpUtility.UrlEncode(base64Str, charset); 
//Request message parameters 
string postStr = "RequestType=reqType&EBusinessID= eEBusinessID&RequestData=jsonStr 
&DataSign= datasign&DataType=dataType"; 
//Communication protocol uses HTTP protocol post request mode to return track data
string post = SendPost(reqURL, postStr);
//The post data obtained is the complete message returned by the express bird. Next, write a method to parse JSON to get the field information.

4.3, C ා call method

///<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));}
 /// <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 = "postData" > request message parameters < / param >
    ///< returns > response results of remote resources < / returns >
    private string SendPost(string url, string postData)
    {
        string result = "";
        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.ToString();
        }
        return result;
    }

5. About signature

Express bird and the third-party e-commerce company system docking, there is a certain security mechanism. IP authentication and signature are adopted for docking. The specific scheme is as follows:

Prevent data from being tampered with 
Five required (R) parameters are passed in the post request 
Requestdata = = data content (URL Code: UTF-8) ebusinessid = = user ID 
Requesttype = request instruction type 
Datasign = = data content signature: encrypt (request content (not encoded) + apikey) with MD5, and then Base64 
Encoding, and finally URL (UTF-8) encoding 
Datatype = = 2 (return data type is JSON) Note:
After the datasign is generated, the other party receives the data and signs with the same algorithm (the push interface requesttype is 
101 / 102 does not need URL encoding), generates a summary, and compares the two summaries to see if they are the same. If they are different, it indicates that they occur in the delivery process
Data tampering. 
Authentication of calling interface 
After registering as a express bird user, the corresponding user ID and apikey will be generated. The user ID is equivalent to the user name, 
Apikey is equivalent to password.

Recommended Today

JS function

1. Ordinary function Grammar: Function function name (){ Statement block } 2. Functions with parameters Grammar: Function function name (parameter list){ Statement block } 3. Function with return value Grammar: Function function name (parameter list){ Statement block; Return value; } Allow a variable to accept the return value after calling the function Var variable name […]