查询运单轨迹接口返回的节点不是实时的,接口:POST https://api.weixin.qq.com/cgi-bin/express/business/path/get?access_token=ACCESS_TOKEN
代码片段:String token = redisCache.getCacheObject("access_tokenWx");
//expressPathUrl="https://api.weixin.qq.com/cgi-bin/express/business/path/get?access_token=";
String url = StringConstant.expressPathUrl + token;
JSONObject jsonObject = new JSONObject();
jsonObject.put("order_id", wxWaybill.getOrderId());
jsonObject.put("openid", wxWaybill.getOpenId());
jsonObject.put("delivery_id", wxWaybill.getDeliveryId());
jsonObject.put("waybill_id", wxWaybill.getWaybillId());
// 设置请求头,指定内容类型为 JSON,并且编码为 UTF-8
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Accept-Charset", "UTF-8");
HttpEntity<String> requestEntity = new HttpEntity<>(jsonObject.toString(), headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
String body = responseEntity.getBody();
// 解析为JSON对象时,确保字符串使用正确的编码
byte[] bytes = body.getBytes(StandardCharsets.ISO_8859_1);
String utf8Body = new String(bytes, StandardCharsets.UTF_8);
return JSONObject.parseObject(utf8Body);
返回的节点为:
下面是实际的物流消息
