|
@@ -1,6 +1,7 @@
|
|
|
package com.iamberry.rst.utils;
|
|
|
|
|
|
import com.iamberry.wechat.tools.HttpClient431Util;
|
|
|
+import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
@@ -141,7 +142,7 @@ public class KuaiDi100 {
|
|
|
*/
|
|
|
public static void main(String[] agrs){
|
|
|
KuaiDi100 kuaidi = new KuaiDi100();
|
|
|
- System.out.println(kuaidi.getExpressInfo("ems","9754210807242"));
|
|
|
+ System.out.println(kuaidi.selectCourierCompany2("yuantong","yt9053971537384"));
|
|
|
}
|
|
|
/**
|
|
|
* 查询快递信息
|
|
@@ -149,6 +150,59 @@ public class KuaiDi100 {
|
|
|
* @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
|
|
@@ -389,6 +443,31 @@ public class KuaiDi100 {
|
|
|
}
|
|
|
return courierCompang;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 百度快递查询
|
|
|
+ * 根据物流单号查询快递信息 state 0在途,1揽收,2疑难,3签收,4退签,5派件,6退回
|
|
|
+ * @param code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject selectCourierCompany2(String code,String num) {
|
|
|
+ num = num.toLowerCase();
|
|
|
+ JSONObject json = null;
|
|
|
+ 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);
|
|
|
+ /*String s = json.getString("status");*/
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ LOGGER.info("=========快递单号:"+code+";处理报错");
|
|
|
+ }
|
|
|
+ return json;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 写入文件
|