圆通的接口:http://www.yto.net.cn/api/trace/waybill
请求方式
下面是java请求示例
1 /** 2 * 根据物流单号查询圆通的物流 3 * @param request 4 * @return 5 */ 6 @ResponseBody 7 @RequestMapping("/logisticsByWaybillYTO") 8 public LogisticsInfo logisticsByWaybillYTO(HttpServletRequest request){ 9 LogisticsInfo logisticsInfo = new LogisticsInfo(); 10 String waybillNo = request.getParameter("waybillCode");// 要查询的快递单号,请勿带特殊符号,不支持中文(大小写不敏感) 11 if (StringUtils.isBlank(waybillNo)) { 12 log.warn("快递单号不能为空----->waybillNo:" + waybillNo); 13 logisticsInfo.setState(1); 14 return logisticsInfo; 15 } 16 try { 17 18 Map<String,String> header = new HashMap<>(); 19 header.put("Content-Type","application/x-www-form-urlencoded"); 20 Map<String,String> body = new HashMap<>(); 21 body.put("waybillNo",waybillNo); 22 String postURL = HttpUtils.httpPostWithForm(YTOURL,header,body); 23 YTOLogisticsEntity ytoENtity = JSON.parseObject(postURL, YTOLogisticsEntity.class); 24 log.warn("圆通返回的物流信息:------>"+postURL); 25 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 26 //将物流信息转为LogisticsInfo类进行返回 27 List<YTOLogisticsInfo.data> traces = ytoENtity.getData().get(0).getTraces(); 28 List<LogisticsInfo.Info> ytInfo= new ArrayList<>(); 29 for (YTOLogisticsInfo.data t : traces){ 30 LogisticsInfo.Info info = new LogisticsInfo.Info(); 31 info.setOpeTime(sdf.format(t.getTime())); 32 if (null!=t.getStationName()){ 33 info.setOpeTitle(t.getStationName()); 34 } 35 info.setOpeRemark(t.getInfo()); 36 ytInfo.add(info); 37 } 38 logisticsInfo.setCourier(traces.get(0).getName()); 39 logisticsInfo.setCourierTel(traces.get(0).getMobile()); 40 logisticsInfo.setInfo(ytInfo); 41 }catch (Exception e){ 42 log.error("获取查询物流跟踪消息 的返回值过程中出错", e); 43 logisticsInfo.setState(1); 44 return logisticsInfo; 45 } 46 if (logisticsInfo.getInfo().size()<1){ 47 log.info("获取查询物流跟踪消息无返回值"); 48 logisticsInfo.setState(1); 49 } 50 return logisticsInfo; 51 }