Electricity supplier site logistics and express a single query api Application Interface Case

[Scene demand Description

Electronic business platform and ISV business demand for logistics api interface, there are many, and today we share is the main docking guide birds express courier single query interface number, express a single query interface docking scenarios are many, many scenes encounter, the most important is called when the user opens the electricity supplier website "my orders" this API to display details of logistics information, the electricity supplier logistics system management background, the status of all customer service inquiries sign the waybill before reconciliation, and tracing, electronic business platform to-business logistics management and control requirements must embrace the pieces must be sent to see how long the express condition, to see how long the goods receipt must be received by the state, according to the state of business control and improve overall user satisfaction.
Electricity supplier site logistics and express a single query api Application Interface Case
[Butt] using flow

1, register an account and apply for certification birds Express

2, express logistics birds query to track state based on a single number and courier companies

3, the bird will express logistics queries to track back to the state electricity provider platform for service providers or ISV

4, electronic business platform ISV ​​or service provider receives the data and do real-time processing or data presentation applications

Express birds very powerful, free, you can query the express track at any time, you can push the express condition, very powerful very convenient. Direct the implementation code. Code on directly: this is the development of a bird express courier push the interface, the received data processing data. This method must post

@RequestMapping(value = "tuisong",method=RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> tuisong(String RequestData,String RequestType,String DataSign) {
         RequestData=Encodes.unescapeHtml(RequestData);
         Map<String,Object> result=new HashMap<String,Object>();
        //判断是从快递鸟进入
        if(!(RequestType.equals("101") && KdniaoUtils.isFromKdniao(RequestData, DataSign))){
            result.put("Success",false);
            result.put("Reason","不是快递鸟推送来的数据。");
            return result;
        }
        JSONObject jsonObj=new JSONObject(RequestData);
         result.put("EBusinessID",jsonObj.getString("EBusinessID"));
         result.put("UpdateTime",jsonObj.getString("PushTime"));
         try {
             JSONArray jsonArray=jsonObj.getJSONArray("Data");
             List<Ship> shipList=Lists.newArrayList();
             Ship ship=null;
             for(int i=0;i<jsonArray.length();i++){
                jsonObj=jsonArray.getJSONObject(i);
                 if(!jsonObj.getBoolean("Success")){
                     continue;
                 }
                 ship=new Ship();
                 ship.setExpress(ErpUtils.getExpressByKdniao(jsonObj.getString("ShipperCode")));
                 ship.setExpressNo(jsonObj.getString("LogisticCode"));
                 String state=jsonObj.getString("State");
                 ship.setStatus(KdniaoUtils.getShipStatus(state));
                 if(ship.getStatus().equals(Ship.STATUS_SIGN)){
                     JSONArray array=jsonObj.getJSONArray("Traces");
                     JSONObject obj=array.getJSONObject(array.length()-1);
                     String time=obj.getString("AcceptTime");
                     ship.setSignTime(DateUtils.parseDate(time,"yyyy-MM-dd HH:mm:ss"));
                 }
                 shipList.add(ship);
              }
             shipService.updateStatus(shipList);
             result.put("Success", true);
         }catch (Exception e) {
             result.put("Success", false);
             result.put("Reason ", "解析数据失败。");
             e.printStackTrace();
         }
        return result;

Here is a utility class provides static methods. KdniaoUtils.java
`` public class KdniaoUtils {
// the DEMO
public static void main (String [] args) throws UnsupportedEncodingException, Exception {
}
// electricity supplier ID
Private EBusinessID static String = "1283391";
// private key encryption electricity supplier, express offers a bird, take good care not to leak
Private AppKey static String = "9df9507a-62fa-47f3-9227-bdd02b95ccf1";
// request url
Private reqURL static String = " http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle. ASPX ";
public static the Map <String, String> = new new StateMap the HashMap <String, String> ();
static {
StateMap.put (" 0 "," no record ");
StateMap.put (". 1 "," football has income ");
StateMap.put (" 2 "," transit ");

StateMap.put ( "3", "have been received");
StateMap.put ( ". 4", "Problems member");
}
// stream Status: 0-no trace, 1-Lanshou, 2-way 201 - sending pieces arrival city, sign 3-, 4- problems pieces
public static int getShipStatus (String State) {
Switch (State) {
Case "0":
return Ship.STATUS_SHIPPED;
Case ". 1":
return Ship.STATUS_SHIPPED;
Case " 2 ":
return Ship.STATUS_ONTHEWAY;
Case" 201 ":
return Ship.STATUS_PAISONG;
Case". 3 ":
return Ship.STATUS_SIGN;
Case". 4 ":
return Ship.STATUS_DIFFICULT;
default:
return Ship.STATUS_SHIPPED;
}
}
/ **

Guess you like

Origin blog.51cto.com/14466758/2428840