X

极兔速递电子面单API接口C#

目录

1.完成前期准备工作

2.API接口

3.请求完整报文(示例)

4.成功返回报文(示例)

5.失败返回报文(示例)

6.分步讲解(C#版本)

7.极兔速递电子面单打印模板内容(HTML)

8.关于签名

前言

J&T 极兔速递是一家科技创新型互联网快递物流企业,致力于为用户带来优质的快递和物流体验。

2015年8月由印尼首都雅加达作为起点,进入快递物流市场,目前覆盖了印度尼西亚、越南、马来西亚、泰国、菲律宾、柬埔寨及新加坡七个国家,成为东南亚超过5.5亿人口信赖的综合性物流服务商。

电子面单模板效果图:

电子面单打印模板规格列表:

快递公司名称编码模板样式尺寸规格TemplateSize字段CustomArea字段极兔速递JTSD一联130宽76**m**m 高130mm传值130支持极兔速递JTSD二联180宽100**m**m 高180mm 切点110/70默认返回,不能传值

1.完成前期准备工作

1.1,去快递鸟免费注册一个对接账号

1.2,免费获得一个apiKey(接口权限验证需要)

1.3,完成实名认证流程

1.4,订购一个免费套餐

1.5,准备打印机、打印纸

打印机:电子面单模板对打印机品牌、型号等没有要求,只要是热敏打印机即可,常见品牌如:斑马、得力、快麦、汉印、佳博等。

打印机可由快递网点提供或者在淘宝京东上购买, 安装打印机及驱动程序联系打印机提供方;

打印纸:打印纸可由快递网点提供或者在淘宝京东上购买,购买时可选择全白热敏 纸。

2.API接口

2.1,测试调用地址:http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json

2.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.请求报文(示例)

{“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”: “广东省深圳市福田区华宝一号大厦”}}

4.成功返回报文(示例)

{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}

5.失败返回报文(示例)

{ “EBusinessID”: “1237100”, “ResultCode”: “106”, “Reason”: “该订单号已下单成功”, “UniquerRequestNumber”:”5e66486b-8fbc-4131-b875-9b13d2ad1354″ }

6.分步讲解(C#版本)

6.1,请求数据包结构

6.2,C#调用代码示例

技术支持:QQ:510997342//电商IDstring eEBusinessID = “test1617571”; //电商加密私钥,快递鸟提供,注意保管,不要泄漏string appKey= “554343b2-7252-439b-b4eb-1af42c8f2175”; //请求urlstring 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的方法就能获取到里面的字段信息。

6.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; }

7.极兔速递电子面单打印模板内容(HTML)

<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=””><img class=”item image” style=”left:17.5px;top:215px;width:31px;height:33px;” src=””><img class=”item image” style=”left:16.5px;top:258px;width:31px;height:31px;” src=””><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=”” /></div><!–<img class=”item image” style=”left:25.5px;top:117px;width:25px;height:23px;” src=””>–><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=””><img class=”item image” style=”left:26.5px;top:545px;width:33px;height:32px;” src=””><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=”” /></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=”” /></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=””>

复制以上HTML内容保存为html格式的文件,可以查看模板效果。

8.关于签名

快递鸟和第三方电子商务公司系统进行对接,有一定的安全机制。采用 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 相当于用户名,