智能判断单号所归属的快递公司;录入单号识别快递公司,提升商家录单体验。 【由于快递公司单号规则不统一,且不断变化,会存在无法识别的情况,该接口命中率为95%左右】
无参数
无参数
名称 | 类型 | 是否必须 | 描述 |
---|---|---|---|
secret_key | string | true | 用户授权key |
secret_code | string | true | 接口编号 |
secret_sign | string | true | 加密签名:md5(secret_key+secret_secret)转大写 |
num | string | true | 快递单号 |
curl http://cloud.kuaidi100.com/api -X POST -d \
"secret_key=***&secret_code=53514ac63f0447d188423221550b0c3e&secret_sign=md5(***)&num="
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
public class CloudDemo {
public static void main (String[] args) {
CloudDemo cloudDemo = new CloudDemo();
Map params = new HashMap();
params.put("secret_key", "***");
params.put("secret_code", "53514ac63f0447d188423221550b0c3e");
params.put("secret_sign", "md5(***)");
params.put("num", "");
cloudDemo.post(params);
}
public String post(Map params) {
StringBuilder response = new StringBuilder("");
BufferedReader reader = null;
try {
StringBuilder builder = new StringBuilder();
for (Map.Entry param : params.entrySet()) {
if (builder.length() > 0) {
builder.append('&');
}
builder.append(URLEncoder.encode(param.getKey(), "UTF-8"));
builder.append('=');
builder.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
byte[] bytes = builder.toString().getBytes("UTF-8");
URL url = new URL("http://cloud.kuaidi100.com/api");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
conn.setRequestMethod("POST");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(bytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(bytes);
reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line = "";
while ((line = reader.readLine()) != null) {
response.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != reader) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return response.toString();
}
}
class MD5Utils { private static MessageDigest mdigest = null;
private static char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
private static MessageDigest getMdInst() {
if (null == mdigest) {
try {
mdigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
return mdigest;
}
public static String encode(String s) {
if(null == s) {
return "";
}
try { byte[] bytes = s.getBytes();
getMdInst().update(bytes);
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++] = digits[byte0 >>> 4 & 0xf];
str[k++] = digits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
暂无示例
<?php
$params = "";
$params .= 'secret_key=***'.'&';
$params .= 'secret_code=53514ac63f0447d188423221550b0c3e'.'&';
$params .= 'secret_sign=md5(***)'.'&';
$params .= 'num='.'&';
$params .= substr($params, 0, -1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, 'http://cloud.kuaidi100.com/api');
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
echo $result;
?>
# coding = utf-8
import sys,os
import requests,json,hashlib
params = {}
params['secret_key'] = '***'
params['secret_code'] = '53514ac63f0447d188423221550b0c3e'
params['secret_sign'] = 'md5(***)'
params['num'] = ''
result = requests.post('http://cloud.kuaidi100.com/api', params)
print(result.text)
无参数
[
{
"lengthPre": 15,
"comCode": "debangwuliu",
"name": "德邦"
},
{
"lengthPre": 15,
"comCode": "debangkuaidi",
"name": "德邦快递"
}
]
{ "returnCode": "400", "message": "参数错误", }
状态码 | 状态码信息 | 描述 |
---|---|---|
400 | 参数错误 |
快递公司编码表格:http://api.kuaidi100.com/manager/openapi/download/kdbm.do
注意:
由于运单号规则不断变化且各个快递公司没有标准、统一的规则,现有机制是通过快递100积累的海量数据进行智能分析得出相关规则并且每天更新,所以无法保证判断准确率能达到100%。我方不会对本接口的准确性、有效性等提供法律层面上的承诺。若贵司将此服务向最终用户提供,建议贵司在展现给用户时加上如下提示:
判断结果后加上一句 “由快递100猜测”等带“猜测”字样的文字说明;
所选的公司可由用户重新手动修改;
在判断结果后提示“本结果仅供参考”等文字说明。