前言
J&T 极兔快递是一家科技创新的互联网快递物流企业,致力于为用户带来优质的快递和物流体验。
2015年8月由印尼首都雅加达作为起点,进入快递物流市场,目前覆盖了印度尼西亚、越南、马来西亚、泰国、菲律宾、柬埔寨及新加坡七个国家,成为东南亚超过5.信赖5亿人的综合物流服务商。
1.完成前期准备工作
1.5,
只要是热敏打印机,电子面单模板就不需要打印机的品牌和型号。斑马、得力、快麦、汉印、佳博等常见品牌。
打印机可由快递网点或淘宝京东购买,安装打印机和驱动程序联系打印机提供商;
打印纸可由快递网点提供或在淘宝京东购买。购买时可选择全白热敏 纸。
2.API接口
2.1.测试调用地址:http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json
2.二、正式调用地址:http://api.kdniao.com/api/EOrderService
2.3.请求方式:POST
2.4,编码格式(utf-8):application/x-www-form-urlencoded;charset=utf-8
2.5.返回类型:JSON
2.6.调试页面:http://kdniao.com/UserCenter/v2/SandBox/TrackQuery.aspx
2.7.调试工具:调试(登录快递鸟账号)
3.请求参数(Headers)
RequestData | String | 需要执行请求内容URL(utf-8)编码,请求内容JSON格式,须和DataType一致 | 必填 |
EBusinessID | String | 用户ID,查看用户ID和ApiKey | 必填 |
RequestType | String | 请求指令类型:1007 | 必填 |
DataSign | String | 签名数据,(Body ApiKey)进行MD加密,然后进行Base64编码,最后进行URL(utf-8)编码 | 必填 |
DataType | String | 求、返回数据类型:2-json ,默认Json | 选填 |
4.请求参数(Body)
参数名称 | 类型 | 说明 | 是否必须 | |
---|---|---|---|---|
MemberID | String(50) | ERP会员系统、电子商务平台等系统或平台用户ID或店铺账号等唯一标识,用于区分用户 | O | |
CustomerName | String(50) | 电子面单客户号需下载快递鸟电子面单客户号参数对照表.xlsx》,参考相应的字段传值 | O | |
CustomerPwd | String(30) | O | ||
SendSite | String(30) | O | ||
SendStaff | String(30) | C | ||
MonthCode | String | C | ||
CustomArea | String(500) | 商家自定义区域 | C | |
WareHouseID | String(30) | 发货仓编码 | O | |
TransType | Int(1) | 运输方式 1- 陆运 2- 空运 不填默认为1 | O | |
ShipperCode | String(10) | 快递公司编码 详细编码参考快递鸟接口支持快递公司编码.xlsx》 | R | |
LogistcCode | String(30) | 快递单号(仅宅急送可用) | O | |
ThrOrderCode | String(50) | 第三方订单号 (ShipperCode为JD且ExpType为1时必填) | C | |
OrderCode | String(30) | 订单编号(自定义,不可重复) | R | |
PayType | Int(1) | 邮费支付方式:1-现付,2-到付,3-月结,4-第三方支付(仅SF支持) | R | |
ExpType | String(2) | 快递类型:1-标准快件 ,详细快递类型参考《快递公司快递业务类型.xlsx》 | R | |
IsReturnSignBill | Int(1) | 是否要求签回单 1- 要求 0-不要求 | O | |
OperateRequire | String(20) | 签回单操作要求(如:签名、盖章、身份证复印件等) | O | |
Cost | Cost Double(5) | 快递运费 | O | |
OtherCost | Double(5) | 其他费用 | O | |
Receiver | Company | String(30) | 收件人公司 | O |
Name | String(30) | 收件人 | R | |
Tel | String(20) | 电话与手机,必填一个 | R | |
Mobile | String(20) | |||
PostCode | String(10) | 收件人邮编 | c | |
ProvinceName | String(20) | 收件省 (如广东省,不要缺少“省”;如是直辖市,请直接传北京、上海等; 如是自治区,请直接传广西壮族自治区等) | R | |
CityName | String(20) | 收件市(如深圳市,不要缺少“市”; 如果是市辖区,请直接传北京市、上海市等) | R | |
ExpAreaName | String(20) | 收件区/县(如福田区,不要缺少“区”或“县”) | R | |
Address | String(100) | 收件人详细地址 | R | |
Sender | Company | String(30) | 发件人公司 | O |
Name | String(30) | 发件人 | R | |
Tel | String(20) | 电话与手机,必填一个 | R | |
Mobile | String(20) | |||
PostCode | String(10) | 发件地邮编(ShipperCode为EMS、YZPY、YZBK时必填) | C | |
ProvinceName | String(20) | 发件省 (如广东省,不要缺少“省”; 如是直辖市,请直接传北京、上海等; 如是自治区,请直接传广西壮族自治区等) | R | |
CityName | String(20) | 发件市(如深圳市,不要缺少“市; 如是市辖区,请直接传北京市、上海市等”) | R | |
ExpAreaName | String(20) | 发件区/县(如福田区,不要缺少“区”或“县”) | R | |
Address | String(100) | 发件人详细地址 | R | |
IsNotice | Int(1) | 是否通知快递员上门揽件 0- 通知 1- 不通知 不填则默认为1 | O | |
StartDate | Date | 上门取货时间段:"yyyy-MM-dd HH:mm:ss"格式化,本文中所有时间格式相同 | O | |
EndDate | Date | O | ||
Weight | Double(10,3) | 包裹总重量kg 当为快运的订单时必填,不填时快递鸟将根据各个快运公司要求传对应的默认值 | C | |
Quantity | Int(2) | 包裹数(最多支持30件) 一个包裹对应一个运单号,如果是大于1个包裹,返回则按照子母件的方式返回母运单号和子运单号 | R | |
Volume | Double(20,3) | 包裹总体积m3 当为快运的订单时必填,不填时快递鸟将根据各个快运公司要求传对应的默认值 | C | |
Remark | String(60) | 备注 | O | |
AddServices | ||||
AddService | Name | String(20) | 增值服务名称 (数组形式,可以有多个增值服务) | C |
Value | String(30) | 增值服务值 | C | |
CustomerID | String(30) | 客户标识(选填) | O | |
Commoditys | ||||
Commodity | GoodsName | String(100) | 商品名称 | R |
GoodsCode | String(100) | 商品编码 | O | |
Goodsquantity | Int(5) | 商品数量 | O | |
GoodsPrice | Double(10) | 商品价格 | O | |
GoodsWeight | Double(10,3) | 商品重量kg | O | |
GoodsDesc | String(50) | 商品描述 | O | |
GoodsVol | Double(15,3) | 商品体积m3 | O | |
IsReturnPrintTemplate | String(1) | 返回电子面单模板:0-不需要;1-需要 | O | |
IsSendMessage | Int(1) | 是否订阅短信:0-不需要;1-需要 | O | |
TemplateSize | String(10) | 模板规格(默认的模板无需传值,非默认模板传对应模板尺寸) | O | |
PackingType | Int(2) | 包装类型(快运字段)默认为0; 0- 纸 1- 纤 2- 木 3- 托膜 4- 木托 99-其他 | C | |
DeliveryMethod | Int(1) | 送货方式(快运字段)默认为0; 0- 自提 1- 送货上门(不含上楼) 2- 送货上楼 | C |
5.返回参数(Return)
参数名称 | 类型 | 说明 | 必须要求 | |
---|---|---|---|---|
EBusinessID | String(10) | 用户ID | R | |
Order | OrderCode | String(30) | 订单编号 | R |
ShipperCode | String(10) | 快递公司编码 | R | |
LogisticCode | String(400) | 快递单号 | R | |
MarkDestination | String(20) | 大头笔 | O | |
OriginCode | String(20) | 始发地区域编码 | O | |
OriginName | String(20) | 始发地/始发网点 | O | |
DestinatioCode | String(20) | 目的地区域编码 | O | |
DestinatioName | String(20) | 目的地/到达网点 | O | |
SortingCode | String(20) | 分拣编码 | O | |
PackageCode | String(20) | 集包编码 | O | |
PackageName | String(50) | 集包地 | O | |
DestinationAllocationCentre | String(50) | 目的地分类 | O | |
Success | Bool(10) | 成功与否(true/false) | R | |
SignWaybillCode | String(15) | 签回单单号 | O | |
ResultCode | String(5) | 返回编码 | R | |
Reason | String(50) | 失败原因 | O | |
UniquerRequestNumber | String(50) | 唯一标识 | R | |
PrintTemplate | String | 面单打印模板内容(html格式) | O | |
EstimatedDeliveryTime | Date | 订单预计到货时间yyyy-mm-dd | O | |
SubCount | Int(5) | 子单数量 | O | |
SubOrders | String(400) | 子单单号 | O | |
SubPrintTemplates | String(2000) | 子单模板内容(html格式) | O | |
SignBillPrintTemplate | String(2000) | 签回单模板内容(html格式) | O | |
ReceiverSafePhone | String(20) | 收件人安全电话 | O | |
SenderSafePhone | String(20) | 收件人安全电话 | O | |
DialPage | String(50) | 拨号页面网址(转换成二维码可扫描拨号) | O |
6.请求报文(示例)
{ "PayType": 1, "CustomerName": "J0086030000", "CustomerPwd": "Jt888888", "ExpType": 1, "ShipperCode": "JTSD", "OrderCode": "300008886539888", "IsNotice": 1, "IsReturnPrintTemplate": 1, "Commodity": [ { "GoodsName": "其他", "Goodsquantity": 1, "GoodsWeight": 0 } ], "Sender": { "Name": "王宝剑", "Mobile": "13988888888", "ProvinceName": "北京市", "CityName": "北京市", "ExpAreaName": "西城区", "Address": "北京市西城区西直门南小街国英1号1020" }, "Receiver": { "Name": "刘小刀", "Mobile": "18809999999", "ProvinceName": "广东省", "CityName": "深圳市", "ExpAreaName": "福田区", "Address": "广东省深圳市福田区华宝一号大厦" }}
7.成功返回报文(示例)
{Order={LogisticCode=JT0000131754417, PackageName=180 600-01 001, OrderCode=300008886539888, KDNOrderCode=KDN2005141650003168, SortingCode=180 600-01 001}, PrintTemplate=打印html内容, EBusinessID=1237100,UniquerRequestNumber=f3ba8bf3-cb4c-4f06-8aee-7fba1e0e8376, ResultCode=100, Reason=成功, Success=true}
8.失败返回报文(示例)
{ "EBusinessID": "1237100", "ResultCode": "106", "Reason": "该订单号已下单成功", "UniquerRequestNumber":"5e66486b-8fbc-4131-b875-9b13d2ad1354" }
去实名认证 / 了解套餐详情
9.分步讲解(C#版本)
9.1,请求数据包结构
9.2,C#调用代码示例
技术支持:QQ:510997342 //电商ID string eEBusinessID = "test1617571"; //电商加密私钥,快递鸟提供,注意保管,不要泄漏 string appKey= "554343b2-7252-439b-b4eb-1af42c8f2175"; //请求url string reqURL = "http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json"; //请求指令 string reqType="1007"; //2-json string dataType = "2"; //字符编码采用UTF-8 string charset = "UTF-8"; //JSON字符串string string jsonStr = "json请求报文示例" ;
//把(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的方法就能获取到里面的字段信息。
9.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.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; }
<style> .item { position: absolute; } </style><div class="item hline" style="left:0.5px;top:1px;width:373px;height:0;border-top:1px solid #000"></div><div class="item vline" style="left:3px;top:1px;height:681px;width:0;border-left:1px solid #000;"></div><div class="item vline" style="left:371px;top:2px;height:681px;width:0;border-left:1px solid #000;"></div><div class="item hline" style="left:1.5px;top:682px;width:369px;height:0;border-top:1px solid #000"></div><!--<div class="item text" style="left:28.5px;top:9px;width:113px;height:38px;font-family:"Microsoft Yahei";font-size:22px;font-weight:400;overflow:visible">Company</div>--><div class="item hline" style="left:4.5px;top:60px;width:366px;height:0;border-top:1px solid #000"></div><div class="item text" style="background:#000;color:#fff;left:234.5px;top:5px;width:107px;height:28px;font-family:"Microsoft Yahei";font-size:20px;font-weight:400;overflow:visible; display: none;"> 代 收 货 款</div><div class="item text" style="left:220.5px;top:38px;width:144px;height:18px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible">服务热线: 400 820 1666</div><div class="item hline" style="left:3.5px;top:151px;width:366px;height:0;border-top:1px solid #000"></div><div class="item text" style="left:15px;top:63px;width:260px;height:42px;font-family:"Microsoft Yahei";font-size:32px;font-weight:400;overflow:visible">180 600-01 001</div><div class="item text" style="left:316.5px;top:67px;width:40px;height:37px;font-family:"Microsoft Yahei";font-size:16px;font-weight:500;overflow:visible">标准快递</div><img class="item image" style="left:14.5px;top:160px;width:39px;height:34px;" src="https://img-blog.csdnimg.cn/2022010621475254270.png"><img class="item image" style="left:17.5px;top:215px;width:31px;height:33px;" src="https://img-blog.csdnimg.cn/2022010621475212396.png"><img class="item image" style="left:16.5px;top:258px;width:31px;height:31px;" src="https://img-blog.csdnimg.cn/2022010621475322919.png"><div class="item " style="left: 80px; top: 180px; width: 370px; height: 120px; fopacity: 1.0; padding-left: 20px; font-weight: bold;"> <img style="left: 40px; top: 120px; width: 270px; height: 100px; " src="https://img-blog.csdnimg.cn/2022010621475312094.png" /></div><!--<img class="item image" style="left:25.5px;top:117px;width:25px;height:23px;" src="https://img-blog.csdnimg.cn/2022010621475312737.png">--><div class="item text" style="left:220.5px;top:113px;width:65px;height:19px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible">打印时间:</div><div class="item text" style="left:282.5px;top:111px;width:83px;height:33px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible">2020/05/14 16:05:12 </div><div class="item hline" style="left:4.5px;top:211px;width:368px;height:0;border-top:1px dashed #000"></div><div class="item vline" style="left:58px;top:151px;height:140px;width:0;border-left:1px solid #000;"></div><div class="item text" style="left:63px;top:153px;width:305px;height:25px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:hidden;ine-height: 95%">刘小刀 18809999999 </div><div class="item text" style="left:63px;top:183px;width:305px;height:26px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:hidden;ine-height: 93%">广东省深圳市福田区华宝一号大厦</div><div class="item hline" style="left:3.5px;top:255px;width:368px;height:0;border-top:1px dashed #000"></div><div class="item text" style="left:63px;top:213px;width:305px;height:18px;font-family:"Microsoft Yahei";font-size:10px;font-weight:400;overflow:hidden">王宝剑 13988888888 </div><div class="item text" style="left:63px;top:230px;width:305px;height:24px;font-family:"Microsoft Yahei";font-size:10px;font-weight:400;overflow:hidden"> 北京市西城区西直门南小街国英1号1020</div><div class="item hline" style="left:0.5px;top:291px;width:373px;height:0;border-top:1px solid #000"></div><div class="item hline" style="left:59.5px;top:272px;width:310px;height:0;border-top:1px dashed #000"></div><div class="item text" style="left:74.5px;top:255px;width:54px;height:20px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible;">代收货款</div><div class="item text" style="left:179.5px;top:255px;width:56px;height:16px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible">到付运费</div><div class="item text" style="left:288.5px;top:254px;width:62px;height:20px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible">计件重量 </div><div class="item vline" style="left:152px;top:254px;height:38px;width:0;border-left:1px solid #000;"></div><div class="item vline" style="left:265px;top:254px;height:38px;width:0;border-left:1px solid #000;"></div><div class="item text" style="left:66.5px;top:272px;width:73px;height:20px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible">0</div><!--<div class="item text" style="left:184.5px;top:272px;width:48px;height:21px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible">¥Cost</div>--><div class="item text" style="left:289.5px;top:271px;width:55px;height:16px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible"></div><div class="item hline" style="left:2.5px;top:416px;width:368px;height:0;border-top:1px solid #000"></div><div class="item text" style="left:6.5px;top:366px;width:90px;height:16px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible">签收人/时间:</div><div class="item text" style="left:4.5px;top:384px;width:268px;height:27px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible">您的签收代表您已接收此包裹,并确认商品信息无误,包裹完好、没有划痕、破损等表面质量问题</div><img class="item image" style="left:26.5px;top:496px;width:34px;height:35px;" src="https://img-blog.csdnimg.cn/2022010621475254270.png"><img class="item image" style="left:26.5px;top:545px;width:33px;height:32px;" src="https://img-blog.csdnimg.cn/2022010621475212396.png"><div class="item vline" style="left:77px;top:498px;height:82px;width:0;border-left:1px solid #000;"></div><div class="item text" style="left:80px;top:494px;width:290px;height:18px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:hidden">刘小刀 18809999999 </div><div class="item text" style="left:80px;top:514px;width:290px;height:30px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:hidden">广东省深圳市福田区华宝一号大厦</div><div class="item text" style="left:80px;top:543px;width:290px;height:18px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:hidden">王宝剑 13988888888 </div><div class="item text" style="left:80px;top:563px;width:290px;height:30px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:hidden">北京市西城区西直门南小街国英1号1020</div><div class="item text" style="left:12.5px;top:603px;width:300px;height:80px;font-family:"Microsoft Yahei";font-size:14px;font-weight:400;overflow:visible">备注: 数量:1 重量:0kg 其他</div><div class="item text" style="left:313.5px;top:657px;width:56px;height:20px;font-family:"Microsoft Yahei";font-size:14px;font-weight:400;overflow:visible">已检视</div><!--<div class="item text" style="left:16.5px;top:578px;width:65px;height:20px;font-family:"Microsoft Yahei";font-size:14px;font-weight:400;overflow:visible">备注</div>--><div class="item" style="left:8.5px;top:295px;width:350px;height:60px;font-family:"Microsoft Yahei";font-size:14px;font-weight:400;overflow:visible"> <img src="https://img-blog.csdnimg.cn/2022010621475456187.gif" /></div><div class="item text" style="left:110px;top:350px;width:170px;height:20px;font-family:"Microsoft Yahei";font-size:14px;font-weight:400;overflow:visible">JT0000131754417</div><div class="item" style="left:190px;top:423px;width:178px;height:55px;font-family:"Microsoft Yahei";font-size:14px;font-weight:400;overflow:visible"> <img src="https://img-blog.csdnimg.cn/2022010621475489872.gif" /></div><div class="item text" style="left:208px;top:475px;width:160px;height:20px;font-family:"Microsoft Yahei";font-size:12px;font-weight:400;overflow:visible">JT0000131754417</div><img class="item image" style="left:286.5px;top:345px;width:82px;height:68px;" src="https://img-blog.csdnimg.cn/2022010621475444865.png">
复制以上HTML内容保存为html格式的文件,可以查看模板效果。
11.关于签名
快递鸟和第三方电子商务公司系统进行对接,有一定的安全机制。采用 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 相当于密码。