E-commerce express query interface docking demo

Function description
Logistics track query - the logistics information can be queried by using the logistics order number and express order number.
Interface rules
(1) The query interface supports query by waybill number (single query, no more than 10 concurrent queries/S).
(2) . Select the corresponding express company code for the specified logistics waybill number. If the format is incorrect or the code is incorrect, the failure message will be returned. For example, the EMS logistics order number should select the express company code (EMS)
(3) The returned logistics tracking information is sorted in ascending order of occurrence time.
(4) Interface instruction 1002.
(5) . Interface secret key application: Express Bird Website

JSON Request Example

 { "OrderCode": "", "ShipperCode": "SF", "LogisticCode": "118650888018" }

JSON return example

Without logistics track

 { "EBusinessID": "1109259", "Traces": [], "OrderCode": "", "ShipperCode": "SF", "LogisticCode": "118461988807", "Success": true, "Reason": null }

With logistics track

 { "EBusinessID": "1109259", "OrderCode": "", "ShipperCode": "SF", "LogisticCode": "118461988807", "Success": true, "CallBack":"", "State": 3, "Reason": null, "Traces": [ { "AcceptTime": "2014/06/25 08:05:37", "AcceptStation": "Dispatching.. (Dispatcher: Deng Yufu, Tel: 18718866310) [Shenzhen City]", "Remark": null }, { "AcceptTime": "2014/06/25 04:01:28", "AcceptStation": "The express is in Shenzhen Hub, ready to be sent to Shenzhen [Shenzhen City], the next station", "Remark": null }, { "AcceptTime": "2014/06/25 01:41:06", "AcceptStation": "Express in Shenzhen Hub [Shenzhen City]", "Remark": null }, { "AcceptTime": "2014/06/24 20:18:58", "AcceptStation": "Received [Shenzhen]", "Remark": null }, { "AcceptTime": "2014/06/24 20:55:28", "AcceptStation": "The express is in Shenzhen, ready to be sent to the next station Shenzhen Hub [Shenzhen City]", "Remark": null }, { "AcceptTime": "2014/06/25 10:23:03", "AcceptStation": "Dispatch has been signed in [Shenzhen]", "Remark": null }, { "AcceptTime": "2014/06/25 10:23:03", "AcceptStation": "Signed by: [Shenzhen City]", "Remark": null } ] }

JAVA call

 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;  /* * *The e-commerce ID and private key in DEMO are only for test use. Please register an account separately for the official environment *  */ public class KdniaoTrackQueryAPI { //DEMO public static void main(String[] args) { KdniaoTrackQueryAPI api = new KdniaoTrackQueryAPI(); try { String result = api.getOrderTracesByJson("ANE", "210001633605"); System.out.print(result); } catch (Exception e) { e.printStackTrace(); } } //E-commerce ID Private String EBusinessID="Please apply http://www.kdniao.com/ServiceApply.aspx "; //The private key of e-commerce encryption should be kept and not disclosed Private String AppKey="Please apply http://www.kdniao.com/ServiceApply.aspx "; //Request url private String ReqURL=" http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx ";	 /** *Query the order logistics track in Json mode * @throws Exception  */ public String getOrderTracesByJson(String expCode, String expNo) throws Exception{ String requestData= "{'OrderCode':'','ShipperCode':'" + expCode + "','LogisticCode':'" + expNo + "'}"; Map<String, String> params = new HashMap<String, String>(); params.put("RequestData", urlEncoder(requestData, "UTF-8")); params.put("EBusinessID", EBusinessID); params.put("RequestType", "1002"); String dataSign=encrypt(requestData, AppKey, "UTF-8"); params.put("DataSign", urlEncoder(dataSign, "UTF-8")); params.put("DataType", "2"); String result=sendPost(ReqURL, params);	 //Information returned according to company business processing 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 method * @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 * @param keyValue Appkey   *@ param charset encoding method * @throws UnsupportedEncodingException ,Exception *@ return DataSign Signature */ @SuppressWarnings("unused") private String encrypt (String content,  String keyValue, String charset) throws UnsupportedEncodingException, Exception { if (keyValue !=  null) { return base64(MD5(content + keyValue, charset), charset); } return base64(MD5(content, charset), charset); } /** *Send a request for the POST method to the specified URL *@ param url Send the requested URL *@ param params The parameter set requested by params *@ return Response result of remote resources */ @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(); //To send a POST request, the following two lines must be set conn.setDoOutput(true); conn.setDoInput(true); //POST method conn.setRequestMethod("POST"); //Set general request properties 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(); //Get 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()); } //Buffer of flush output stream out.flush(); //Define the BufferedReader input stream to read the response of the URL in = new BufferedReader( new InputStreamReader(conn.getInputStream(), "UTF-8")); String line; while ((line = in.readLine()) !=  null) { result.append(line); } } catch (Exception e) {             e.printStackTrace(); } //Use the finally block to close the output stream and 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();  } }

C # call

 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"; private string AppKey = "518a73d8-1f7f-441a-b644-33e77b49d846"; //Request url private string ReqURL = " http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx "; /// <summary> ///Query the order logistics track in Json mode /// </summary> /// <returns></returns> public string getOrderTracesByJson() { string requestData = "{'OrderCode':'','ShipperCode':'SF','LogisticCode':'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); //Information returned according to company business processing return result; } /// <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="param">The requested parameter set</param> ///<returns>Response results of remote resources</returns> private string sendPost(string url,  Dictionary<string, string> param) { string 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 ///</summary> ///<param name="content">Content</param> ///<param name="keyValue">Appkey</param> ///<param name="charset">URL encoding</param> ///<returns>DataSign signature</returns> private string encrypt(String content,  String keyValue, String charset) { if (keyValue !=  null) { return base64(MD5(content + keyValue, charset), charset); } return base64(MD5(content, charset), charset); } ///<summary> ///String MD5 encryption ///</summary> ///<param name="str">The string to be encrypted</param> ///<param name="charset">Coding 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">Coding Method</param> /// <returns></returns> private string base64(String str, String charset) { return Convert.ToBase64String(System. Text.Encoding.GetEncoding(charset). GetBytes(str)); } } }
  • zero
    give the thumbs-up
  • step on
  • zero
    Collection
    Think it's good? One click collection
  • zero
    comment

Is "relevant recommendation" helpful to you?

  • Very unhelpful
  • No help
  • commonly
  • to be helpful to
  • Very helpful
Submit
comment
Add Red Packet

Please fill in the red envelope greeting or title

individual

The minimum number of red packets is 10

element

The minimum amount of red packet is 5 yuan

Current balance three point four three element Go to recharge>
To be paid: ten element
Achieve 100 million technicians!
After receiving, you will automatically become a fan of the blogger and the red envelope owner rule
hope_wisdom
Red packet sent
Paid in element
Payment with balance
Click to retrieve
Scan code for payment
Wallet balance zero

Deduction description:

1. The balance is the virtual currency of wallet recharge, and the payment amount is deducted at a ratio of 1:1.
2. The balance cannot be directly purchased and downloaded, but VIP, paid columns and courses can be purchased.

Balance recharge