利用快递100来获取快递信息,和中间遇到的坑
public static void main(String[] args) throws Exception {
//com 为快递公司,以圆通为例;num为快递单号;这两个为必要参数
String param ="{\"com\":\"yuantong\",\"num\":\"快递单号\"}";
//customer与key可以通过快递100的管理后台获取
String customer ="自己的customer";
String key = "自己的key";
//这边需要注意采用Md5加密后,需要把加密的结果转成大写
String sign = MD5Util.encode(param+key+customer);
sign=sign.toUpperCase();
//这边有一个坑,这边使用的是RestTemplate的postForObject方法
//不能够使用HashMap,需要换成MultiValueMap
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("param",param);
params.add("sign",sign);
params.add("customer",customer);
String resp;
try {
RestTemplate s=new RestTemplate();
resp =s.postForObject("http://poll.kuaidi100.com/poll/query.do", params, String.class);
System.out.println(resp);
} catch (Exception e) {
e.printStackTrace();
}
}
至于为什么RestTemplate不能够使用HashMap可以参考https://www.cnblogs.com/shoren/p/RestTemplate-problem.html