1、电子面单批量打印接口手册(快递鸟)1 打印 API1.1 API 说明(1)、只支持 Json 格式。接口指令 1007。(2)、订单编号(OrderCode)不可重复提交,重复提交系统会返回具体错误代码。(3)、 接口支持:顺丰(SF) 、EMS(EMS) 、宅急送(ZJS) 、圆通(YTO) 、百世快递(HTKY) 、中通(ZTO) 、韵达(YD) 、申通(STO) 、德邦(DBL) 、优速(UC) 、京东(JD)常用 20 家快递。(4)、测试地址:http:/testapi.kdniao.cc:8081/api/eorderservice/(5)、正式地址:http:/api.kdni
2、ao.cc/api/EOrderService(6)、请求报文中不允许出现以下特殊字符: “ # import java.io.IOException; import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import co
3、m.sun.org.apache.xerces.internal.impl.dv.util.Base64;import java.security.MessageDigest; public class KdGoldAPIDemo /电商 IDprivate String EBusinessID=“ “;/电商加密私钥,注意保管,不要泄漏private String AppKey=“ “;/请求 url, 正式环境地址:http:/api.kdniao.cc/api/Eorderservice 测试环境地址:http:/testapi.kdniao.cc:8081/api/EOrderServ
4、iceprivate String ReqURL=“http:/testapi.kdniao.cc:8081/api/Eorderservice“;/* Json 方式 电子面单* throws Exception */public String orderOnlineByJson() throws ExceptionString requestData= “OrderCode: 012657700387,“ +“ShipperCode:SF,“ +“PayType:1,“ +“ExpType:1,“ +“Cost:1.0,“ +“OtherCost:1.0,“ +“Sender:“ +“ +
5、“Company:LV,Name:Taylor,Mobile:15018442396,ProvinceName:上海,CityName: 上海,ExpAreaName:青浦区,Address:明珠路 73 号,“ +“Receiver:“ +“ +“Company:GCCUI,Name:Yann,Mobile:15018442396,ProvinceName:北京,CityName: 北京,ExpAreaName:朝阳区,Address:三里屯街道雅秀大厦,“ +“Commodity:“ +“ +“GoodsName:鞋子,Goodsquantity:1,GoodsWeight:1.0,“ +
6、“Weight:1.0,“ +“Quantity:1,“ +“Volume:0.0,“ +“Remark:小心轻放,“ +“IsReturnPrintTemplate:1“;Map params = new HashMap();params.put(“RequestData“, urlEncoder(requestData, “UTF-8“);params.put(“EBusinessID“, EBusinessID);params.put(“RequestType“, “1007“);String dataSign=encrypt(requestData, AppKey, “UTF-8“);
7、params.put(“DataSign“, urlEncoder(dataSign, “UTF-8“);params.put(“DataType“, “2“);String result=sendPost(ReqURL, params);/根据公司业务处理返回的信息.return result;/* MD5 加密* param str 内容 * param charset 编码方式* throws Exception */SuppressWarnings(“unused“)private String MD5(String str, String charset) throws Except
8、ion MessageDigest md = MessageDigest.getInstance(“MD5“);md.update(str.getBytes(charset);byte result = md.digest();StringBuffer sb = new StringBuffer(32);for (int i = 0; i params) OutputStreamWriter out = null;BufferedReader in = null; StringBuilder result = new StringBuilder(); try URL realUrl = new
9、 URL(url);HttpURLConnection conn =(HttpURLConnection) realUrl.openConnection();/ 发送 POST 请求必须设置如下两行conn.setDoOutput(true);conn.setDoInput(true);/ POST 方法conn.setRequestMethod(“POST“);/ 设置通用的请求属性conn.setRequestProperty(“accept“, “*/*“);conn.setRequestProperty(“connection“, “Keep-Alive“);conn.setReque
10、stProperty(“user-agent“,“Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)“);conn.setRequestProperty(“Content-Type“, “application/x-www-form-urlencoded“);conn.connect();/ 获取 URLConnection 对象对应的输出流out = new OutputStreamWriter(conn.getOutputStream(), “UTF-8“);/ 发送请求参数 if (params != null) StringBu
11、ilder param = new StringBuilder(); for (Map.Entry entry : params.entrySet() if(param.length()0)param.append(“ param.append(entry.getKey();param.append(“=“);param.append(entry.getValue(); System.out.println(entry.getKey()+“:“+entry.getValue();System.out.println(“param:“+param.toString();out.write(par
12、am.toString();/ flush 输出流的缓冲out.flush();/ 定义 BufferedReader 输入流来读取 URL 的响应in = new BufferedReader(new InputStreamReader(conn.getInputStream(), “UTF-8“);String line;while (line = in.readLine() != null) result.append(line); catch (Exception e) e.printStackTrace();/使用 finally 块来关闭输出流、输入流finallytryif(ou
13、t!=null)out.close();if(in!=null)in.close();catch(IOException ex)ex.printStackTrace();return result.toString();2.2 C#对接using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;using System.Text;using System.Web;using System.Security.Cryptography.X509Certificate
14、s;using System.Net.Security;namespace Testpublic class KdApiEOrderDemo/电商 IDprivate string EBusinessID = “请申请 http:/ string AppKey = “请申请“;/请求 url/正式环境地址/ private string ReqURL = “http:/api.kdniao.cc/api/Eorderservice“;/测试环境地址private string ReqURL = “http:/testapi.kdniao.cc:8081/api/EOrderService“;/ / Json 方式 电子面单/