Birds are not limited express single query interface to -JAVA Docking

Unlimited express logistics trajectory query interface free docking, the principle is the order content Subscribe to the interface, the interface orders for real-time monitoring, when the logistics track updates, real-time access to data, format the data, calculate the waybill estimated time of arrival after the logistics status, current location data and other cities of the whole process, push back. After receipt of the order until the end of the monitoring. More suitable for electricity providers and some system software.

• scenarios

① buyers Logistics query: tracking, parcel progress, expected delivery time, delivery person contact information.

② seller logistics tracking: whether super area, turn pieces, delivery times, rejected

③ platform monitoring and management: Monitoring false transaction, the seller shipped matched with the customer to confirm the time of receipt.

javademo example:

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; 

public class KdGoldAPIDemo {
    
    //电商ID
    privateEBusinessID = String "1.2371 million" ;    
     // electricity providers private key encryption, providing courier birds, take good care, do not leak (to be re-application ID) 
    Private String AppKey = "518a73d8-1f7f-441a-b644-33e77b49d846" ;    
     // request url 
    Private String reqURL = "http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx" ;     
 
    / ** 
     * Json embodiment subscription information stream 
     * @throws Exception 
      * / 
    public String orderTracesSubByJson () throws Exception { 
        String requestData = "{ 'Code': 'SF', 'Item': [ "+  
                           " { 'No': '909 261 024 507', 'the Bk': 'Test'}, "+
                           " { 'No': '589 554 393 102', 'the Bk': 'Test'}, "+
                           "{'No': '589522101958','Bk': 'test'},"+
                           "{'No': '909198822942', 'Bk': 'test'}"+
                           "]}";
        
        Map<String, String> params = new HashMap<String, String>();
        params.put("RequestData", urlEncoder(requestData, "UTF-8"));
        params.put("EBusinessID", EBusinessID);
        params.put("RequestType", "1005");
        String dataSign=encrypt(requestData, AppKey, "UTF-8");
        params.put("DataSign", URLEncoder (dataSign, "UTF-. 8"+
                            "<Items>"+));
        params.put ( "the DataType", "2" ); 
        
        String Result = sendPost (reqURL, the params);     
        
        // The information processing business ...... returned 
        
        return Result; 
    } 
    
    / ** 
     * the XML stream mode information Subscribe 
     * @throws Exception 
      * / 
    public String orderTracesSubByXml () throws Exception { 
        String requestData = "<? xml Version = \" 1.0 \ "encoding = \" UTF-8 \ "?>" + 
                            "<Content>" + 
                            "< Code> SF </ Code> "+ 
                            " <Item> "+
                            "<No>909261024507</No>"+
                            "<Bk>test</Bk>"+
                            "</Item>"+
                            "<Item>"+
                            "<No>909261024507</No>"+
                            "<Bk>test</Bk>"+
                            "</Item>"+
                            "</Items>"+
                            "</Content>";
        
        Map<String, String> params = new HashMap<String, String>();
        params.put("RequestData", urlEncoder(requestData, "UTF-8"));
        params.put("EBusinessID", EBusinessID);
        params.put("RequestType", "1005");
        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;
        
    
    @SuppressWarnings (* /Exception 
     @throws
     *charset coding@param
     *STR content       @param
     *
     * the MD5 encrypted/ **
    } "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 = 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 内容   
     * @param keyValue Appkey  
     * @param charset 编码方式
     * @throws UnsupportedEncodingException ,Exception
     * @return DataSign签名
     */
    @SuppressWarnings("unused")
    private String encrypt (String content, String 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); 
    } 
    
     / ** 
     * to the specified URL POST method request      
     * @param the URL transmission request URL     
     * @param the params request parameter set      
     * @return response result remote resources
      * / 
    @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 provided the following two lines 
            conn.setDoOutput ( to true ); 
            conn.setDoInput ( to true );
             // the POST method
            conn.setRequestMethod("POST");
            // 设置通用的请求属性
            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();
            // 获取URLConnection对象对应的输出流
            out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            send the 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 ()); 
            } 
            // the flush buffered output stream 
            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 ((= in Line. 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 ) { 
                    the out.close (); 
                } 
                IF (! In = null ) { 
                    in.close (); 
                } 
            } 
            the catch (IOException EX) { 
                ex.printStackTrace (); 
            } 
        } 
        return result.toString (); 
    } 
}

 

Guess you like

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