一、首先去快递100页面注册唯一性ID
二、选择自己觉得好用的接口,(有一个接口很坑,主流的快递都不能查询),大家注意
三、代码块
//获得快递100的查询地址
private String searchkuaiDiInfo(String id)
{
OrderForm obj = this.orderFormService
.getObjById(CommUtil.null2Long(id));
String content = "";
try{
URL url = new URL("http://www.kuaidi100.com/applyurl?key="
+ this.configService.getSysConfig().getKuaidi_id()
+ "&com="
+ (obj.getEc() != null ? obj.getEc().getCompany_mark() : "")
+ "&nu="
+ obj.getShipCode()
);
URLConnection con = url.openConnection();
con.setAllowUserInteraction(false);
InputStream urlStream = url.openStream();
byte b[] = new byte[10000];
int numRead = urlStream.read(b);
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, "UTF-8");
content += newContent;
}
}
urlStream.close();
} catch (Exception e)
{
e.printStackTrace();
}
//System.out.println(content);
return content;
}
这儿是根据快递单号获取快递信息,快递100返回的是一个地址,然后,我们开发人员将这个地址嵌入到自己的页面即可,完了我们就可以看到对应的快递编号的物流信息了,这个页面有快递100的广告。