看完快递鸟api顺丰丰⽹速运快递对接教程这篇⽂章,然后把源码复制到你的项⽬上,就能快速完成丰⽹速运快递接⼝对接.更适合刚⼊门的菜鸟,调⽤快递鸟的丰⽹速运快递快递查询API接⼝,能查询到快递单号从收件、运输,到转运中⼼,派送到签收等各个环节的物流发货状态。快递鸟api接⼝不区分开发语⾔,⽀持Java,C#,PHP,Python,ObjectC等开发语⾔的程序调⽤。编码⽤顺丰编码即可查询(SF),下⾯具体讲解实现过程.
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.6,调试页⾯:
2.7,调试⼯具:去调试(使⽤快递鸟账号登录)
3.请求参数(Headers)
4.请求参数(Body)
6.请求完整报⽂(⽰例)
RequestData=%7b%27OrderCode%27%3a%27%27%2c%27ShipperCode%27%3a%27JTSD%27%2c%27LogisticCode%27%3a%27
jt0000052600488%27%7d&EBusinessID=1264783&RequestType=1002&DataSign=MTYyMDU4NWQ2NmU1ZDI2MDEzNGE5YmV
lM2YxYzEzMTM%3d&DataType=2
7.成功返回报⽂(⽰例)
{
"LogisticCode": "SF0000052600488",
"ShipperCode": "SF",
"Traces": [
{
"AcceptStation": "【芜湖市】【芜湖镜湖⽹点】的邓拥军 178********已取件",
"AcceptTime": "2020-03-16 16:26:13"
},
{
"AcceptStation": "【芜湖市】【芜湖镜湖⽹点】的邓拥军 178********已取件",
"AcceptTime": "2020-03-16 16:41:33"
},
{
"AcceptStation": "【芜湖市】【芜湖镜湖⽹点】已收件",
"AcceptTime": "2020-03-16 17:39:21"
},
{
"AcceptStation": "【芜湖市】快件离开【芜湖镜湖⽹点】已发往【芜湖转运中⼼】",
"AcceptTime": "2020-03-16 17:40:27"
},
{
"AcceptStation": "【芜湖市】快件到达【芜湖转运中⼼】",
"AcceptTime": "2020-03-16 19:36:32"
},
{
"AcceptStation": "【芜湖市】快件离开【芜湖转运中⼼】已发往【合肥转运中⼼】",
"AcceptTime": "2020-03-16 20:47:03"
},
{
"AcceptStation": "【合肥市】快件到达【合肥转运中⼼】",
"AcceptTime": "2020-03-16 23:40:10"
},
{
"AcceptStation": "【合肥市】快件离开【合肥转运中⼼】已发往【⼴州花都转运中⼼】",
"AcceptTime": "2020-03-17 00:10:48"
},
{
"AcceptStation": "【⼴州市】快件到达【⼴州花都转运中⼼】",
"AcceptTime": "2020-03-17 20:45:00"
},
{
"AcceptStation": "【⼴州市】快件离开【⼴州花都转运中⼼】已发往【深圳宝安转运中⼼】",
"AcceptTime": "2020-03-18 00:17:55"
},
{
"AcceptStation": "【深圳市】快件到达【深圳宝安转运中⼼】",
"AcceptTime": "2020-03-18 03:00:17"
},
{
"AcceptStation": "【深圳市】快件离开【深圳宝安转运中⼼】已发往【深圳福⽥⽹点】",
"AcceptTime": "2020-03-18 04:44:39"
},
{
"AcceptStation": "【深圳市】【深圳福⽥⽹点】的邹俊林 176********正在派件",
"AcceptTime": "2020-03-18 08:10:09"
},
{
"AcceptStation": "【深圳市】【深圳福⽥⽹点】的赵凯 159********正在派件",
"AcceptTime": "2020-03-18 09:55:19"
},
{
"AcceptStation": "【深圳市】快件已签收,签收⼈是【代收】,如有疑问请联系:159********,期待再次为您服务", "AcceptTime": "2020-03-18 14:53:54"
}
],
"State": "3",
"EBusinessID": "1264783",
"Success": true
}
8.失败返回报⽂(⽰例)
{
"LogisticCode": "SF0000052600488",
"ShipperCode": "SF",
"Traces": [],
"State": "0",
"EBusinessID": "1264783",
"Reason": "业务错误[没有可⽤套餐]",
"Success": false
}
说明:未实名认证,未订购套餐,套餐可⽤查询量已经⽤完都会返回此报⽂信息宋慧乔承认怀孕
9.⽆轨迹返回报⽂(⽰例)
{
"LogisticCode": "SF0000052600488",
"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":"SF","LogisticCode":"SF0000052600488"}" ;
//把(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);
qq邮箱打不开怎么办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.50727; .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.丰⽹速运快递快递查询接⼝应⽤
发布评论