Polar rabbit express bill No. query - polar rabbit Express

Keywords: Programming encoding JSON network Java


After reading this article, copy the source code to your project, and you can quickly complete the docking of polar rabbit express interface. The effect of the interface displayed on the official website of polar rabbit express is more suitable for novices, Call the polar rabbit Express query API interface of the express bird to query the logistics delivery status of the polar rabbit express bill No. in all links, including receiving, transportation, transfer center, delivery to sign in, etc. The express bird API interface does not distinguish development languages. It supports program calls in Java, C, PHP, Python, ObjectC and other development languages. The following details the implementation process

1. Complete the preparatory work

1.1 go to express bird website Free registration An account number

1.2. Obtain an apikey for free (required for interface permission verification)

1.3 complete the real name certification process

1.4, order a free package

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 method: POST

2.4, UTF-8: application/x-www-form-urlencoded;charset=utf-8

2.5, return type: JSON

2.6, debugging page: http://kdniao.com/UserCenter/v2/SandBox/TrackQuery.aspx

2.7 debugging tools: Debug (log in with express bird account)


3. Request parameters (Headers)

Parameter name type Explain Must ask
RequestData String The requested content shall be URL(utf-8) encoded, and the JSON format of the requested content shall be consistent with the DataType Must fill
EBusinessID String User ID, View user ID and ApiKey Must fill
RequestType String Request instruction type: 1002 Must fill
DataSign String The signature data (Body+ApiKey) is encrypted by MD5, then encoded by Base64, and finally encoded by URL(utf-8) Must fill
DataType String Find and return data type: 2-json, default Json

4. Request parameter (Body)

Parameter name type Explain Must ask
OrderCode String Order number Selective filling
ShipperCode String Express Company Code: JTSD Must fill
LogisticCode String Logistics waybill No Must fill


5. Return parameter

Parameter name type Explain Must ask
EBusinessID String User ID Must fill
ShipperCode String Express company code Must fill
LogisticCode String Logistics waybill No Selective filling
Success String Success or not Must fill
Reason String Reasons for failure Selective filling
State String Logistics status: 2-on the way, 3-sign in, 4-problem parts Must fill
Traces  String time  
AcceptTime String   Must fill
AcceptStation String Description Selective filling
Remark String Remarks Must fill

6. Request complete message (example)


7. Successful return message (example)

"LogisticCode": "JT0000052600488",
"ShipperCode": "JTSD",
"Traces": [
"AcceptStation": "[Deng Yongjun of Wuhu City and Wuhu Jinghu network has taken 17855364213",
"AcceptTime": "2020-03-16 16:26:13"
"AcceptStation": "[Deng Yongjun of Wuhu City and Wuhu Jinghu network has taken 17855364213",
"AcceptTime": "2020-03-16 16:41:33"
"AcceptStation": "[Received by Wuhu City and Wuhu Jinghu branch",
"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 left Wuhu transfer center and sent to Hefei transfer center",
"AcceptTime": "2020-03-16 20:47:03"
"AcceptStation": "[Express to Hefei Transfer Center",
"AcceptTime": "2020-03-16 23:40:10"
"AcceptStation": "[Hefei express left [Hefei transfer center] and sent to [Guangzhou Huadu transfer center]",
"AcceptTime": "2020-03-17 00:10:48"
"AcceptStation": "[Guangzhou] express to Guangzhou Huadu Transfer Center",
"AcceptTime": "2020-03-17 20:45:00"
"AcceptStation": "[Guangzhou City Express left Guangzhou Huadu transfer center and sent to Shenzhen Bao'an transfer center",
"AcceptTime": "2020-03-18 00:17:55"
"AcceptStation": "[Shenzhen] express to Shenzhen Bao'an Transfer Center",
"AcceptTime": "2020-03-18 03:00:17"
"AcceptStation": "[Shenzhen express 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] 17679495647 is sending",
"AcceptTime": "2020-03-18 08:10:09"
"AcceptStation": "[Zhao Kai 15919817730 of Shenzhen City [Shenzhen Futian branch] is sending a piece",
"AcceptTime": "2020-03-18 09:55:19"
"AcceptStation": "[Shenzhen Express has been signed in 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

8. Failure return message (example)


"LogisticCode": "JT0000052600488",
"ShipperCode": "JTSD",
"Traces": [],
"State": "0",
"EBusinessID": "1264783",
"Reason": "Business error[No packages available]",
"Success": false

Note: this message will be returned if there is no real name authentication, no package is ordered, and the available query volume of the package has been used up
To real name authentication / Learn more about the package

9. No trace return message (example)


"LogisticCode": "JT0000052600488",
"ShipperCode": "JTSD",
"Traces": [],
"State": "0",
"EBusinessID": "1264783",
"Reason": "No track information",
"Success": true

10. Step by step explanation (version C)

10.1 request packet structure

10.2,C call code example

//Electricity supplier ID
string eEBusinessID = "test1617571";
 //E-commerce encrypts the private key, which is provided by express bird. Take care not to disclose
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";
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.

10.3,C call method

    ///String MD5 encryption
    ///< 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);
            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");
                    ret += a.ToString("X");
            return ret.ToLower();
    /// <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());
            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);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream backStream = response.GetResponseStream();
            StreamReader sr = new StreamReader(backStream, Encoding.GetEncoding("UTF-8"));
            result = sr.ReadToEnd();
        catch (Exception ex)
            result = ex.ToString();
        return result;

11. Application effect of polar rabbit Express query interface


Completion can achieve the display effect of polar rabbit official website.


12. About signature

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

Prevent data tampering 
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) 
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 whether the two summaries are the same. If they are different, data tampering occurs in the process of transmission. 
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.

13. Return code definition

Code Explain
100 Success
101 Missing required parameters
102 Verification problem
103 Format problem

Posted by dk4210 on Mon, 30 Mar 2020 00:16:37 -0700