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

preface

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.

catalog
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)

RequestData=%7b++++%22OrderCode%22%3a+%22012657018199%22%2c++++%22PayType%22%3a+%221%22%2c++++%22MonthCode%22%3a+%221234567890%22%2c++++%22ExpType%22%3a+%221%22%2c++++%22Sender%22%3a+%7b++++++++%22Name%22%3a+%22Taylor%22%2c++++++++%22Mobile%22%3a+%2215018442396%22%2c++++++++%22ProvinceName%22%3a+%22%e4%b8%8a%e6%b5%b7%22%2c++++++++%22CityName%22%3a+%22%e4%b8%8a%e6%b5%b7%e5%b8%82%22%2c++++++++%22Address%22%3a+%22%e6%98%8e%e7%8f%a0%e8%b7%af%22++++%7d%2c++++%22Receiver%22%3a+%7b++++++++%22Company%22%3a+%22GCCUI%22%2c++++++++%22Name%22%3a+%22Yann%22%2c++++++++%22Mobile%22%3a+%2215018442396%22%2c++++++++%22ProvinceName%22%3a+%22%e5%8c%97%e4%ba%ac%22%2c++++++++%22CityName%22%3a+%22%e5%8c%97%e4%ba%ac%e5%b8%82%22%2c++++++++%22ExpAreaName%22%3a+%22%e6%9c%9d%e9%98%b3%e5%8c%ba%22%2c++++++++%22Address%22%3a+%22%e4%b8%89%e9%87%8c%e5%b1%af%e8%a1%97%e9%81%93%22++++%7d%2c++++%22Commodity%22%3a+%5b++++++++%7b++++++++++++%22GoodsName%22%3a+%22%e9%9e%8b%e5%ad%90%22%2c++++++++++++%22Goodsquantity%22%3a+1%2c++++++++++++%22GoodsWeight%22%3a+1++++++++%7d++++%5d%2c++++%22AddService%22%3a+%5b++++++++%7b++++++++++++%22Name%22%3a+%22COD%22%2c++++++++++++%22Value%22%3a+%221020%22%2c++++++++++++%22CustomerID%22%3a+%221234567890%22++++++++%7d++++%5d%2c++++%22Weight%22%3a+1%2c++++%22Quantity%22%3a+1%2c++++%22Volume%22%3a+0%2c++++%22Remark%22%3a+%22%e5%b0%8f%e5%bf%83%e8%bd%bb%e6%94%be%22%2c++++%22StartDate%22%3a+%222020-05-19+11%3a00%3a00%22%2c++++%22EndDate%22%3a+%222020-05-19+15%3a00%3a00%22%7d&EBusinessID=test1617571&RequestType=1801&DataSign=MjRkM2ZjYWNhYzMyOGQ4M2U5ZDhjZmQxNTZjNTMxY2M%3d&DataType=2

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)
Note:
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:
{'OrderCode':'','ShipperCode':'SF','LogisticCode':'118954907573'}

The URL(UTF-8) encoded content is:
%7b%27OrderCode%27%3a%27%27%2c%27ShipperCode%27%3a%27SF%27%2c%27LogisticCode%27%3a%27118954907573%27%7d;
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
{'OrderCode':'','ShipperCode':'SF','LogisticCode':'118954907573'}56da2cf8-c8a2-44b2-b6fa-476cd7d1ba17
 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
OWFhM2I5N2ViM2U2MGRkMjc4YzU2NmVlZWI3ZDk0MmE=

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";
//2-json
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:

///<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;
    }

Tags: ASP.NET encoding JSON Mobile Windows

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