Jingdong express home-to-door Collection - online order API interface development


In recent years, the scale of e-commerce transactions in China has become larger and larger, online orders are more and more, and the situation of goods return and exchange is more and more common. Return and exchange is an important part of online shopping process, and also an important aspect of reflecting the service level of e-commerce platform and merchants. At the same time, the return and exchange of goods is also the most easily disputed link among e-commerce platforms, businesses and consumers. In order to ensure the service of this link, e-commerce platform launched the return and exchange of goods and pick-up business. Return, exchange and pick-up at home is a kind of convenient and convenient logistics service provided for the buyer when returning goods. When the buyer needs to return the goods when applying for replacement or initiating a claim for safeguarding rights, the logistics company does not need to mail the goods by itself, and arranges the courier to pick up the goods at home.

1. Interface function description

2. Complete the preparatory work

3.API interface

4. Request parameters (example)

5. Return message (example)

6. Complete requested message (URL code)

7. Decoded message

8. Step by step explanation (version C)

9. About signature

  1. Interface function description
    This interface is used to inform the courier of the express company to collect the goods at home.

2. Complete the preparatory work
Go to express bird website to register an account for free
Get an apikey for free (required for interface permission verification)
Complete the real name authentication process
Order a free package
3.API interface
Test call address: http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json
Official call address: http://api.kdniao.com/api/dist
Request method: POST
UTF-8: application/x-www-form-urlencoded;charset=utf-8
Return type: JSON
Debug page: http://kdniao.com/UserCenter/v2/SandBox/TrackQuery.aspx
Debugging tool: to debug (log in with express bird account)

4. Request parameters (example)

    "OrderCode": "012657018199",
    "PayType": "1",
    "MonthCode": "1234567890",
    "ExpType": "1",
    "Sender": {
        "Name": "Taylor",
        "Mobile": "15018442396",
        "ProvinceName": "Shanghai",
        "CityName": "Shanghai",
        "Address": "Mingzhu Road"
    "Receiver": {
        "Company": "GCCUI",
        "Name": "Yann",
        "Mobile": "15018442396",
        "ProvinceName": "Beijing",
        "CityName": "Beijing",
        "ExpAreaName": "Chaoyang District",
        "Address": "Sanlitun Street"
    "Commodity": [
            "GoodsName": "shoes",
            "Goodsquantity": 1,
            "GoodsWeight": 1
    "AddService": [
            "Name": "COD",
            "Value": "1020",
            "CustomerID": "1234567890"
    "Weight": 1,
    "Quantity": 1,
    "Volume": 0,
    "Remark": "Handle with care",
    "StartDate": "2020-05-19 11:00:00",
    "EndDate": "2020-05-19 15:00:00"

5. Return message (example)

    "EBusinessID": "test1617571",
    "Success": true,
    "Order": {
        "OrderCode": "112657018199",
        "KDNOrderCode": "KDN10200519103057",
        "ShipperCode": "JD"
    "ResultCode": "100",
    "Reason": "",
    "UniquerRequestNumber": "1ed104ea-ff57-404f-8e12-59e1f4636920"

6. Complete requested message (URL code)


7. Decoded message:

RequestData={"PayType": 1,"ExpType": 1,"ShipperCode": "SF","OrderCode": "300008886539888","IsNotice": 1,"IsReturnPrintTemplate": 1,"Commodity": [{"GoodsName": "other","Goodsquantity": 1,"GoodsWeight": 0}],"Sender": {"Name": "Wang Baojian","Mobile": "13988888888","ProvinceName": "Beijing","CityName": "Beijing","ExpAreaName": "Xicheng District","Address": "1020, No.1, Guoying, Xizhimen South Street, Xicheng District, Beijing"},"Receiver": {"Name": "Liu Xiaodao","Mobile": "18809999999","ProvinceName": "Guangdong Province","CityName": "Shenzhen City","ExpAreaName": "Futian District","Address": "Huabao No.1 building, Futian District, Shenzhen City, Guangdong Province"}}&EBusinessID=test1617571&RequestType=1007&DataSign=ZDhhOTU2OTcxMWI1NGFiNTBmMzQ5NjMwNzYxZmEyMzk=&DataType=2

8. Step by step explanation (version C)
Request packet structure

9. Signature description
About signing
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:

1. 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, then encode with Base64, and finally encode with URL(utf-8)
Datatype = = 2 (return data type is json)
After the DataSign is generated, the other party receives the data and signs it with the same algorithm (URL coding is not required for the push interface RequestType 101 / 102). The summary is generated and compared with whether the two summaries are the same. If they are different, data tampering occurs during the transfer process.

2. Calling the identity authentication of the 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 and APIKey is equivalent to the password.
give an example:
1. Assumptions
 The content of RequestData (JSON) is:

The URL(UTF-8) encoded content is:
EBusinessID=1237100 [example ID, not available for actual use]
APIKey=56da2cf8-c8a2-44b2-b6fa-476cd7d1ba17 [example Key, not available for actual use]

2. Then the content signed by DataSign is
 After md5 and base64, the content is: owfhm2i5n2vim2u2mgrkmj4yzu2nmvlzwi3zdk0mme =,
After URL(UTF-8) encoding, the content is: owfhm2i5n2vim2u2mgrkmj4yzu2nmvlzwi3zdk0mme% 3D
 The final data to be sent is:
RequestType=1002&EBusinessID=1237100&RequestData =%7b%27OrderCode%27%3a%27%27%2c%27ShipperCode%27%3a%27SF%27%2c%27LogisticCode%27%3a%27118954907573%27%7d&DataSign=OWFhM2I5N2ViM2U2MGRkMjc4YzU2NmVlZWI3ZDk0MmE%3d&DataType=2

3. After receiving the data, the receiver obtains
 EBusinessID, RequestData and DataSign.
4. The receiver obtains APIKey from EBusinessID, and the data of RequestData+APIKey
 The content after md5 and base64 is

5. The receiver judges whether the signed data is consistent with the delivered DataSign. If the business operation is consistent, an error will be returned if the data is inconsistent.

Interface call example:

string used = "1237100";//Sample ID only, not for practical use
//Encrypted private key, provided by express bird
string keyValue = "56da2cf8-c8a2-44b2-b6fa-476cd7d1ba17";//As an example Key only, it cannot be used in practice
//Request address
string url = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
string DataType = "2";
//UTF-8 for character encoding
string charset = "UTF-8";
//JSON string
string jsonStr = "json Request message";
//MD5 encryption of (jsonStr+APIKey), Base64 encoding, and URL(utf-8) encoding
datasign = HttpUtility.UrlEncode(base64(MD5(jsonStr + keyValue, "UTF-8"), "UTF-8"), Encoding.UTF8);
//Request message parameters
string PostStr = "RequestType=1002&EBusinessID= used &RequestData=jsonStr &DataSign= datasign&DataType=DataType";
//Communication protocol uses Http protocol Post request mode
string post = this.DoPost(url, PostStr);

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;

Tags: ASP.NET encoding JSON Mobile Windows

Posted on Wed, 20 May 2020 04:56:39 -0700 by burtybob