Express a single query interface - pole Rabbit Courier

Preface
watching birds api express courier extremely rabbit docking tutorial article, and then copy the source code to your project, you can quickly express interface, docking poles Rabbit. Is more suitable for a novice just getting started, call the courier bird pole rabbit Express inquiry API interface, to inquire into the pole rabbit express a single number from the recipient, transportation, the transit center, delivery to all aspects of the sign and other logistics shipping status. Express birds api interface does not distinguish between language development, program support Java, C #, PHP, Python , ObjectC other development language called. The following explain in detail the implementation process.
1. Complete the preparatory work
1.1, to express the birds official website registered a free account

1.2, free access to a apiKey (interface to verify permissions required)

1.3, complete real-name certification process

1.4, a free subscription package

2.API Interface

2.1 Test call address: http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json

2.2, the official call address: http://api.kdniao.com/api/dist

2.3, the request mode: POST

2.4, encoding format (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: to debug (using courier birds account login)

3. Request parameter (Headers)

Express a single query interface - pole Rabbit Courier
4. Request parameter (Body)
. 5.Express a single query interface - pole Rabbit Courier

6. request complete message (example)

RequestData=%7b%27OrderCode%27%3a%27%27%2c%27ShipperCode%27%3a%27
JTSD%27%2c%27LogisticCode%27%3a%27
jt0000052600488%27%7d&EBusinessID=1264783&RequestType=1002&DataSign=MT
YyMDU4NWQ2NmU1ZDI2MDEzNGE5YmV
lM2YxYzEzMTM%3d&DataType=2
{
    "LogisticCode": "JT0000052600488",
    "ShipperCode": "JTSD",
    "Traces": [
        {
            "AcceptStation": "【芜湖市】【芜湖镜湖网点】的邓拥军 17855364213已取件",
            "AcceptTime": "2020-03-16 16:26:13"
        },
        {
            "AcceptStation": "【芜湖市】【芜湖镜湖网点】的邓拥军 17855364213已取件",
            "AcceptTime": "2020-03-16 16:41:33"
        },
        {
            "AcceptStation": "【芜湖市】【芜湖镜湖网点】已收件",
            "AcceptTime": "2020-03-16 17:39:21"
        },
        {
            "AcceptStation": "【芜湖市】快件离开【芜湖镜湖网点】已发往【芜湖转运中心】",
            "AcceptTime": "2020-03-16 17:40:27"
        },
        {
            "AcceptStation": "【芜湖市】快件到达【芜湖转运中心】",
            "AcceptTime": "2020-03-16 19:36:32"
        },
        {
            "AcceptStation": "【芜湖市】快件离开【芜湖转运中心】已发往【合肥转运中心】",
            "AcceptTime": "2020-03-16 20:47:03"
        },
        {
            "AcceptStation": "【合肥市】快件到达【合肥转运中心】",
            "AcceptTime": "2020-03-16 23:40:10"
        },
        {
            "AcceptStation": "【合肥市】快件离开【合肥转运中心】已发往【广州花都转运中心】",
            "AcceptTime": "2020-03-17 00:10:48"
        },
        {
            "AcceptStation": "【广州市】快件到达【广州花都转运中心】",
            "AcceptTime": "2020-03-17 20:45:00"
        },
        {
            "AcceptStation": "【广州市】快件离开【广州花都转运中心】已发往【深圳宝安转运中心】",
            "AcceptTime": "2020-03-18 00:17:55"
        },
        {
            "AcceptStation": "【深圳市】快件到达【深圳宝安转运中心】",
            "AcceptTime": "2020-03-18 03:00:17"
        },
        {
            "AcceptStation": "【深圳市】快件离开【深圳宝安转运中心】已发往【深圳福田网点】",
            "AcceptTime": "2020-03-18 04:44:39"
        },
        {
            "AcceptStation": "【深圳市】【深圳福田网点】的邹俊林 17679495647正在派件",
            "AcceptTime": "2020-03-18 08:10:09"
        },
        {
            "AcceptStation": "【深圳市】【深圳福田网点】的赵凯 15919817730正在派件",
            "AcceptTime": "2020-03-18 09:55:19"
        },
        {
            "AcceptStation": "【深圳市】快件已签收,签收人是【代收】,如有疑问请联系:15919817730,期待再次为您服务",
            "AcceptTime": "2020-03-18 14:53:54"
        }
    ],
    "State": "3",
    "EBusinessID": "1264783",
    "Success": true
}

Note: No real-name authentication, did not order the package, the package has run out of available queries will return this message information

9. No trace back packets (Example)

{
"LogisticCode": "JT0000052600488",
"ShipperCode": "JTSD",
"Traces": [],
"State": "0",
"EBusinessID": "1264783",
"Reason": "暂无轨迹信息",
"Success": true
}

10. explain step (C # version)
10.1, request packet structure
11.Express a single query interface - pole Rabbit Courier

10.2, C # code samples calling

// electricity supplier ID
String eEBusinessID = "test1617571";
// private key encryption electricity supplier, providing courier birds, take good care not to leak
String AppKey = "554343b2-7252-439b-b4eb-1af42c8f2175";
// request url
String reqURL = " http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json ";
// request command
String reqType = "1002";
// 2-JSON
String dataType = "2";
// character encoding . 8-using UTF
string charset = "UTF-. 8";
// the JSON string string
string jsonStr =
"{\" OrderCode \ ": \" \ ", \" ShipperCode \ ": \" JTSD \ ", \" LogisticCode \ ": \" JT0000052600488 \ "}";
// the (jsonStr + aPIKey) for MD5 encryption
string md5Str = MD5 (jsonStr + apiKey , charset);
// md5Str Base64 encoding of the
string base64Str = base64 (md5Str, charset );
// URL encoding (UTF-. 8)
String datasign = HttpUtility.UrlEncode (base64Str, charset);
// request packet parameters
String postStr = "the RequestType = reqType & EBusinessID = eEBusinessID & the RequestData = jsonStr
& DataSign = datasign & the DataType = dataType";
// protocol use Http protocol Post request method returns the trajectory data
String post = SendPost (reqURL, postStr);
// get the post data to express the bird is returned complete message, then write a json analytic methods to be able to get inside field information.
10.3, C # method call

///<summary>
/// 字符串MD5加密
///</summary>
///<param name="str">要加密的字符串</param>
///<param name="charset">编码方式</param>
///<returns>密文</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();
}
The catch
{
the throw;
}
}
/// <Summary>
/// Base64 encoding
/// </ Summary>
/// <param name = "STR"> SUMMARY </ param>
/// <param name = "charset "> encoding </ param>
/// <Returns> </ Returns>
Private String Base64 (STR String, String charset)
{
return Convert.ToBase64String (System.Text.Encoding.GetEncoding (charset) .GetBytes (STR)) ;
}
/// <Summary>
submitted data /// Post, the return page source
/// </ Summary>
</ param> /// <param name = "URL"> the URL transmission request
/// <param name = "postData"> parameter request message </ param>
/// <Returns> in response to the result of the remote resource </ 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;Express a single query interface - pole Rabbit Courier

            12.关于签名

Bird Express and third-party e-commerce company for docking systems, there is a certain security mechanisms. Plus signature authentication using IP
docking mode, specific programs are as follows:

Prevent tampering with the data
can be transmitted 5 (R) parameter in the POST request
RequestData == content data (URL encoding: UTF-. 8)
EBusinessID == user ID
the RequestType = request command type
DataSign == signature data content of: (a request content (uncoded) + apiKey) for MD5 encrypted and then Base64
encoding, finally URL (utf-8) encoding
dataType == 2 (return data type is json)
Note:
after DataSign generation, the other received data, with the same the signature algorithm (push to RequestType interfaces
101/102 need not be a URL-encoded) to generate a digest, a summary comparison of both are the same, if different, indicating the occurrence of the delivery process
data tampering.
Call Interface authentication
after a user registered as a courier birds, will generate a user ID and APIKey corresponding user ID corresponds to the user name,
APIKey as a password.

}

Guess you like

Origin blog.51cto.com/14679631/2484534