|
@@ -1,6 +1,5 @@
|
|
|
package com.iamberry.rst.core.tools;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.iamberry.wechat.tools.HttpClient431Util;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
@@ -30,8 +29,7 @@ public class KuaiDi100 {
|
|
|
private static Logger LOGGER = LoggerFactory.getLogger(KuaiDi100.class);
|
|
|
|
|
|
private static String key = "29833628d495d7a5";//授权密匙key 百度的
|
|
|
- /*private static String key = "06d6c2ea1bdb4ee9";//授权密匙key 自己的*/
|
|
|
-
|
|
|
+ /*private static String key = "06d6c2ea1bdb4ee9";*///授权密匙key 自己的
|
|
|
//快递鸟 电商ID
|
|
|
private static final String EBusinessID="1343593";
|
|
|
//电商加密私钥,快递鸟提供
|
|
@@ -112,6 +110,9 @@ public class KuaiDi100 {
|
|
|
case "dbkd":
|
|
|
code = "debangwuliu";
|
|
|
break;
|
|
|
+ case "hoau":
|
|
|
+ code = "tiandihuayu";
|
|
|
+ break;
|
|
|
case "lianhaowuliu":
|
|
|
code = "lianhaowuliu";
|
|
|
break;
|
|
@@ -133,74 +134,20 @@ public class KuaiDi100 {
|
|
|
* 邮政国际包裹 youzhengguoji
|
|
|
* EMS国际快递 emsguoji
|
|
|
*/
|
|
|
-
|
|
|
/**
|
|
|
* 查询快递信息
|
|
|
* @param com 快递公司代码
|
|
|
* @param nu 快递单号
|
|
|
* @return
|
|
|
*/
|
|
|
- public JSONObject getExpressInfo2(String com , String nu){
|
|
|
- JSONObject ret = null;
|
|
|
- try
|
|
|
- {
|
|
|
- com = logisticsConversions(com);
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?cb=abc&appid=4001");
|
|
|
- sb.append("&com=").append(com);
|
|
|
- sb.append("&nu=").append(nu);
|
|
|
- URL url= new URL(sb.toString());
|
|
|
- URLConnection con=url.openConnection();
|
|
|
- con.setAllowUserInteraction(false);
|
|
|
- InputStream urlStream = url.openStream();
|
|
|
- String type = con.guessContentTypeFromStream(urlStream);
|
|
|
- String charSet=null;
|
|
|
- if (type == null)
|
|
|
- type = con.getContentType();
|
|
|
-
|
|
|
- if (type == null || type.trim().length() == 0)
|
|
|
- return null;
|
|
|
-
|
|
|
- if(type.indexOf("charset=") > 0)
|
|
|
- charSet = type.substring(type.indexOf("charset=") + 8);
|
|
|
-
|
|
|
- byte b[] = new byte[10000];
|
|
|
- int numRead = urlStream.read(b);
|
|
|
- String content = new String(b, 0, numRead, "UTF-8");
|
|
|
- while (numRead != -1) {
|
|
|
- numRead = urlStream.read(b);
|
|
|
- if (numRead != -1) {
|
|
|
- //String newContent = new String(b, 0, numRead);
|
|
|
- String newContent = new String(b, 0, numRead, "UTF-8");
|
|
|
- content += newContent;
|
|
|
- }
|
|
|
- }
|
|
|
- content = content.replaceAll(":null", ":\"\"");
|
|
|
- ret = JSONObject.fromObject(content);
|
|
|
- System.out.println(ret);
|
|
|
- urlStream.close();
|
|
|
- } catch (MalformedURLException e)
|
|
|
- {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e)
|
|
|
- {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return ret;
|
|
|
- }/**
|
|
|
- * 查询快递信息
|
|
|
- * @param com 快递公司代码
|
|
|
- * @param nu 快递单号
|
|
|
- * @return
|
|
|
- */
|
|
|
public JSONObject getExpressInfo(String com , String nu){
|
|
|
JSONObject ret = null;
|
|
|
try
|
|
|
{
|
|
|
com = logisticsConversions(com);
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("http://api.kuaidi100.com/api?id=");
|
|
|
- sb.append(KuaiDi100.key);
|
|
|
+ sb.append("https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?cb=jQuery110204759692032715892_1499865778178&appid=4001");
|
|
|
+ /*sb.append(KuaiDi100.key);*/
|
|
|
sb.append("&com=").append(com);
|
|
|
sb.append("&nu=").append(nu);
|
|
|
sb.append("&show=0&muti=1&order=desc");
|
|
@@ -436,75 +383,74 @@ public class KuaiDi100 {
|
|
|
/**
|
|
|
* 百度快递查询
|
|
|
* 根据物流单号查询快递信息 state 0在途,1揽收,2疑难,3签收,4退签,5派件,6退回
|
|
|
- * @param code
|
|
|
+ * @param
|
|
|
* @return
|
|
|
*/
|
|
|
- public JSONObject selectCourierCompany2(String code,String num) {
|
|
|
- num = num.toLowerCase();
|
|
|
- JSONObject json = null;
|
|
|
- if(code.toLowerCase().equals("sf") || code.toLowerCase().equals("shunfeng")){
|
|
|
- KuaiDi100 kuaidi = new KuaiDi100();
|
|
|
- String result = null;
|
|
|
- try {
|
|
|
- result = kuaidi.selectCourierSF("SF", num);
|
|
|
- if(result != null){
|
|
|
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- JSONObject jn = JSONObject.fromObject(result);
|
|
|
- String state = jn.getString("State");
|
|
|
- JSONArray context = jn.getJSONArray("Traces");
|
|
|
- Map<String,Object> msg = new HashMap<>();
|
|
|
- Map<String,Map<String,Object>> data = new HashMap<>();
|
|
|
- Map<String,Object> info = new HashMap<>();
|
|
|
- List<HashMap> list = new ArrayList<>();
|
|
|
- for(int i=context.size()-1;i >= 0;i--){
|
|
|
- JSONObject job = context.getJSONObject(i);
|
|
|
- HashMap<String,String> map = new HashMap<>();
|
|
|
-
|
|
|
- map.put("time",String.valueOf((sf.parse(job.getString("AcceptTime")).getTime()) /1000));
|
|
|
- map.put("desc",job.getString("AcceptStation"));
|
|
|
- list.add(map);
|
|
|
- }
|
|
|
- info.put("state",state);
|
|
|
- info.put("context",JSONArray.fromObject(list));
|
|
|
- data.put("info",info);
|
|
|
- msg.put("status","0");
|
|
|
- msg.put("data",JSONObject.fromObject(data));
|
|
|
- json = JSONObject.fromObject(msg);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }else{
|
|
|
- try {
|
|
|
- Map<String, String> params = new HashMap<String, String>();
|
|
|
- String cookie = "BAIDUID=E157C876272626E1F7F498C10A6A3F00:FG=1";
|
|
|
- String url = "https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?cb=cb&appid=4001&nu="+num+"&com="+code;
|
|
|
- // 发送请求
|
|
|
- String html = HttpClient431Util.doGet2(params, url,cookie);
|
|
|
- String content = html.substring(7, html.length());
|
|
|
- content = content.substring(0, content.length()-1);
|
|
|
- json = JSONObject.fromObject(content);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- LOGGER.info("=========快递单号:"+code+";处理报错");
|
|
|
+ public JSONObject selectCourierCompany2(LogisticsInfo logisticsInfo,String num) {
|
|
|
+ // 调用百度的接口
|
|
|
+ /*try {
|
|
|
+ *//*String temp = logisticsConversions(code.toLowerCase());*//*
|
|
|
+ String baiduURL = "https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?cb=cb&appid=4001&nu="+num+"&com="+logisticsInfo.getLogisticsOnehundredCode();
|
|
|
+ String result = HttpClient431Util.doGet2(null, baiduURL,"BAIDUID=E157C876272626E1F7F498C10A6A3F00:FG=1");
|
|
|
+ String content = result.substring(7, result.length());
|
|
|
+ content = content.substring(0, content.length()-1);
|
|
|
+ JSONObject json = JSONObject.fromObject(content);
|
|
|
+ String state = json.getString("status");
|
|
|
+ if("0".equals(state) || "1".equals(state) || "2".equals(state) || "3".equals(state) || "4".equals(state) || "5".equals(state) || "6".equals(state)){
|
|
|
+ return json;
|
|
|
}
|
|
|
- }
|
|
|
+ } catch (Exception e) {
|
|
|
+ LoggerFactory.getLogger(KuaiDi100.class).error("", e);
|
|
|
+ }*/
|
|
|
+ // 调用快递鸟的接口
|
|
|
+ try {
|
|
|
+ String result = selectCourierSF(logisticsInfo.getLogisticsRstCode().toUpperCase(), num);
|
|
|
+ JSONObject jn = JSONObject.fromObject(result);
|
|
|
+ Map<String,Object> msg = new HashMap<>();
|
|
|
+ Map<String,Map<String,Object>> data = new HashMap<>();
|
|
|
+ if (result != null && jn.getInt("State") != 0) {
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String state = jn.getString("State");
|
|
|
+ JSONArray context = jn.getJSONArray("Traces");
|
|
|
|
|
|
|
|
|
- return json;
|
|
|
+ Map<String,Object> info = new HashMap<>();
|
|
|
+ List<HashMap> list = new ArrayList<>();
|
|
|
+ for(int i=context.size()-1;i > 0;i--){
|
|
|
+ JSONObject job = context.getJSONObject(i);
|
|
|
+ HashMap<String,String> map = new HashMap<>();
|
|
|
+ map.put("time",String.valueOf((sf.parse(job.getString("AcceptTime")).getTime()) /1000));
|
|
|
+ map.put("desc",job.getString("AcceptStation"));
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ info.put("state",state);
|
|
|
+ info.put("context",JSONArray.fromObject(list));
|
|
|
+ data.put("info",info);
|
|
|
+ msg.put("status","0");
|
|
|
+ msg.put("data",JSONObject.fromObject(data));
|
|
|
+ return JSONObject.fromObject(msg);
|
|
|
+ }else{
|
|
|
+ msg.put("status","-1");
|
|
|
+ msg.put("data",JSONObject.fromObject(data));
|
|
|
+ return JSONObject.fromObject(msg);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ LoggerFactory.getLogger(KuaiDi100.class).error("", e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 百度快递查询签收时间
|
|
|
* 根据物流单号查询快递信息 state 0在途,1揽收,2疑难,3签收,4退签,5派件,6退回
|
|
|
- * @param code
|
|
|
+ * @param
|
|
|
* @return
|
|
|
*/
|
|
|
- public Date selectCourierSignTime(String code, String num){
|
|
|
+ public Date selectCourierSignTime(LogisticsInfo logisticsInfo, String num){
|
|
|
JSONObject json = null;
|
|
|
for(int i = 0; i < 3; i++){
|
|
|
- json = selectCourierCompany2(code,num);
|
|
|
- if(json.getString("status").equals("0")){
|
|
|
+ json = selectCourierCompany2(logisticsInfo,num);
|
|
|
+ if(json == null || json.getString("State").equals("0")){
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -530,17 +476,19 @@ public class KuaiDi100 {
|
|
|
/**
|
|
|
* 百度快递查询签收时间 - 查询揽件时间
|
|
|
* 根据物流单号查询快递信息 state 0在途,1揽收,2疑难,3签收,4退签,5派件,6退回
|
|
|
- * @param code
|
|
|
+ * @param
|
|
|
* @return
|
|
|
*/
|
|
|
- public Date selectCourierSignCaseTime(String code, String num){
|
|
|
+ public Date selectCourierSignCaseTime(LogisticsInfo logisticsInfo, String num){
|
|
|
JSONObject json = null;
|
|
|
boolean flag = false;
|
|
|
for(int i = 0; i < 3; i++){
|
|
|
- json = selectCourierCompany2(code,num);
|
|
|
+ json = selectCourierCompany2(logisticsInfo,num);
|
|
|
+ if (json == null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
String state = json.getString("status");
|
|
|
- if("0".equals(state) || "1".equals(state) || "2".equals(state) || "3".equals(state) || "4".equals(state)
|
|
|
- || "5".equals(state) || "6".equals(state)){
|
|
|
+ if("0".equals(state) || "1".equals(state) || "2".equals(state) || "3".equals(state) || "4".equals(state) || "5".equals(state) || "6".equals(state)){
|
|
|
flag = true;
|
|
|
break;
|
|
|
}
|
|
@@ -736,33 +684,8 @@ public class KuaiDi100 {
|
|
|
/*System.out.println(kuaidi.selectCourierCompany2("yuantong","yt9053971537384"));*/
|
|
|
/*System.out.println(kuaidi.selectCourierSignTime("yuantong","yt9053971537384"));*/
|
|
|
/*System.out.println(kuaidi.selectCourierSF("106494280800","SF","291003792023"));*/
|
|
|
- try {
|
|
|
- String result = kuaidi.selectCourierSF("SF", "291126767780");
|
|
|
- System.out.print(result);
|
|
|
- if(result != null){
|
|
|
- JSONObject jn = JSONObject.fromObject(result);
|
|
|
- String state = jn.getString("State");
|
|
|
- JSONArray context = jn.getJSONArray("Traces");
|
|
|
- Map<String,String> msg = new HashMap<>();
|
|
|
- Map<String,Map<String,String>> data = new HashMap<>();
|
|
|
- Map<String,String> info = new HashMap<>();
|
|
|
- List<HashMap> list = new ArrayList<>();
|
|
|
- for(int i=context.size()-1;i >= 0;i--){
|
|
|
- JSONObject job = context.getJSONObject(i);
|
|
|
- HashMap<String,String> map = new HashMap<>();
|
|
|
- map.put("time",job.getString("AcceptTime"));
|
|
|
- map.put("desc",job.getString("AcceptStation"));
|
|
|
- list.add(map);
|
|
|
- System.out.println(JSON.toJSONString(list)) ;
|
|
|
- }
|
|
|
- info.put("state",state);
|
|
|
- info.put("context",JSON.toJSONString(list));
|
|
|
- data.put("info",info);
|
|
|
- msg.put("status","0");
|
|
|
- msg.put("data",JSON.toJSONString(data));
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ /*System.out.println(kuaidi.getExpressInfo("shentong","221510432233"));*/
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|