通过寄件地址、收件地址和重量,预估快递公司的运费,目前支持顺丰、京东、德邦、圆通、中通、申通、韵达、ems
无参数
无参数
名称 | 类型 | 是否必须 | 描述 |
---|---|---|---|
secret_key | string | true | 用户授权key |
secret_code | string | true | 接口编号 |
secret_sign | string | true | 加密签名:md5(secret_key+secret_secret)转大写 |
companyName | string | true | 快递公司编码 |
sendAddr | string | true | 寄件地址 |
receiveAddr | string | true | 收件地址 |
weight | double | true | 重量,默认单位为kg,参数无需带单位,如1.0 |
curl http://cloud.kuaidi100.com/api -X POST -d \
"secret_key=***&secret_code=87aff9cff2ff431c8c6280a7eb2b7f09&secret_sign=md5(***)&companyName=jd&sendAddr=%E5%B9%BF%E4%B8%9C%E7%9C%81%E6%B7%B1%E5%9C%B3%E5%B8%82%E5%8D%97%E5%B1%B1%E5%8C%BA%E7%B2%A4%E6%B5%B7%E8%A1%97%E9%81%93&receiveAddr=%E5%B9%BF%E4%B8%9C%E7%9C%81%E6%B7%B1%E5%9C%B3%E5%B8%82%E5%8D%97%E5%B1%B1%E5%8C%BA%E7%B2%A4%E6%B5%B7%E8%A1%97%E9%81%93&weight=1.0"
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", "87aff9cff2ff431c8c6280a7eb2b7f09");
params.put("secret_sign", "md5(***)");
params.put("companyName", "jd");
params.put("sendAddr", "广东省深圳市南山区粤海街道");
params.put("receiveAddr", "广东省深圳市南山区粤海街道");
params.put("weight", "1.0");
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=87aff9cff2ff431c8c6280a7eb2b7f09'.'&';
$params .= 'secret_sign=md5(***)'.'&';
$params .= 'companyName=jd'.'&';
$params .= 'sendAddr=%E5%B9%BF%E4%B8%9C%E7%9C%81%E6%B7%B1%E5%9C%B3%E5%B8%82%E5%8D%97%E5%B1%B1%E5%8C%BA%E7%B2%A4%E6%B5%B7%E8%A1%97%E9%81%93'.'&';
$params .= 'receiveAddr=%E5%B9%BF%E4%B8%9C%E7%9C%81%E6%B7%B1%E5%9C%B3%E5%B8%82%E5%8D%97%E5%B1%B1%E5%8C%BA%E7%B2%A4%E6%B5%B7%E8%A1%97%E9%81%93'.'&';
$params .= 'weight=1.0'.'&';
$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'] = '87aff9cff2ff431c8c6280a7eb2b7f09'
params['secret_sign'] = 'md5(***)'
params['companyName'] = 'jd'
params['sendAddr'] = '广东省深圳市南山区粤海街道'
params['receiveAddr'] = '广东省深圳市南山区粤海街道'
params['weight'] = '1.0'
result = requests.post('http://cloud.kuaidi100.com/api', params)
print(result.text)
无参数
{
"status": "200",
"message": "ok",
"data": {
"com": "jd",
"combos": [
{
"price": 16.0,
"productName": "特惠送"
}
]
}
}
{
"status": "201",
"message": "无快递产品或该地未开通查询业务",
"data": {
"com": "jd",
"combos": []
}
}
状态码 | 状态码信息 | 描述 |
---|---|---|
201 | 无快递产品或该地未开通查询业务 |
通过寄件地址、收件地址和重量,预估快递公司的运费。
温馨提示:该接口返回的价格为预估价格,用于页面展示时,建议加上“预估价格”或者“预测价格”;实际价格以快递公司实际产生的费用为准。
目前支持的快递公司:
顺丰:shunfeng
京东:jd
德邦快递:debangkuaidi
圆通:yuantong
中通:zhongtong
申通:shentong
韵达:yunda
ems:ems