Java对接圆通电子面单下单接口

Java对接圆通电子面单下单接口

package test;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.MessageDigest;
import org.apache.commons.codec.binary.Base64;

/**
 * 创建订单
 * @author luojia
 *
 */
public class CreateOrderModeB {
     

	public static void main(String[] args) {
     

		String apiUrl = "http://58.32.246.71:8000/CommonOrderModeBPlusServlet.action     ";
		String clientId = "K21000119";
		String customerId = "K21000119";
		String parternId = "u2Z1F7Fh";
		//String mailNo = "5555555358";//申请但没有使用过的电子面单号
		String array[] = {
     
			"81132426447"
		};

		for(int i=0; i<array.length; i++){
     
		try{
     
			//打开连接
			URL url = new URL(apiUrl);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.setDoOutput(true);
			connection.setRequestMethod("POST");
			OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
			//数据
			StringBuilder xmlBuilder = new StringBuilder();
			xmlBuilder.append("");
			xmlBuilder.append("    "+clientId+"");
			xmlBuilder.append("    YTO");
			xmlBuilder.append("    "+customerId+"");
			xmlBuilder.append("    "+"LP"+array[i]+"");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    1");
			xmlBuilder.append("    ");
			xmlBuilder.append("        小明");
			xmlBuilder.append("        123456");
			xmlBuilder.append("        1234567");
			xmlBuilder.append("        18221885929");
			xmlBuilder.append("        湖南省");
			xmlBuilder.append("        郴州市,资兴市");
			xmlBuilder.append("        
湖南省郴州市资兴市市立中学
"
); xmlBuilder.append(" "); xmlBuilder.append(" "); xmlBuilder.append(" 小红"); xmlBuilder.append(" 123456"); xmlBuilder.append(" 1234567"); xmlBuilder.append(" 18221885929"); xmlBuilder.append(" 湖南省"); xmlBuilder.append(" 郴州市,资兴市"); xmlBuilder.append("
湖南省郴州市资兴市资兴市二中
"
); xmlBuilder.append(" "); xmlBuilder.append(" "); xmlBuilder.append(" "); xmlBuilder.append(" 36ab0b08-3b5c-4423-a352-08477f050e55"); xmlBuilder.append(" 2"); xmlBuilder.append(" 50"); xmlBuilder.append(" "); xmlBuilder.append(" "); xmlBuilder.append(" 0a4e51b9-5616-4feb-b8a8-d2e1ba24401f"); xmlBuilder.append(" 2"); xmlBuilder.append(" 50"); xmlBuilder.append(" "); xmlBuilder.append(" "); xmlBuilder.append(""); //加密 MessageDigest messagedigest = MessageDigest.getInstance("MD5"); messagedigest.update((xmlBuilder.toString() + parternId).getBytes("UTF-8")); byte[] abyte0 = messagedigest.digest(); String data_digest = new String(Base64.encodeBase64(abyte0)); //开始时间 long a = System.currentTimeMillis(); //查询 String queryString = "logistics_interface=" + URLEncoder.encode(xmlBuilder.toString(), "UTF-8") + "&data_digest="+ URLEncoder.encode(data_digest,"UTF-8") + "&clientId=" + URLEncoder.encode(clientId, "UTF-8"); out.write(queryString); out.flush(); out.close(); //获取服务端的反馈 String responseString = ""; String strLine = ""; InputStream in = connection.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); while ((strLine = reader.readLine()) != null) { responseString += strLine + "\n"; } in.close(); //结束时间 long b = System.currentTimeMillis(); //响应时间 long c = b - a; System.err.print("响应时间:"+c + "ms\n"); System.err.print("请求的返回信息:"+responseString); }catch(Exception e){ e.printStackTrace(); } } } }

你可能感兴趣的:(圆通电子面单下单接口,java,接口,圆通面单打印)