丰⽹速运单号查询快递鸟API接⼝-丰⽹速运
前⾔
顺丰斥资1000万成⽴深圳丰⽹速运有限公司。其中,顺丰速运出资800万,持股80%,中⾦出资200万,持股20%。
据悉,该公司成⽴时间为2020年4⽉7⽇,法⼈代表为吴国忠,杨尊淼、李祥乐任董事,马⽴军任监事。
经营范围包括:国际货运代理;经济技术咨询;技术信息咨询;以特许经营⽅式从事商业活动;经营进出⼝业务;机械设备租赁;汽车租赁;房屋租赁业务;商务服务、商务代理;过境货物运输代理;3C产品检测、维修服务。许可经营项⽬是:国内、国际快递;国际供应链;普通货运;货物专⽤运输,⼤型物件运输;仓储服务。
接下来给⼤家讲解⼀下如何对接丰⽹速运的快递查询接⼝。
调⽤快递鸟的丰⽹速运查询API接⼝,能查询到丰⽹速运单号从收件、运输,到转运中⼼,派送到签收等各个环节的物流发货状态。快递鸟api接⼝不区分开发语⾔,⽀持Java,C#,PHP,Python,ObjectC等开发语⾔的程序调⽤。下⾯具体讲解实现过程.
⽬录
1.完成前期准备⼯作
1.1,去快递鸟官⽹⼀个账号
1.2,免费获得⼀个apiKey(接⼝权限验证需要)
1.3,完成实名认证流程
1.4,订购⼀个免费套餐
2.API接⼝
2.3,请求⽅式:POST
2.4,编码格式(utf-8):application/x-www-form-urlencoded;charset=utf-8
2.5,返回类型:JSON
2.7,调试⼯具:去调试(使⽤快递鸟账号登录)
3.请求参数(Headers)
参数名称类型说明必须要求
RequestData String请求内容需进⾏URL(utf-8)编码,请求内容JSON格式,须和DataType⼀致必填
EBusinessID String⽤户ID,查看⽤户ID和ApiKey必填
RequestType String请求指令类型:1002 必填
DataSign String签名数据,(Body+ApiKey)进⾏MD5加密,再进⾏Base64编码,最后进⾏URL(utf-8)编码必填
DataType String求、返回数据类型:2-json ,默认Json选填
4.请求参数(Body)
参数名称类型说明必须要求
OrderCode String订单编号选填
ShipperCode String快递公司编码,丰⽹速运:SF必填
LogisticCode String物流运单号必填
5.返回参数(Return)
参数名称类型说明必须要求
EBusinessID String⽤户ID 必填
url编码和utf8区别
ShipperCode String快递公司编码必填
LogisticCode String物流运单号选填
Success String成功与否必填
Reason String失败原因选填
State String物流状态:2-在途中,3-签收,4-问题件必填
State String物流状态:2-在途中,3-签收,4-问题件必填
Traces 时间
AcceptTime必填
AcceptStation描述选填
Remark备注必填
6.请求完整报⽂(⽰例)
RequestData=%0d%0a++++++++++++%7b%27OrderCode%27%3a%27%27%2c%27ShipperCode%27%3a%27SF%27%2c%27LogisticCode%27%3a%27295734066970%27%2c%27CustomerName %27%3a%276073%27%7d%0d%0a++++++++&EBusinessID=1264783&RequestType=1002&DataSign=ZTJlZWU0NjI1YTljNTlmYzY5Y2M4YjMzYjcxYWU3MDA%3d&DataType=2
7.成功返回报⽂(⽰例)
丰⽹速运单号295734066970的返回报⽂信息
{
"LogisticCode": "295734066970",
"ShipperCode": "SF",
"Traces": [{
"AcceptStation": "顺丰速运已收取快件",
"AcceptTime": "2020-02-13 18:39:21"
}, {
"AcceptStation": "快件在【衡⽔桃城区集收客户营业部】已装车,准备发往【⽯家庄⾼开集散中⼼】",
"AcceptTime": "2020-02-13 18:39:31"
}, {
"AcceptStation": "快件已发车",
"AcceptTime": "2020-02-13 19:15:24"
}, {
"AcceptStation": "快件到达【⽯家庄⾼开集散中⼼】",
"AcceptTime": "2020-02-14 04:27:00"
}, {
"AcceptStation": "快件在【⽯家庄⾼开集散中⼼】已装车,准备发往【长沙星沙集散中⼼】",
"AcceptTime": "2020-02-14 08:36:14"
}, {
"AcceptStation": "快件已发车",
"AcceptTime": "2020-02-14 18:34:31"
}, {
"AcceptStation": "快件到达【长沙星沙集散中⼼】",
"AcceptTime": "2020-02-16 09:58:05"
}, {
"AcceptStation": "快件在【长沙星沙集散中⼼】已装车,准备发往【怀化盈⼝集散点】",
"AcceptTime": "2020-02-16 11:03:53"
}, {
"AcceptStation": "快件已发车",
"AcceptTime": "2020-02-16 11:50:35"
}, {
"AcceptStation": "快件到达【怀化盈⼝集散点】",
"AcceptTime": "2020-02-16 20:20:42"
}, {
"AcceptStation": "快件在【怀化盈⼝集散点】已装车,准备发往【沅陵县御鑫城营业点】",
"AcceptTime": "2020-02-17 05:33:23"
}, {
"AcceptStation": "快件已发车",
"AcceptTime": "2020-02-17 05:33:37"
}, {
"AcceptStation": "快件到达【沅陵县御鑫城营业点】",
"AcceptTime": "2020-02-17 07:55:20"
}, {
"AcceptStation": "快件在【沅陵县御鑫城营业点】已装车,准备发往【怀化市沅陵县⼆⾣苗族乡合作点】",
"AcceptTime": "2020-02-17 09:31:53"
}, {
"AcceptStation": "快件到达【怀化市沅陵县⼆⾣苗族乡合作点】",
"AcceptTime": "2020-02-17 09:32:16"
}, {
"AcceptStation": "正在派送途中,请您准备签收(派件⼈:邓⼩云,电话:132********)",
"AcceptTime": "2020-02-17 09:32:31"
}, {
"AcceptStation": "快件交给邓⼩云,正在派送途中(:132********,顺丰已开启“安全呼叫”保护您的电话隐私,请放⼼接听!)", "AcceptTime": "2020-02-17 09:33:26"
}, {
"AcceptStation": "已签收,感谢使⽤顺丰,期待再次为您服务(主单总件数:1件)",
"AcceptTime": "2020-02-17 22:41:24"
}, {
"AcceptStation": "在官⽹\"运单资料&签收图\",可查看签收⼈信息",
"AcceptTime": "2020-02-17 22:41:26"
}],
"State": "3",
"EBusinessID": "1264783",
"Success": true
}
8.失败返回报⽂(⽰例)
{
"LogisticCode": "295734066970",
"ShipperCode": "SF",
"Traces": [],
"State": "0",
"EBusinessID": "1264783",
"Reason": "业务错误[没有可⽤套餐]",
"Success": false
}
说明:未实名认证,未订购套餐,套餐可⽤查询量已经⽤完都会返回此报⽂信息
/
9.⽆轨迹返回报⽂(⽰例)
{
"LogisticCode": "295734066970",
"ShipperCode": "SF",
"Traces": [],
"State": "0",
"EBusinessID": "1264783",
"Reason": "暂⽆轨迹信息",
"Success": true
}
10.分步讲解(C#版本)
10.1,请求数据包结构
10.2,C#调⽤代码⽰例
//电商ID
string eEBusinessID = "test1617571";
//电商加密私钥,快递鸟提供,注意保管,不要泄漏
string appKey= "554343b2-7252-439b-b4eb-1af42c8f2175";
//请求url
string reqURL = "sandboxapi.kdniao:8080/kdniaosandbox/gateway/exterfaceInvoke.json";
//请求指令
string reqType="1002";
/
/2-json
string dataType = "2";
//字符编码采⽤UTF-8
string charset = "UTF-8";
//JSON字符串string
string jsonStr =
"{\"OrderCode\":\"\",\"ShipperCode\":\"JTSD\",\"LogisticCode\":\"JT0000052600488\"}" ;
//把(jsonStr+APIKey)进⾏MD5加密
string md5Str=MD5(jsonStr + apiKey, charset);
//把md5Str 进⾏Base64编码
string base64Str=base64(md5Str,charset);
/
/进⾏URL编码 (utf-8)
string datasign = HttpUtility.UrlEncode(base64Str, charset);
//请求报⽂参数
string postStr = "RequestType=reqType&EBusinessID= eEBusinessID&RequestData=jsonStr
&DataSign= datasign&DataType=dataType";
//通讯协议使⽤Http协议Post请求⽅式返回轨迹数据
string post = SendPost(reqURL, postStr);
//获取到的post数据就是快递鸟返回的完整报⽂,接下来⾃⼰写⼀个解析json的⽅法就能获取到⾥⾯的字段信息。
10.3,C#调⽤⽅法
///<summary>
/// 字符串MD5加密
///</summary>
///<param name="str">要加密的字符串</param>
///<param name="charset">编码⽅式</param>
///<returns>密⽂</returns>
private string MD5(string str, string charset)
{
byte[] buffer = System.Text.Encoding.GetEncoding(charset).GetBytes(str);
try
{
System.Security.Cryptography.MD5CryptoServiceProvider check;
check = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] somme = check.ComputeHash(buffer);
string ret = "";
foreach (byte a in somme)
{
if (a < 16)
ret += "0" + a.ToString("X");
else
ret += a.ToString("X");
}
return ret.ToLower();
}
catch
{
throw;
}
}
/// <summary>
/// base64编码
/// </summary>
/// <param name="str">内容</param>
/// <param name="charset">编码⽅式</param>
/// <returns></returns>
private string base64(String str, String charset)
{
return Convert.ToBase64String(System.Text.Encoding.GetEncoding(charset).GetBytes(str));
}
/// <summary>
/// Post⽅式提交数据,返回⽹页的源代码
/// </summary>
/// <param name="url">发送请求的 URL</param>
/// <param name="postData">请求报⽂参数</param>
/// <returns>远程资源的响应结果</returns>
private string SendPost(string url, string postData)
{
string result = "";
byte[] byteData = Encoding.GetEncoding("UTF-8").GetBytes(postData.ToString());
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/x-www-form-urlencoded";
request.Referer = url;
request.Accept = "*/*";
request.Timeout = 30 * 1000;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.5072
7; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";            request.Method = "POST";
request.ContentLength = byteData.Length;
Stream stream = request.GetRequestStream();
stream.Write(byteData, 0, byteData.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream backStream = response.GetResponseStream();
StreamReader sr = new StreamReader(backStream, Encoding.GetEncoding("UTF-8"));
result = sr.ReadToEnd();
sr.Close();
backStream.Close();
response.Close();
request.Abort();
}
catch (Exception ex)
{
result = ex.ToString();
}
return result;
}
11.丰⽹速运查询接⼝应⽤
12.关于签名
快递鸟和第三⽅电⼦商务公司系统进⾏对接,有⼀定的安全机制。采⽤ IP 认证加签名
的⽅式对接,具体⽅案如下:
防⽌数据被篡改
在 POST 请求中会传递 5 个必须(R)参数
RequestData==数据内容(URL 编码:UTF-8)
EBusinessID==⽤户 ID
RequestType=请求指令类型
DataSign== 数据内容签名:把(请求内容(未编码)+ApiKey)进⾏ MD5 加密,然后 Base64
编码,最后进⾏ URL(utf-8)编码
DataType==2(返回数据类型为 json)
注:
DataSign ⽣成后,对⽅接收到数据后,以同样的算法进⾏签名(推送接⼝ RequestType 为
101/102 不需要进⾏ URL 编码),⽣成摘要,对⽐两者的摘要是否相同,如果不同,说明传递过程中发⽣数据篡改。
调⽤接⼝的⾝份认证
注册成为快递鸟⽤户后,会⽣成对应的⽤户 ID 和 APIKey,⽤户 ID 相当于⽤户名,
APIKey 相当于密码。
13.返回码定义

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。