Shunfeng Express Single Number Query api Interface Free Docking Parameters and demo

Posted by f8ball on Tue, 13 Aug 2019 11:16:43 +0200

Shunfeng Express has strict control over logistics information. The sliding validation code provided by Tencent Cloud is added to the official website to protect it. If a large number of logistic information of Shunfeng need to be queried, it must be connected with the official route query interface of Shunfeng. Note that the docking interface must have Shunfengyue account closure, after successful docking can only query the routing information of the logistics single number of their shipment.
Shunfeng currently offers two docking modes:
One is the self-service docking of developers, which requires the registration of Fengqiao account, the application to become a developer, and then upload electronic face sheets and other operations, which is more cumbersome.
Another way is to focus on the third-party service provider docking. Express Bird has been stationed in Shunfeng third-party software service platform, docking is very convenient.
Logistics Track Query - Logistics single number and express single number can be used to query logistics information.
(1) The query interface supports querying according to the shipping number (single query).
(2) The designated logistics waybill number chooses the corresponding express company code. If the format is wrong or the coding error will return the failure information. If Shunfeng Logistics Number should choose Express Company Code (SF)
(3) Interface Source: Express Bird
(4) Logistics tracking information returned is arranged in ascending order according to the time of occurrence.
(5) Interface instruction 1002.
System-level input parameters

Application level input parameters

Return result parameters

Examples of requests

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

Return an example
No logistics trajectory

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

Logistics trajectory

{
"EBusinessID": "1109259",
"OrderCode": "",
"ShipperCode": "SF",
"LogisticCode": "118461988807",
"Success": true,
"CallBack":"",
"State": 3,
"Reason": null,
"Traces": [
{
"AcceptTime": "2014/06/25 08:05:37",
"AcceptStation": "Delivery in progress..(Dispatcher:Deng Yufu,Telephone:18718866310)[Shenzhen]",
"Remark": null
},
{
"AcceptTime": "2014/06/25 04:01:28",
"AcceptStation": "Express in Shenzhen Distribution Center ,Ready for next stop in Shenzhen [Shenzhen City]",
"Remark": null
},
{
"AcceptTime": "2014/06/25 01:41:06",
"AcceptStation": "Express in Shenzhen Distribution Center [Shenzhen City]",
"Remark": null
},
{
"AcceptTime": "2014/06/24 20:18:58",
"AcceptStation": "Received[Shenzhen City]",
"Remark": null
},
{
"AcceptTime": "2014/06/24 20:55:28",
"AcceptStation": "Express in Shenzhen ,Preparing to be sent to the next station, Shenzhen Distribution Center [Shenzhen City]",
"Remark": null
},
{
"AcceptTime": "2014/06/25 10:23:03",
"AcceptStation": "The dispatch has been signed[Shenzhen City]",
"Remark": null
},
{
"AcceptTime": "2014/06/25 10:23:03",
"AcceptStation": "Signatory: Signed[Shenzhen City]",
"Remark": null
}
]
}

JAVA docking demo

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 {
    
    //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 to express bird website http://www.kdniao.com/ServiceApply.aspx";
    //E-commerce encryption private key, courier bird provides, take care of, do not leak
    private String AppKey="Please apply to express bird website http://www.kdniao.com/ServiceApply.aspx";
    //Request url
    private String ReqURL="http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx";    
 
    /**
     * Json Way to Query Order Logistics Trajectory
     * @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);    
        
        //Processing the returned information according to the company's business...
        
        return result;
    }
    
    /**
     * XML Way to Query Order Logistics Trajectory
     * @throws Exception 
     */
    public String getOrderTracesByXml() throws Exception{
        String requestData= "<?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>();
        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);    
        
        //Processing the returned information according to the company's business...
        
        return result;
    }
 
    /**
     * MD5 encryption
     * @param str content       
     * @param charset Coding 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 Code
     * @param str content       
     * @param charset Coding 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;
    }
    
    /**
     * Sign Signature Generation in E-commerce
     * @param content content   
     * @param keyValue Appkey  
     * @param charset Coding method
     * @throws UnsupportedEncodingException ,Exception
     * @return DataSign autograph
     */
    @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 a POST method to a specified URL     
     * @param url The URL to send the request    
     * @param params Request parameter set     
     * @return RESPONSE RESULTS 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, you must set the following two lines
            conn.setDoOutput(true);
            conn.setDoInput(true);
            // POST Method
            conn.setRequestMethod("POST");
            // Setting Common 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();
        }
        //Close the output and input streams using the final block
        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(); 
    }
}

Topics: Java xml JSON encoding