看快递网有没有提供可用的 API,如果没有可以用 curl 或其他相应技术提交带有定单号的POST数据,并分析返回的数据

解决方案 »

  1.   

    这个很简单的 ,关键是订单和快递号谁维护,如果是自已,很简单的,查这个订单号的快递号和信息
    如果快递信息是快递公司维护的,一般而且,快递公司也应自已的业务号,你可查快递公司的业务号和信息
    订单号 ----快递公司----快递公司的业务号你根据快递公司给你的业务号,在后台查询该定单的快递信息(curl或其他),但后返给客户
      

  2.   

      有一个接口,不但能实现你所说的功能,还能直接在你自己的网站上就能显示出查询的结果,根本不用点链接跳转,当用户点击进入“我的订单”时就能直接看到订单的物流跟踪状况,就像淘宝的的物流跟踪一样:http://code.google.com/p/kuaidi-api/wiki/Open_API_API_URL。
      现在拍拍也在用这个,这里可以看到拍拍使用的效果:http://www.kuaidi100.com/app/paipai.shtml实现起来也很简单:
    (1)向上述的接口提交请求,请求时带上快递公司、快递单号等参数就行;
    (2)获得结果,
    (3)解析结果,将结果显示出来以下是Java实例:
    URL url= new URL("http://api.kuaidi100.com/api?id=XXXX&com=tiantian&nu=11111&show=2&muti=1&order=desc");
    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 || type.trim().indexOf("text/html") < 0)
        return ;    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);
       while (numRead != -1) {
        numRead = urlStream.read(b);
        if (numRead != -1) {
         //String newContent = new String(b, 0, numRead);
         String newContent = new String(b, 0, numRead, charSet);
         content += newContent;
        }
       }
       //System.out.println("content:" + content);
       urlStream.close();