对接京东接口之图片上传jingdong.las.picture.upload(Java实现)
对接京东接口流程如下:
Java代码如下:
public static String serverUrl = "https://api.jdwl.com/routerjson";
public static String accessToken = "***";//您的访问Token
public static String appKey = "***";//您的APP KEY
public static String appSecret = "***";//您的APP Secret
public static String serProNo = "***";//您的服务商编号,京东提供
public static String searchToken = "123456";//获取订单的校验码
// 上传图片
public static void lasPictureUploadLop() throws JdException, IOException {
JdClient client = new DefaultJdClient(serverUrl,accessToken,appKey,appSecret);
LasPictureUploadLopRequest request = new LasPictureUploadLopRequest();
FileDto dto = new FileDto();
dto.setFileName("1.png");
dto.setFileData(InputStream2ByteArray("D:\\1.png"));
request.setPin("123456");
request.setDto(dto);
LasPictureUploadResponse response = client.execute(request);
System.out.println(response.getResult().getContent());
}private static Byte[] InputStream2ByteArray(String filePath) throws IOException {
InputStream in = new FileInputStream(filePath);
byte[] data = toByteArray(in);
in.close();
Byte[] returndata=new Byte[data.length];
for (int i = 0; i < data.length; i++) {
returndata[i]=data[i];
}
return returndata;
}
private static byte[] toByteArray(InputStream in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024 * 4];
int n = 0;
while ((n = in.read(buffer)) != -1) {
out.write(buffer, 0, n);
}
return out.toByteArray();
}
源码项目目录如下: