700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 常用快递电子面单接口API对接方法

常用快递电子面单接口API对接方法

时间:2020-02-18 06:31:52

相关推荐

常用快递电子面单接口API对接方法

快递电子面单接口API比较常用在电商、仓储系统和ERP系统,对接后不用下载安装软件,可以直接嵌入系统网站调用。

目前有快递鸟和菜鸟提供集成的电子面单打印接口,分别支持20,15家快递的电子面单打印

1.1 接口

(1)、订单编号(OrderCode)不可重复提交,重复提交系统会返回具体错误代码。

(2)、支持常用20家快递电子面单打印。

(3)、测试地址::8081/api/eorderservice/

(4)、正式地址:/api/EOrderService

(5)、接口申请:快递鸟网站注册账号申请接口

(6)、单号申请:部分快递需提前申请单号

1.2 系统级和应用级输入参数

1.3 返回结果参数

l同步返回

2 批量打印接口对接demo

package cc.kdniao.api;import java.io.IOException;import java.io.PrintWriter;import java.io.UnsupportedEncodingException;import .URLEncoder;import java.security.MessageDigest;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.sun.xml.internal.messaging.saaj.util.Base64;/*** Servlet implementation class printOrder*/@WebServlet("/printOrder")public class printOrder extends HttpServlet {private static final long serialVersionUID = 1L;final String EBussinessID = "";// EBusinessIDfinal String AppKey = ""; // AppKeyfinal Integer IsPreview = 0; //是否预览 0-不预览 1-预览/*** @see HttpServlet#HttpServlet()*/public printOrder() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stub//response.getWriter().append("Served at: ").append(request.getContextPath());PrintWriter print = response.getWriter();String jsonResult = "";try {String ip = getIpAddress(request);jsonResult = getPrintParam(ip);} catch (Exception e) {//write log}print.println(jsonResult);print.flush();print.close();}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, UnsupportedEncodingException {// TODO Auto-generated method stubresponse.setContentType("");PrintWriter print = response.getWriter();String jsonResult = "";try {String ip = getIpAddress(request);jsonResult = getPrintParam(ip);} catch (Exception e) {//wirte log}print.println(jsonResult);print.flush();print.close();}/*** get print order param to json string* @return** @throws Exception*/private String getPrintParam(String ip) throws Exception {String data = "[{\"OrderCode\":\"234351215333113311353\",\"PortName\":\"SF\"},{\"OrderCode\":\"234351215333113311354\",\"PortName\":\"打印机名称二\"}]";String result = "{\"RequestData\": \"" + URLEncoder.encode(data, "UTF-8") + "\", \"EBusinessID\":\"" + EBussinessID + "\", \"DataSign\":\"" + encrpy(ip + data, AppKey) + "\", \"IsPreview\":\""+ IsPreview + "\"}";return result;}private String md5(String str, String charset) throws Exception {MessageDigest md = MessageDigest.getInstance("MD5");md.update(str.getBytes(charset));byte[] result = md.digest();StringBuffer sb = new StringBuffer(32);for (int i = 0; i < result.length; i++) {int val = result[i] & 0xff;if (val <= 0xf) {sb.append("0");}sb.append(Integer.toHexString(val));}return sb.toString().toLowerCase();}private String encrpy(String content, String key) throws UnsupportedEncodingException, Exception {String charset = "UTF-8";return new String(Base64.encode(md5(content + key, charset).getBytes(charset)));}/*** 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址;* * @param request* @return* @throws IOException*/public final static String getIpAddress(HttpServletRequest request) throws IOException {// 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址 String ip = request.getHeader("X-Forwarded-For");if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {ip = request.getHeader("Proxy-Client-IP");}if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {ip = request.getHeader("WL-Proxy-Client-IP");}if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {ip = request.getHeader("HTTP_CLIENT_IP");}if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {ip = request.getHeader("HTTP_X_FORWARDED_FOR");}if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {ip = request.getRemoteAddr();}} else if (ip.length() > 15) {String[] ips = ip.split(",");for (int index = 0; index < ips.length; index++) {String strIp = (String) ips[index];if (!("unknown".equalsIgnoreCase(strIp))) {ip = strIp;break;}}}return ip;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。