加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

获取圆通的物流信息

发布时间:2020-12-15 07:51:08 所属栏目:Java 来源:网络整理
导读:圆通的接口:http://www.yto.net.cn/api/trace/waybill ? 请求方式 ? ? ? ? ? 下面是java请求示例 1 /** 2 * 根据物流单号查询圆通的物流 3 * @param request 4 * @return 5 */ 6 @ResponseBody 7 @RequestMapping("/logisticsByWaybillYTO" ) 8 public Logi

圆通的接口: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     }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读