电子面单下单:
5.3.1、请求接口之前需要先实名认证,开通相关会员服务,否则会请求失败并返回提示“未申请开通接口”;
5.3.2、接口开发需下载“快递鸟接口技术文档”、“2018快递鸟接口支持快递公司编码列表.xlsx”、“快递鸟电子面单客户号参数对照表”、“快递公司快递业务类型”进行查看;电子面单,参考技术文档中的3.2部分;
5.3.3、快递鸟官网-帮助与文档下载“电子面单demo”进行参考(仅提供了.NET、Java、PHP三种语言的demo);其他语言开发的用户需下载技术文档自行开发;
5.3.4、使用电子面单接口还需要电子面单账号(注:每家快递公司电子面单账号需要传的字段不同,详情请参考“快递鸟电子面单客户号参数对照表”);
5.3.4.1、测试环境:必须使用快递鸟提供的测试账号,在快递鸟官网-帮助与文档下载“快递鸟电子面单客户号参数对照表”查看相应账号和接口请求对应的字段名,另外电子面单接口测试环境由快递公司维护,快递公司经常调整导致测试环境不稳定甚至不可用,如:申通、宅急送、安能。正式环境是可以正常使用的。测试环境只是提供给用户调通接口使用,每家快递鸟支持的快递公司逻辑相同,测通一家快递公司说明接口已调通。
5.3.4.2、正式环境:
² 无需电子面单账号直接下单:
顺丰,EMS(广东省内发全国),宅急送,邮政快递包裹、中铁快运、邮政国内标快、全一快递;
² 线上(快递鸟官网后台)申请账号:
优速、韵达、圆通、远成快运、安能、百世;
(申请路径:快递鸟官网—电子面单—我的快递公司—申请新的快递公司);
² 其他的快递公司您需要和当地的快递网点线下申请账号(预存单号)才可以使用。
电子面单批量打印:
5.3.5、快递鸟官网-帮助与文档下载“电子面单批量打印demo”进行参考(仅提供了.NET、Java、PHP三种语言的demo);其他语言开发的用户需下载技术文档自行开发;
5.3.6、对接注意事项
5.3.6.1、确保接口中电商ID、密钥(AppKey)与用户管理后台的商户ID、密钥完全一致;
5.3.6.2、OrderCode必须是快递鸟电子面单下单接口正式环境下单的订单号;PortName是打印机名称,必须与本地
打印机名称一致;
5.3.6.3、确保接口demo中GetIp()方法获取到的IP和用户连接打印机的电脑IP(百度搜索IP138)一致。
5.3.7、安装快递鸟打印控件C-Lodop (Print)
安装方式1、调用快递鸟批量打印demo后会提示下载。
安装方式2、在快递鸟官网下载,下载地址:http://www.kdniao.com/product-eorder-specific
demo示例:
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Web; namespace KdGoldAPI { /** * * 快递鸟电子面单接口 * * @技术QQ * @技术QQ群 * @see: http://www.kdniao.com/MiandanAPI.aspx * @copyright: 深圳市快金数据技术服务有限公司 * * ID和Key请到官网申请:http://www.kdniao.com/ServiceApply.aspx */ public class KdApiEOrderDemo { //电商ID private string EBusinessID = "请到快递鸟官网申请http://www.kdniao.com/ServiceApply.aspx"; //电商加密私钥,快递鸟提供,注意保管,不要泄漏 private string AppKey = "请到快递鸟官网申请http://www.kdniao.com/ServiceApply.aspx"; //请求url, 正式环境地址:http://api.kdniao.cc/api/Eorderservice private string ReqURL = "http://testapi.kdniao.cc:8081/api/EOrderService"; /// <summary> /// Json方式 电子面单 /// </summary> /// <returns></returns> public string orderTracesSubByJson() { string requestData = "{'OrderCode': '012657700312'," + "'ShipperCode':'YTO'," + "'PayType':1," + "'ExpType':1," + "'Cost':1.0," + "'OtherCost':1.0," + "'Sender':" + "{" + "'Company':'LV','Name':'Taylor','Mobile':'1xxxxxxxxxx','ProvinceName':'上海','CityName':'上海','ExpAreaName':'青浦区','Address':'明珠路73号'}," + "'Receiver':" + "{" + "'Company':'GCCUI','Name':'Yann','Mobile':'1xxxxxxxxxx','ProvinceName':'北京','CityName':'北京','ExpAreaName':'朝阳区','Address':'三里屯街道雅秀大厦'}," + "'Commodity':" + "[{" + "'GoodsName':'鞋子','Goodsquantity':1,'GoodsWeight':1.0}]," + "'AddService':" + "[{" + "'Name':'COD','Value':'1020'}]," + "'Weight':1.0," + "'Quantity':1," + "'Volume':0.0," + "'Remark':'小心轻放'," + "'IsReturnPrintTemplate':1}"; Dictionary<string, string> param = new Dictionary<string, string>(); param.Add("RequestData", HttpUtility.UrlEncode(requestData, Encoding.UTF8)); param.Add("EBusinessID", EBusinessID); param.Add("RequestType", "1007"); string dataSign = encrypt(requestData, AppKey, "UTF-8"); param.Add("DataSign", HttpUtility.UrlEncode(dataSign, Encoding.UTF8)); param.Add("DataType", "2"); string result = sendPost(ReqURL, param); //根据公司业务处理返回的信息...... return result; } /// <summary> /// Post方式提交数据,返回网页的源代码 /// </summary> /// <param name="url">发送请求的 URL</param> /// <param name="param">请求的参数集合</param> /// <returns>远程资源的响应结果</returns> private string sendPost(string url, Dictionary<string, string> param) { string result = ""; StringBuilder postData = new StringBuilder(); if (param != null && param.Count > 0) { foreach (var p in param) { if (postData.Length > 0) { postData.Append("&"); } postData.Append(p.Key); postData.Append("="); postData.Append(p.Value); } } 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.Message; } return result; } ///<summary> ///电商Sign签名 ///</summary> ///<param name="content">内容</param> ///<param name="keyValue">Appkey</param> ///<param name="charset">URL编码 </param> ///<returns>DataSign签名</returns> private string encrypt(String content, String keyValue, String charset) { if (keyValue != null) { return base64(MD5(content + keyValue, charset), charset); } return base64(MD5(content, charset), charset); } ///<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)); } } }