1:近来工作上需要对接paypal ,有关支付,退款等等都有相关的SDK集成。但是此时的项目需求,我需要对接的纠纷模块,然而paypal相关的纠纷是没有现成的SDK的。所以只能自己写;里面有多种种坑道记录一下。
下面是对接paypal 纠纷数据 拓展中的 争议信息回复 。
功能点:其中发送信息和用户交互 ,其中包含了 多文件上传的功能(小弟能力有限,里面遇到坑道,在下面记录一下,若有同样问题,可以参考参考);
HttpPost httpPost = new HttpPost(disputeLinks.getUrl());
//这里对应上的 头部TOKEN ,本应该这里按照文档上操作,还需要设置 头部 app****/json的 ,切记,这个地方不能放
httpPost.setHeader(HttpHeaders.AUTHORIZATION,environment.authorizationString());
//重点在这里
MultipartEntityBuilder create = MultipartEntityBuilder.create();
Map<String,String> requetBody = new HashMap<String,String>();
requetBody.put("message", disputeLinks.getMessage());
//需要回复的消息 组成 json
create.addTextBody("input",JSONObject.toJSONString(requetBody), ContentType.APPLICATION_JSON);
//若存在 的话循环 文件
if(null != disputeLinks.getFiles()) {
try {
for(MultipartFile file : disputeLinks.getFiles()) {
create.addBinaryBody("file", file.getInputStream(),ContentType.DEFAULT_BINARY,
file.getOriginalFilename());
}
} catch (Exception e) {
e.printStackTrace();
return new ResponseResult("文件提取错误");
}
}
httpPost.setEntity(create.build());
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
String json = EntityUtils.toString(response.getEntity());
JSONObject resultResponse = JSON.parseObject(json);
}else {
return new ResponseResult("提交失败 "+statusCode);
}
} catch (Exception e) {
e.printStackTrace();
return new ResponseResult("请求PAYPAL错误"+e);
} finally {
HttpClientUtils.closeQuietly(response);
}
return new ResponseResult("提交成功");
}
实现的记过是成功的;
希望能帮助到大家。