常见问题
常见问题
业务客服: 点击这里给我发消息
技术客服: 点击这里给我发消息
API文档

代码示例:(Java为例)

通用示例:基于Apache HttpClient v4.3

                    import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;


public class HttpUtilDsrt {
	

	public static String ENCODING = "UTF-8";
	private static String URL="http://dsrt.yiwu2word.com/dsrt/import/batch";
	

	public static String send(String url, String message) {
		String content = "";
		String result = "";
		try {
			HttpClient httpClient = HttpClients.createDefault();
			HttpPost httppost = new HttpPost(url);
			StringEntity myEntity = new StringEntity(message, ENCODING);
			httppost.addHeader("Content-Type", "application/json");
			httppost.setEntity(myEntity);
			HttpResponse response = null;
			try {
				response = httpClient.execute(httppost);
				HttpEntity resEntity = response.getEntity();
				InputStreamReader reader = new InputStreamReader(
						resEntity.getContent(), ENCODING);
				char[] buff = new char[1024];
				int length = 0;
				while ((length = reader.read(buff)) != -1) {
					content = new String(buff, 0, length);
					result = result + content;
				}
			} catch (ClientProtocolException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				HttpClientUtils.closeQuietly(response);
				HttpClientUtils.closeQuietly(httpClient);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return result;
	}

	public static void main(String[] args) {
		String contentString = "{\"content\":[{\"orderNo\":\"2300920309419\",
		\"waybillNo\":\"300293aE393999\",\"companyName\":\"eee\",\"tradTime\":
		\"2016-01-29T15:13:38.754+0800\",\"countryName\":\"美国\",\"logisticName\":
		\"中外运\",\"logisticType\":\"空运\",\"totalPkg\":3,\"totalPrice\":9.45,
		\"addTime\":\"2016-01-29T15:13:38.754+0800\",\"companyCode\":\"3322\",
		\"list\":[{\"goodsPrice\":3.34,\"chName\":\"qqqq\",\"enName\":\"englishname\",
		\"hsCode\":\"30293000\",\"goodsNum\":2,\"declaredAmount\":3.34,\"currencyCode\":
		\"142\",\"currencyName\":\"人民币\"},{\"goodsPrice\":3.35,\"chName\":\"eee\",\"enName\":
		\"\",\"hsCode\":\"30293000\",\"goodsNum\":2,\"declaredAmount\":3.35,\"currencyCode\":
		\"142\",\"currencyName\":\"人民币\"}]}],\"appId\":\"yiwt0000aaaa\",\"type\":\"export\",
		\"signData\":\"6d2aa22d1337603f8dcf00382a9f57a6\",\"companyCode\":\"aabbcc\"}";
		send(URL, contentString);
	}
}

					
                    

client示例:本示例基于义网通的restclient.jar包,如果合作方使用Java可以向义网通索要该开发包。

                    package com.ywt.restclient.test;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.ywt.restclient.client.dsrt.DsrtClient;
import com.ywt.restclient.domain.DsrWayBillDetail;
import com.ywt.restclient.domain.DsrWayBillInfo;
import com.ywt.restclient.domain.DsrtBatchMessage;
import com.ywt.restclient.domain.DsrtMessageResultBean;
import com.ywt.restclient.domain.DsrtOneMessage;
import com.ywt.restclient.domain.DsrtQueryOrderBean;
import com.ywt.restclient.domain.DsrtQueryOrderContentBean;
import com.ywt.restclient.domain.DsrtQueryOrderResultBean;

public class TestDsrt {

	public static void main(String[] args) {
		ApplicationContext context = new FileSystemXmlApplicationContext
		("D:/develop/WORKSPACES/ywtrestclient/config/spring/ywt-rest-config-beans.xml");
		//获取客户端实例
		DsrtClient client=(DsrtClient)context.getBean("dsrtClient");
		//导入单条请求消息实例
		DsrtOneMessage oneMessage= new DsrtOneMessage();
		//
		oneMessage.setAppId("");
		oneMessage.setCompanyCode("aabbcc");
		oneMessage.setType("export");
		//运单信息实例
		DsrWayBillInfo content=new DsrWayBillInfo();
		content.setAddTime(new Date());
		content.setOrderNo("23009203099SS");
		content.setWaybillNo("30029393999SS");
		content.setCompanyName("eee");
		content.setLogisticName("中外运");
		content.setLogisticType("空运");
		content.setTotalPkg(new BigDecimal("3"));
		content.setCountryName("美国");
		content.setCompanyCode("3322");
		content.setTotalPrice(new BigDecimal("9.45"));
		content.setTradTime(new Date());
		//运单详情list
		List dsrWayBillDetails = new ArrayList();
		DsrWayBillDetail detail0 = new DsrWayBillDetail();
		detail0.setChName("qqqq");
		detail0.setEnName("englishname");
		detail0.setGoodsNum(new BigDecimal("2"));
		detail0.setGoodsPrice(new BigDecimal("3.34"));
		detail0.setCurrencyCode("142");
		detail0.setCurrencyName("人民币");
		detail0.setDeclaredAmount(new BigDecimal("3.34"));
		detail0.setHsCode("30293000");
		
		DsrWayBillDetail detail1 = new DsrWayBillDetail();
		detail1.setChName("eee");
		detail1.setEnName("");
		detail1.setGoodsNum(new BigDecimal("2"));
		detail1.setGoodsPrice(new BigDecimal("3.36"));
		detail1.setCurrencyCode("142");
		detail1.setCurrencyName("人民币");
		detail1.setDeclaredAmount(new BigDecimal("3.35"));
		detail1.setHsCode("30293000");
		
		dsrWayBillDetails.add(detail0);
		dsrWayBillDetails.add(detail1);
		//设置运单详情list
		content.setList(dsrWayBillDetails);
		//设置单条消息内容
		oneMessage.setContent(content);
		//通过客户端发送内容并接受返回
		DsrtMessageResultBean resultBean=client.putOne(oneMessage, "33309023920");
		
		System.out.println(resultBean);
		DsrtBatchMessage batchMessage=new DsrtBatchMessage();
		batchMessage.setAppId("yiwt0000aaaa");
		batchMessage.setCompanyCode("aabbcc");
		batchMessage.setType("export");
		List content1=new ArrayList();
		content1.add(content);
		batchMessage.setContent(content1);
		DsrtMessageResultBean resultBean1=client.putBatch(batchMessage, "062a3ac10eda8a847336f8bcd460d74b");
		System.out.println(resultBean1);
		DsrtQueryOrderBean queryOrderBean=new DsrtQueryOrderBean();
		queryOrderBean.setAppId("yiwt0000aaaa");
		queryOrderBean.setCompanyCode("6");
		queryOrderBean.setType("queryOrder");
		DsrtQueryOrderContentBean contentBean=new DsrtQueryOrderContentBean();
		contentBean.setStartTime(DateUtils.addDays(new Date(), -1));
		contentBean.setPageNum(1);
		contentBean.setPageSize(10);
		contentBean.setEndTime(DateUtils.addDays(new Date(), 1));
		contentBean.setWaybillNo("2");
		queryOrderBean.setContent(contentBean);
		DsrtQueryOrderResultBean resultBean3=client.queryOrder
		(queryOrderBean, "062a3ac10eda8a847336f8bcd460d74b");
		System.out.println(resultBean3);
		DsrtQueryOrderResultBean resultBean4=client.queryOrderDetail
		(queryOrderBean, "062a3ac10eda8a847336f8bcd460d74b");
		
		System.out.println(resultBean4);
	}
	
	
}

                    

地 址:浙江省义乌市机场路588号 邮 箱:cs@yiwu2world.com 咨询热线:18157938685

版权所有: 义乌市国际陆港集团有限公司 浙ICP备15025827号-2 © Copyright 2015