Third-party logistics domestic commonly express a single query API interface Integrated Case

Suited to applications involving frequent delivery, express delivery to send people, businesses, electricity providers websites, micro-channel public dock No. platform use. Support than three hundred domestic and international express delivery and logistics company express a single number stop inquiry.

Instructions for use:

1. Express birds have ready-made demo

2.  http://www.kdniao.com/api-track used in accordance with instructions

3. If you have any doubts, please consult the official website of the courier bird

Express check API interface currently implemented in two ways, one is active queries, one is a push subscription data interfaces. To express Bird interface as an example (interface, docking interfaces required secret key, here is the test, can not use it, and the birds can go to the official website of the courier application is free to apply the secret key) will eventually be accompanied by a demo of java and more multi-language demo of birds can be found on the courier website.
Official Website:  http://www.kdniao.com
need to log in to apply for what user ID and API key, and opened his own real-name authentication-related courier service (free and paid packages packages to choose from a variety of value-added services)
access Process:

 

 

1, authentication type, application type can be selected according to the actual situation, the interface returns the data independent of the selection result;

3.2 marked * are required, required to upload a clear, jpg format pictures and less than 2M of documents;
3.3, docking technology people information to the user side docking engineer of information;
3.4, any additional questions can be added into the official website of the Business Cooperation group consultation.
After successful authentication, enter the "Services Management", subscribe to a membership service

(two), Interface Description / Description
(1) query interface support in accordance with Tracking Number (single query).
(2) express a single number to specify the interface of Express encoding format will not return an error or failure information is encoded.
Such as: EMS single stream number should be selected coding Express (EMS) Express view coding

demo Example:

java.io.BufferedReader Mport; 
Import java.io.IOException; 
Import the java.io.InputStreamReader; 
Import java.io.OutputStreamWriter; 
Import java.io.UnsupportedEncodingException; 
Import java.net.HttpURLConnection The; 
Import the java.net.URL; 
Import java.net.URLEncoder; 
Import java.security.MessageDigest; 
Import java.util.HashMap; 
Import java.util.Map; 

/ ** 
* 
* express logistics birds trajectory instant query interface 
* 
* @ technology QQ group: 456 320 272 
* @see : http://www.kdniao.com/YundanChaxunAPI.aspx 
* @copyright: Shenzhen City Express gold data services Limited 
* 
* ID and private electricity supplier in the DEMO testing purposes only, please register an account separate formal environment 
* More than 500 single-day single query volume, we recommend that the logistics track access subscription push Interface 
*
* ID and Key to go to the official website application: HTTP: //www.kdniao.com/ServiceApply.aspx 
* / 

public class KdniaoTrackQueryAPI { 
     
    // the DEMO 
    public static void main (String [] args) { 
        KdniaoTrackQueryAPI KdniaoTrackQueryAPI new new API = (); 
        {the try 
            String api.getOrderTracesByJson Result = ( "the ANE", "210 001 633 605"); 
            of System.out.print (Result); 
             
        } the catch (Exception E) { 
            e.printStackTrace (); 
        } 
    } 
     
    // electricity supplier ID 
    Private String EBusinessID = "courier birds go to the official website application http://www.kdniao.com/ServiceApply.aspx"; 
    // private key encryption electricity supplier, providing courier birds, take good care not to leak  
    private String AppKey = "courier birds go to the official website application http://www.kdniao.com/ServiceApply.aspx ";
    // url request
    private String ReqURL="http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx";  
  
    /**
     * Json方式 查询订单物流轨迹
     * @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, the params); 
         
        // return information in accordance with the business process ...... 
         
        return Result; 
    } 
     
    / ** 
     * XML query mode Order logistics trajectory 
     * @throws Exception 
     * / 
    public String getOrderTracesByXml () throws Exception { 
        String requestData = "<? xml Version = \" 1.0 \ "encoding = \" UTF-8 \ "?>" + 
                            "<the Content>" + 
                            "<OrderCode> </ OrderCode>" + 
                            "<ShipperCode> SF </ ShipperCode>" + 
                            "<LogisticCode>589707398027</LogisticCode>"+
                            "</Content>";
         
        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", "1");
         
        String result=sendPost(ReqURL, params);
         
        //根据公司业务处理返回的信息......
         
        return result;
     * /
     * @throws Exception
     * @param charset coding
     * @param str content      
     * the MD5 encrypted
    / **
    }
  
    @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编码
     * @param str 内容      
     * @param charset 编码方式
     * @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;
    }
     
    /**
     * 电商Sign签名生成
     * @param content 内容  
     * @param keyValue Appkey 
     * @param charset 编码方式
     * @throws UnsupportedEncodingException ,Exception
     * @Return DataSign signature 
        the OutputStreamWriter OUT = null;
     */
    @SuppressWarnings("unused")
    Private String the encrypt (String Content, String the keyValue, 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); 
    } 
     
     / ** 
     * sends a POST request method specified URL     
     * @param url transmission request URL    
     * @param request parameter set the params     
     * @return remote resource response results 
     * / 
    @SuppressWarnings ( "unused" ) 
    Private sendPost String (String URL, the Map <String, String> the params) { 
        the BufferedReader in = null;       
        StringBuilder result = new StringBuilder();
        try {
            URL realUrl = new URL(url);
            HttpURLConnection conn =(HttpURLConnection) realUrl.openConnection();
            // 发送POST请求必须设置如下两行
            conn.setDoOutput(true);
            conn.setDoInput(true);
            // POST方法
            conn.setRequestMethod("POST");
            // 设置通用的请求属性
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent",
                    "The Mozilla / 4.0 (compatible; MSIE 6.0; the Windows NT 5.1; SVl)"); 
                      }               
                      param.append (entry.getKey ()); 
                      param.append ( "=");
            conn.setRequestProperty("Content-Type", "application/x-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 new new param = the StringBuilder (); 
                  for (of Map.Entry <String, String> entry: params.entrySet ()) { 
                      IF (param.length ()> 0) { 
                          param.append ( "&");
                      param.append (entry.getValue ());                     
                      //System.out.println(entry.getKey () + ":" entry.getValue + ()); 
                  } 
                  //System.out.println("param:"+ param.toString ()); 
                  out.write (param.toString ()); 
            } 
            // the flush buffered output stream 
            out.flush (); 
            // read the input stream defined BufferedReader URL response 
            in = new new BufferedReader ( 
                    new new the InputStreamReader (conn.getInputStream (), "UTF-. 8")); 
            String Line; 
            the while ((Line = in.readLine ()) = null)! { 
                result.append (Line); 
            }
        The catch} (Exception E) {            
            e.printStackTrace (); 
        } 
        // finally block used to close the output stream, the input stream 
        finally { 
            the try { 
                IF (OUT = null!) { 
                    The out.close (); 
                } 
                IF (in =! null) { 
                    in.close (); 
                } 
            } 
            the catch (IOException EX) { 
                ex.printStackTrace (); 
            } 
        } 
        return result.toString (); 
    } 
     
     
    Private static char [] = new new base64EncodeChars 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();
    }
}

  

Guess you like

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