How the interface supports message reception: HTTP POST
Encoding format of the request method (Utf-8): "Application/x-www-form-urlencoded;charset=utf-8"
Request, return data type: Only JSON format is supported
Interface offers: Express Bird
System-Level parameter definitions
Parameter name |
Type |
Description |
Must require |
RequestData |
String |
The request content needs to be URL (utf-8) encoded. Request content JSON format, must be consistent with datatype. |
Must fill in |
Ebusinessid |
String |
Merchant ID, please view it on the My Services page. |
Must fill in |
RequestType |
String |
Request Instruction Type: 1007 |
Must fill in |
Datasign |
String |
Data content Signature: The (Request content (not encoded) +appkey) is MD5 encrypted, then BASE64 encoded, and finally the URL (utf-8) encoding. Please check the demo for detailed procedures. |
Must fill in |
DataType |
String |
Request, return data type: Only JSON format is supported |
Must fill in |
Java docking
Import Java.io.bufferedreader;import Java.io.ioexception;import Java.io.inputstreamreader;import Java.io.outputstreamwriter;import Java.io.unsupportedencodingexception;import Java.net.HttpURLConnection;import Java.net.url;import Java.net.urlencoder;import Java.security.messagedigest;import Java.util.HashMap;import Java.util.Map; public class Kdniaotrackqueryapi {//demopublic static void main (string[] args) {Kdniaotrackqueryapi API = new KDNIAOTRACKQ Ueryapi (); try {String result = Api.getordertracesbyjson ("ANE", "210001633605"); System.out.print (result);} catch (Exception e) {e.printstacktrace ();}} E-commerce idprivate String ebusinessid= "Please apply to express Bird official website http://www.kdniao.com/ServiceApply.aspx";//e-commerce encryption private key, courier birds provided, attention to custody, Do not leak private string appkey= "please go to express Bird official website for http://www.kdniao.com/ServiceApply.aspx";//Request Urlprivate String requrl= "http:// Api.kdniao.cc/ebusiness/ebusinessorderhandle.aspx "; /** * JSON way to Query Order logistics track * @throws Exception */public string Getordertracesbyjson (String Expcode, string expno) thro WS EXCEption{string requestdata= "{' Ordercode ': ', ' shippercode ': '" + Expcode + "', ' logisticcode ': '" + Expno + "'}"; map<string, string> params = new hashmap<string, string> ();p arams.put ("RequestData", Urlencoder ( RequestData, "UTF-8"));p arams.put ("Ebusinessid", Ebusinessid);p arams.put ("RequestType", "1002"); String Datasign=encrypt (RequestData, AppKey, "UTF-8");p arams.put ("Datasign", Urlencoder (Datasign, "UTF-8")); Params.put ("DataType", "2"); String result=sendpost (Requrl, params);//The information returned according to the company's business process ... return result; /** * XML Query Order Logistics track * @throws Exception */public String getordertracesbyxml () throws Exception{string Requestdat A= "<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>" + "<Content>" + "<OrderCode></OrderCode>" + " <ShipperCode>SF</ShipperCode> "+" <LogisticCode>589707398027</LogisticCode> "+" </ Content> "; map<string, string> params = new hashmap<string, string> ();p arams.put ("RequestData", Urlencoder ( RequestData, "UTF-8 "));p arams.put (" Ebusinessid ", Ebusinessid);p arams.put (" RequestType "," 1002 "); String Datasign=encrypt (RequestData, AppKey, "UTF-8");p arams.put ("Datasign", Urlencoder (Datasign, "UTF-8")); Params.put ("DataType", "1"); String result=sendpost (Requrl, params);//The information returned according to the company's business process ... return result; /** * MD5 encryption * @param STR content * @param charset encoding method * @throws Exception */@SuppressWarnings ("unused" ) Private string MD5 (String str, String charset) throws Exception {MessageDigest MD = messagedigest.getinstance ("MD5"); Md.update (Str.getbytes (charset)); Byte[] result = Md.digest (); StringBuffer sb = new StringBuffer (32); for (int i = 0; i < result.length; i++) {int val = result[i] & 0xff; if (Val <= 0xf) {sb.append ("0"); } sb.append (Integer.tohexstring (Val)); } return Sb.tostring (). toLowerCase ();} /** * Base64 encoding * @param STR content * @param charset encoding * @throws unsupportedencodingexception */private string base64 (String str, String charset) throws unsupportedencodingexception{string encoded = Base64Encode ( Str.getbytes (CharSet)); return encoded; } @SuppressWarnings ("unused") Private String Urlencoder (String str, String charset) throws Unsupportedencodingexception {String result = Urlencoder.encode (str, charset); return result;} /** * e-commerce sign Signature generation * @param content Contents * @param keyValue Appkey * @param charset encoding method * @throws Unsuppo Rtedencodingexception, Exception * @return datasign Signature */@SuppressWarnings ("unused") private string Encrypt (String cont ENT, String keyValue, String charset) throws Unsupportedencodingexception, Exception{if (keyValue! = null) {return Base64 ( MD5 (content + KeyValue, CharSet), CharSet);} Return base64 (MD5 (Content, CharSet), CharSet);} /** * Request to send a POST method to the specified URL * @param URL to send the request * @param params request Parameter Collection * @return The response result of the remote resource */@SuppressWarnings ("unused") private string sendpost (string URL, map< String, string> params) {outputstreamwriter out = null; BufferedReader in = null; StringBuilder result = new StringBuilder (); try {URL realurl = new URL (URL); HttpURLConnection conn = (httpurlconnection) realurl.openconnection (); The Send POST request must be set to the following two lines conn.setdooutput (true); Conn.setdoinput (TRUE); Post Method Conn.setrequestmethod ("post"); Set the generic request attribute Conn.setrequestproperty ("accept", "*/*"); Conn.setrequestproperty ("Connection", "keep-alive"); Conn.setrequestproperty ("User-agent", "mozilla/4.0" (compatible; MSIE 6.0; Windows NT 5.1; SV1) "); Conn.setrequestproperty ("Content-type", "application/x-www-form-urlencoded"); Conn.connect (); Gets the output stream corresponding to the URLConnection object out = new OutputStreamWriter (Conn.getoutputstream (), "UTF-8"); Send Request Parameters if(params = null) {StringBuilder param = new StringBuilder (); For (map.entry<string, string> entry:params.entrySet ()) {if (Param.length () >0) {Param.append ( "&"); } param.append (Entry.getkey ()); Param.append ("="); Param.append (Entry.getvalue ()); System.out.println (Entry.getkey () + ":" +entry.getvalue ()); }//system.out.println ("Param:" +param.tostring ()); Out.write (Param.tostring ()); }//Flush output stream buffer Out.flush (); Defines the BufferedReader input stream to read the response of the URL in = new BufferedReader (New InputStreamReader (conn.getinput Stream (), "UTF-8")); String Line; while (line = In.readline ())! = null) {result.append (line); }} catch (Exception e) {e.printstacktrace (); }//Use finally block to close the output stream, input stream finally{ try{if (out!=null) {out.close (); } if (In!=null) {in.close (); }} catch (IOException ex) {ex.printstacktrace (); }} return result.tostring (); } private static char[] Base64encodechars = new char[] {' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ', ' A ', ' B ', ' C ', ' d ', ' e ' ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' u ', ' V ', ' w ', ' X ', ' Y ', ' z ', ' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' + ', '/'; public static String Base64Encode (byte[] data) {StringBuffer SB = new StringBuffer (); int len = data.length; int i = 0; int B1, B2, B3; while (I < len) {B1 = data[i++] & 0xff; if (i = = len) {sb.append (base64encodechars[b1 >>> 2]); Sb.append (base64encodechars[(B1 & 0x3) << 4]); Sb.append ("= ="); Break } b2 = data[i++] & 0xff; if (i = = len) {sb.append (base64encodechars[b1 >>> 2]); Sb.append (base64encodechars[(B1 & 0x03) << 4) | ((B2 & 0xf0) >>> 4)]); Sb.append (base64encodechars[(B2 & 0x0f) << 2]); Sb.append ("="); Break } B3 = data[i++] & 0xff; Sb.append (BASE64ENCODECHARS[B1 >>> 2]); Sb.append (base64encodechars[(B1 & 0x03) << 4) | ((B2 & 0xf0) >>> 4)]); Sb.append (base64encodechars[(B2 & 0x0f) << 2) | ((B3 & 0xc0) >>> 6)]); Sb.append (base64encodechars[B3 & 0x3f]); } return sb.tostring (); }}
PHP Docking
<?php//e-commerce iddefined (' Ebusinessid ') or define (' Ebusinessid ', 1237100);//e-commerce encryption private key, courier Bird provided, pay attention to custody, do not leak defined (' AppKey ') or define (' AppKey ', ' 518a73d8-1f7f-441a-b644-33e77b49d846 ');//Request urldefined (' Requrl ') or define (' requrl ', ' http:// Api.kdniao.cc/ebusiness/ebusinessorderhandle.aspx '); /** * JSON way to query order logistics trajectory */function Getordertracesbyjson () {$requestData = "{' Ordercode ': ', ' shippercode ': ' SF ', ' Logisticcode ': ' 589707398027 '} "; $datas = Array (' ebusinessid ' = = ebusinessid, ' requesttype ' = ' 1002 '), ' RequestData ' = UrlEncode ($requestData), ' DataType ', ' 2 ',); $datas [' datasign '] = Encrypt ($requestData, AppKey), $result =sendpost (Requrl, $datas);//information returned according to the company's business ... return $ Result;} /** * XML Query Order logistics trajectory */function getordertracesbyxml () {$requestData = "<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>" ." <Content> "." <OrderCode></OrderCode> "." <ShipperCode>SF</ShipperCode> "." <LogisticCode>589707398027</LogisticCode> "." </content> "; $datas = Array (' ebusinessid ' = = ebusinessid, ' requesttype ' = ' 1002 ', ' REQUESTD ATA ' = UrlEncode ($requestData), ' DataType ' = ' 1 ',); $datas [' datasign '] = Encrypt ($requestData, AppKey), $result =sendpost (Requrl, $datas);//information returned according to the company's business ... return $ Result;} /** * Post Submission Data * @param string $url request URL * @param array $datas submitted data * @return URL response returned by HTML */function sendpost ($url , $datas) {$temps = array (); foreach ($datas as $key = + $value) {$temps [] = sprintf ('%s=%s ', $key, $value); } $post _data = Implode (' & ', $temps); $url _info = Parse_url ($url), if ($url _info[' Port ']== ') {$url _info[' port ']=80;} echo $url _info[' Port ']; $httpheader = "POST". $url _info[' path ']. "Http/1.0\r\n"; $httpheader. = "Host:". $url _info[' host ']. "\ r \ n"; $httpheader. = "content-type:application/x-www-form-urlencoded\r\n"; $httpheader. = "Content-length:". strlen ($post _data). "\ r \ n"; $httpheader. = "ConnectioN:close\r\n\r\n "; $httpheader. = $post _data; $FD = Fsockopen ($url _info[' host '), $url _info[' Port ']; Fwrite ($FD, $httpheader); $gets = ""; $headerFlag = True;while (!feof ($FD)) {if ($header = @fgets ($FD)) && ($header = = "\ r \ n" | | $header = = "\ n")) {break;}} while (!feof ($FD)) {$gets. = fread ($FD, 128); } fclose ($FD); return $gets;} /** * e-commerce sign Signature generated * @param data content * @param appkey appkey * @return datasign signature */function Encrypt ($data, $appkey) {R Eturn UrlEncode (Base64_encode (MD5 ($data. $appkey));}? >
C # Docking
Using system;using system.collections.generic;using system.linq;using system.text;using System.Web;using System.Net; Using System.IO; Namespace kdgoldapi{public class Kdapisearchdemo {//e-commerce id private string ebusinessid = "1237100"; E-commerce encryption private key, courier birds provide, pay attention to safekeeping, do not leak private string AppKey = "518a73d8-1f7f-441a-b644-33e77b49d846"; Request URL private String requrl = "Http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx"; <summary>//JSON query for order Logistics track///</summary>//<returns></returns> public string Getordertracesbyjson () {string requestData = ' {' Ordercode ': ', ' shippercode ': ' SF ', ' Logi Sticcode ': ' 589707398027 '} "; dictionary<string, string> param = new dictionary<string, string> (); Param. ADD ("RequestData", Httputility.urlencode (RequestData, Encoding.UTF8)); Param. ADD ("Ebusinessid", Ebusinessid); Param. ADD ("RequesttYpe "," 1002 "); String datasign = Encrypt (RequestData, AppKey, "UTF-8"); Param. ADD ("Datasign", Httputility.urlencode (Datasign, Encoding.UTF8)); Param. ADD ("DataType", "2"); string result = Sendpost (Requrl, param); The information returned according to the company's business process ... return result; }///<summary>//XML Query Order Logistics track///</summary>//<returns></returns& Gt public string Getordertracesbyxml () {String requestData = "<?xml version=\" 1.0\ "encoding=\" utf-8\ " ?> "+" <Content> "+" <ordercode></ordercod E> "+" <ShipperCode>SF</ShipperCode> "+" < Logisticcode>589707398027</logisticcode> "+" </Content> "; dictionary<string, string> param = new Dictionary<strinG, string> (); Param. ADD ("RequestData", Httputility.urlencode (RequestData, Encoding.UTF8)); Param. ADD ("Ebusinessid", Ebusinessid); Param. ADD ("RequestType", "1002"); String datasign = Encrypt (RequestData, AppKey, "UTF-8"); Param. ADD ("Datasign", Httputility.urlencode (Datasign, Encoding.UTF8)); Param. ADD ("DataType", "1"); string result = Sendpost (Requrl, param); The information returned according to the company's business process ... return result; }///<summary>///Post data, return the source code of the webpage///</summary>//<param name= "url" Send request url</param>//<param name= "param" > Requested parameter collection </param>//<returns> response result of remote resource < ;/returns> private string sendpost (string url, dictionary<string, string> param) {Strin G result = ""; StringBuilder postdata = new StringBuilder (); if (param! = null && param. Count; 0) {foreach (var p in param) {if (Postdata.length > 0) {Postdata.append ("&"); } postdata.append (P.key); Postdata.append ("="); Postdata.append (P.value); }} 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. Message; } return result; }///<summary>//E-commerce sign signature///</summary>///<param name= "Content" > Contents </par am>///<param name= "KeyValue" >Appkey</param>///<param name= "CharSet" >urL Code </param>///<returns>datasign signature </returns> private string Encrypt (string content, Strin G KeyValue, String charset) {if (keyValue! = null) {return base64 (MD5 (Conten T + KeyValue, CharSet), CharSet); } return Base64 (MD5 (Content, CharSet), CharSet); }///<summary>///String MD5 encryption///</summary>///<param name= "str" > string to encrypt </p aram>///<param name= "CharSet" > Encoding </param>///<returns> redaction </returns> Priva Te 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 <) ret + = "0" + A.tostrin G ("X"); else ret + = a.tostring ("X"); } return ret. ToLower (); } catch {throw; }}///<summary>//Base64 code///</summary>/<param name= "str" > Inside </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)); } }}
Shun Fung Express Tracking API docking (full code)