|
接口信息 |
物流轨迹查询 |
请求方式:GET 地址:https://chawuliu.market.alicloudapi.com/query |
复 制 |
请求参数: (Body) |
字段名 |
变量名 |
必填 |
类型 |
示例值 |
描述 |
快递单号 |
kddh |
是 |
String(20) |
JT3084743373888 |
快递单号 |
快递代码 |
code |
否 |
String(20) |
zhongtong |
快递代码 |
4位手机尾号 |
tel |
否 |
String(14) |
8888 |
例如顺丰快递,需传入4位收/发件人手机尾号(非必传) |
API地址为https://chawuliu.market.alicloudapi.com/query,发起GET请求时,请确保在header中设置Authorization字段,格式为Authorization: APPCODE <您的AppCode>,其中<您的AppCode>替换为实际AppCode。注意:APPCODE与AppCode间有空格。
|
成功响应示例: |
|
成功报文解析: |
{
"ok": 1,
"msg": "查询成功",
"status": 2,
"kdmc": "中通快递",
"kddh": "78627****758",
"data": [{
"time": "2022-10-27 19:18:40",
"content": "【泉州市】 快件离开 【福建营销部】 已发往 【泉州中转部】"
}, {
"time": "2022-10-27 19:13:12",
"content": "【泉州市】 【福建营销部】(189*****0) 的 舒宝(189*****0) 已揽收"
}]
}
|
|
字段名 |
类型 |
示例值 |
描述 |
ok |
number |
1
|
成功标识:1成功,0失败
|
msg |
string |
查询成功
|
报文成败描述
|
status |
number |
2
|
状态码
|
kdmc |
string |
中通快递
|
快递名称
|
kddh |
string |
78627****758
|
快递单号
|
data |
array |
[...]
|
查询结果数据包
|
time |
string |
2022-10-27 19:18:40
|
跟踪时间
|
content |
string |
【泉州市】 快件离开 【福建营销部】 已发往 【泉州中转部】
|
跟踪内容 |
|
失败响应示例: |
|
失败报文解析: |
{
"ok": 0,
"msg": "请传入快递单号【kddh字段】",
"status": 0,
"kdmc": "",
"kddh": "",
"data": []
}
|
|
字段名 |
类型 |
示例值 |
描述 |
ok |
number |
0 |
成功标识:1成功,0失败 |
msg |
string |
请传入快递单号【kddh字段】
|
报文成败描述 |
|
|
|
PHP代码 |
注意AppCode安全,验证API参数,处理HTTPS请求时禁用证书验证风险。 |
复 制 |
|
<?php
$host = "https://aliyun03.muzhiapi.com";
$path = "/query";
$method = "GET";
$appcode = "你自己的AppCode";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$querys = "kddh=JT3009406646575&code=code&tel=tel";
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
var_dump(curl_exec($curl));
?>
|
|
Java代码 |
注意API URL、AppCode正确性,并确保处理HTTPS请求时SSL验证配置。 |
复 制 |
|
public static void main(String[] args) {
String host = "https://aliyun03.muzhiapi.com";
String path = "/query";
String method = "GET";
String appcode = "你自己的AppCode";
Map headers = new HashMap();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
Map querys = new HashMap();
querys.put("kddh", "JT3009406646575");
querys.put("code", "code");
querys.put("tel", "tel");
try {
/**
* 重要提示如下:
* HttpUtils请从
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
* 下载
*
* 相应的依赖请参照
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
*/
HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
System.out.println(response.toString());
//获取response的body
//System.out.println(EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
|
|
C#代码 |
注意处理HTTPS请求时的SSL证书验证,确保AppCode和URL正确性。 |
复 制 |
|
//using System.IO;
//using System.Text;
//using System.Net;
//using System.Net.Security;
//using System.Security.Cryptography.X509Certificates;
private const String host = "https://aliyun03.muzhiapi.com";
private const String path = "/query";
private const String method = "GET";
private const String appcode = "你自己的AppCode";
static void Main(string[] args)
{
String querys = "kddh=JT3009406646575&code=code&tel=tel";
String bodys = "";
String url = host + path;
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
if (0 < querys.Length)
{
url = url + "?" + querys;
}
if (host.Contains("https://"))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = method;
httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
if (0 < bodys.Length)
{
byte[] data = Encoding.UTF8.GetBytes(bodys);
using (Stream stream = httpRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
}
catch (WebException ex)
{
httpResponse = (HttpWebResponse)ex.Response;
}
Console.WriteLine(httpResponse.StatusCode);
Console.WriteLine(httpResponse.Method);
Console.WriteLine(httpResponse.Headers);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("\n");
}
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
|
|
Python代码 |
urllib2在Python 3中已被弃用,Python 3用户应使用urllib.request模块。 |
复 制 |
|
import urllib, urllib2, sys
import ssl
host = 'https://aliyun03.muzhiapi.com'
path = '/query'
method = 'GET'
appcode = '你自己的AppCode'
querys = 'kddh=JT3009406646575&code=code&tel=tel'
bodys = {}
url = host + path + '?' + querys
request = urllib2.Request(url)
request.add_header('Authorization', 'APPCODE ' + appcode)
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urllib2.urlopen(request, context=ctx)
content = response.read()
if (content):
print(content)
|
|
ObjectC代码 |
拼接URL时,?开头查询字符串可行。建议使用NSURLComponents。缓存策略按需设,超时时间可调。 |
复 制 |
|
NSString *appcode = @"你自己的AppCode";
NSString *host = @"https://aliyun03.muzhiapi.com";
NSString *path = @"/query";
NSString *method = @"GET";
NSString *querys = @"?kddh=JT3009406646575&code=code&tel=tel";
NSString *url = [NSString stringWithFormat:@"%@%@%@", host, path , querys];
NSString *bodys = @"";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: url] cachePolicy:1 timeoutInterval: 5];
request.HTTPMethod = method;
[request addValue: [NSString stringWithFormat:@"APPCODE %@" , appcode] forHTTPHeaderField: @"Authorization"];
NSURLSession *requestSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionDataTask *task = [requestSession dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable body , NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"Response object: %@" , response);
NSString *bodyString = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding];
//打印应答中的body
NSLog(@"Response body: %@" , bodyString);
}];
[task resume];
|
|
curl代码 |
|
复 制 |
|
curl -i -k --get --include 'https://aliyun03.muzhiapi.com/query?kddh=JT3009406646575&code=code&tel=tel' -H 'Authorization:APPCODE 你自己的AppCode'
|