Express Online Analytical birds pick reservation API interface, docking encoding

 

 

We know that online courier pickup booking interface is implemented made express function on its own website system interface, then express reservations pick what API interface, docking code is? Here take a look.

 First, the interface docking process

  Bird Express website application interfaces KEY- docking interface - Commissioning - on-line use

1. Log birds Express courier official website registration page Register an account birds
2, login user management background birds Express
NOTE: obtain a user ID and login APIKey Express birds user management background, this is used to ensure the reliability of the source application, to avoid the application falsified, unscrupulous use.
Go to "My Member" real-name authentication Note:
1, authentication type, application type can be selected according to the actual situation, the interface returns the data has nothing to do with the selection result;
2, marked * are required, required to upload clear, jpg picture format and less than 2M of documents;
3, an information technology docking Intelligence user side docking engineer;
4, if you have other questions can enter the official website added business cooperation group for consultation. After successful authentication, enter the "Services Management", subscribe to a membership service

Second, the Interface Description / Description

  (1) single-line interface is the express orders of birds provide an interface to the independent electricity supplier, warehouse management systems, logistics and supply chain logistics system platforms.

  (2) to address the needs of online delivery, courier business network selection by sending a request to inform the courier company courier shipments.

  (3) customer data forwarded to the courier birds through this interface by express courier birds arrange pickup of on-site service.

  (4) order number (OrderCode) can not be repeated submission, resubmit the system will return a specific error code.

  (5) the interface to support message receiving mode HTTP POST, the request method of encoding format (utf-8): "application / x-www-form-urlencoded; charset = utf-8".

  (6) Interface Address: API test address: http: //testapi.kdniao.cc: 8081 / api / OOrderService

  API official address: http: //api.kdniao.cc/api/OOrderService

Third, the interface parameters

  Interface code

  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.util.HashMap;

  import java.util.Map;

  import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

  import java.security.MessageDigest;

Example:

/ * 
  * Key ID and go to the official website application: HTTP: //www.kdniao.com/reg 
  * / 
  public  class KdGoldAPIDemo {
  // electricity supplier ID 
  Private String EBusinessID = " Go to the official website of birds Express application http: // www. kdniao.com/reg " ;
  // electricity providers private key encryption, providing courier birds, take good care not to leak 
  Private String AppKey = " go to the official website of birds express application http://www.kdniao.com/reg " ;
  // test request url 
  Private  String reqURL = " http://testapi.kdniao.cc:8081/api/oorderservice " ;
  // formal request url
  // Private reqURL String = "http://api.kdniao.cc/api/OOrderService";
  /**
  * Json方式 在线下单
  * @throws Exception
  */
  public String orderOnlineByJson() throws Exception{
  String requestData= "{'OrderCode': '012657700312'," +
  "'ShipperCode':'YTO'," +
  "'PayType':1," +
  "'ExpType':1," +
  "'Cost':1.0," +
  "'OtherCost':1.0," +
  "'Sender':" +
  "{" +
  " 'Company': 'LV', 'the Name': 'Taylor', 'Mobile': '15,018,442,396', 'provinceName': 'Shanghai', 'CityName': 'Shanghai', 'ExpAreaName': 'Qingpu District ',' Address: Pearl Road No. 73 is '},' ' " +
  " ' Receiver ': " +
  " { " +
  " ' Company ':' GCCUI ',' the Name ':' Yann ',' Mobile ':' 15,018,442,396 ',' provinceName ':' Beijing ',' CityName ':' Beijing ',' ExpAreaName ':' Chaoyang ',' Address': 'Sanlitun street Masahide building'}, " +
  " 'Commodity': " +
  "[{" +
  "'GoodsName':'鞋子','Goodsquantity':1,'GoodsWeight':1.0}]," +
  "'AddService':" +
  "[{" +
  "'Name':'COD','Value':'1020'}]," +
  "'Weight':1.0," +
  "'Quantity':1," +
  "'Volume':0.0," +
  "'Remark':'小心轻放'," +
  "'Commodity':" +
  "[{" +
  "'GoodsName':'鞋子'," +
  "'Goodsquantity':1," +
  "'GoodsWeight':1.0}]" +
  "}";
  Map<String, String> params = new HashMap<String, String>();
  params.put("RequestData", urlEncoder(requestData, "UTF-8"));
  params.put("EBusinessID", EBusinessID);
  params.put("RequestType", "1001");
  String dataSign=encrypt(requestData, AppKey, "UTF-8");
  params.put("DataSign " , URLEncoder (dataSign, " UTF-. 8 " ));
  the params .put ( " the DataType " , " 2 " ); 
  String Result = sendPost (reqURL, the params );
  // information based business process returns ... ... 
  return Result; 
  } 
  / * * 
  * the MD5 encrypted 
  * @param str content 
  * @param charset coding 
  * @throws Exception 
  * / 
  @SuppressWarnings ( " unused " )
  Private String the MD5 (STR String, String charset) throws Exception { 
  the 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编码
  * @param str 内容
  * @param charset 编码方式
  * @throws UnsupportedEncodingException
  */
  private String base64(String str, String charset) throws UnsupportedEncodingException{
  String encoded = Base64.encode(str.getBytes(charset));
  return encoded;
  }
  @SuppressWarnings("unused")
  private String urlEncoder(String str, String charset) throws UnsupportedEncodingException{
  String result = URLEncoder.encode(str, charset);
  return result;
  }
  /**
  * 电商Sign签名生成
  * @Param content content 
  * @param keyValue AppKey 
  * @param charset encoding 
  * @throws UnsupportedEncodingException, Exception 
  * @return DataSign signature 
  * / 
  @SuppressWarnings ( " unused " )
  Private String the encrypt (String Content, keyValue String, String charset) throws UnsupportedEncodingException, Exception 
  { 
  IF (the keyValue =! null ) 
  { 
  return Base64 (the MD5 (Content + the keyValue, charset), charset); 
  } 
  return Base64 (the MD5 (Content, charset), charset); 
  } 
  / * *
  * a POST to the specified URL request method
  * URL @param url transmission request 
  * @param params request parameter set 
  * @return remote resources in response to the results 
  * / 
  @SuppressWarnings ( " unused " )
  Private String sendPost (String URL, the Map <String, String> the params ) { 
  the OutputStreamWriter OUT = null ; 
  the BufferedReader in = null ; 
  the StringBuilder Result = new new the StringBuilder ();
  the try { 
  the URL realUrl = new new the URL (URL); 
  the HttpURLConnection Conn =(The HttpURLConnection) realUrl.openConnection ();
  // send a POST request must set the following two lines 
  conn.setDoOutput ( to true ); 
  conn.setDoInput ( to true );
  // POST method 
  conn.setRequestMethod ( " POST " );
  // Set General request attribute 
  conn.setRequestProperty ( " Accept " , " * / * " ); 
  conn.setRequestProperty ( " Connection " , " the Keep-Alive " ); 
  conn.setRequestProperty ( " User-Agent " ,
    " Mozilla / 4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) " ); 
  conn.setRequestProperty ( " Content-Type " , " the Application / the X--the WWW-form-urlencoded " ); 
  conn.connect (); 
  // Get URLConnection object corresponding to the output stream 
  OUT = new new the OutputStreamWriter (conn.getOutputStream (), " UTF-. 8 " );
  // send a request parameter 
  IF ( the params =! null ) { 
  the StringBuilder param = new new the StringBuilder ();
  for (the 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输出流的缓冲
  OUT .flush ();
  // define BufferedReader input stream to read the URL of the response 
  in = new new BufferedReader (
  new new the InputStreamReader (conn.getInputStream (), " UTF-. 8 " )); 
  String Line; 
  the while ((Line = in . the readLine ()) =! null ) { 
  result.append (Line); 
  } 
  } the catch (Exception E) { 
  e.printStackTrace (); 
  } 
  // use the finally block to close the output stream, the input stream 
  finally {
  the try {
  IF ( OUT ! = null ) {
  OUT.close();
  }
  if(in!=null){
  in.close();
  }
  }
  catch(IOException ex){
  ex.printStackTrace();
  }
  }
  return result.toString();
  }
  }

 

Guess you like

Origin www.cnblogs.com/kdn2019/p/11612833.html