这个相关资料比较少,写出来给有需要的人吧
事先说明,没有试过自己申请免费版的情况,如果有不对的地方请纠正,H5/APP接入自己看文档去吧
访问快递100的官网然后查看他的接入技术文档
官网地址:https://www.kuaidi100.com/openapi/api_post.shtml
如果你按照这个步骤你会发现根本走不通
首先这个id我是真的不知道是什么鬼,企业版只提供了key和一个customer,没有上面所谓的id
下面说下正确调用姿势吧
String param ="{\"com\":\"***\",\"num\":\"***\"}";//com 快递公司标识,num:快递单号
String customer ="***";//这是申请下来的公钥
String key = "****";//这是申请下来的私钥
String sign = MD5.encode(param+key+customer);//md5加密
HashMap<String, String> params = new HashMap<String, String>();
params.put("param",param);
params.put("sign",sign);
params.put("customer",customer);
String resp;
try {
resp = new HttpRequest().postData("http://poll.kuaidi100.com/poll/query.do", params, "utf-8").toString();
System.out.println(resp);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MD5加密算法
private static MessageDigest _mdInst = null;
private static char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
private static MessageDigest getMdInst() {
if (_mdInst == null) {
try {
_mdInst = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new AppException(e);
}
}
return _mdInst;
}
public static String encode(String s) {
try {
byte[] btInput = s.getBytes();
// 使用指定的字节更新摘要
getMdInst().update(btInput);
// 获得密文
byte[] md = getMdInst().digest();
// 把密文转换成十六进制的字符串形式
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
throw new AppException(e);
}
}
最后再说下官方提供的参数问题
快递单号:nu改成num
muti | String | 是 | 返回信息数量: 1:返回多行完整的信息, 0:只返回一行信息。 不填默认返回多行。 |
这个传过去是无效的,正确写法我也不知道
其它的都可以正常使用