标签:配置 basic treemap try 版本 pps mil success stack
做个记录
public ResultDto pddInvoiceDetailUpload(String platformCode,String customerCode,Map invocieMap) {
ResultDto returnDto = new ResultDto(true);
AppConfigService appConfigService = new AppConfigServiceImpl();
//接口配置
ResultDto appConfigDto = appConfigService.getAppConfig(platformCode,customerCode);
if(appConfigDto.isSuccess() == false){
returnDto = appConfigDto;
return returnDto;
}
//调用拼多多接口,SDK要求Java版本1.7以上,他大爷的...
CloseableHttpClient httpclient = null;
CloseableHttpResponse response = null;
StringBuilder stringBuilder = new StringBuilder();
try{
//应用级别参数
AppConfigDto appConfig = (AppConfigDto)appConfigDto.getData();
String url = appConfig.getAppUrl();
String clientId = appConfig.getAppKey();
String clientSecret = appConfig.getAppSecret();
String accessToken = appConfig.getAccessToken();
stringBuilder.append("\r\n"+new Date()+"appConfig:"+clientId+"--"+clientSecret+"--"+accessToken);
SystemLogSwitch.println("appConfig:"+clientId+"--"+clientSecret+"--"+accessToken);
//回传之前调用审核操作
ResultDto updateDto = pddInvoiceApplicationUpdate(appConfig,invocieMap.get("application_id").toString(),invocieMap.get("order_sn").toString(),"2","");
if(updateDto.isSuccess()==false){
returnDto.setSuccess(false);
returnDto.setMessage(updateDto.getMessage());
return returnDto;
}
httpclient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
//系统参数
Map<String,String> map = new TreeMap<String,String>();
map.put("type","pdd.invoice.detail.upload");
map.put("client_id",clientId);
map.put("access_token",accessToken);
map.put("timestamp",String.valueOf(System.currentTimeMillis()));
//应用参数
Iterator<Map.Entry<String,String>> it = invocieMap.entrySet().iterator();
while(it.hasNext()){
Map.Entry<String, String> entry = it.next();
map.put(entry.getKey(),entry.getValue().toString());
}
//生成签名
String sign = SignUtils.sign(map,clientSecret);
map.put("sign",sign);
List<NameValuePair> params = new ArrayList<NameValuePair>();
Iterator<Map.Entry<String,String>> iterator = map.entrySet().iterator();
while(iterator.hasNext()){
Map.Entry<String, String> entry = iterator.next();
stringBuilder.append("\r\nKey = " + entry.getKey() + ", Value = " + entry.getValue());
SystemLogSwitch.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
params.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString()));
}
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
String result = "";
response = (CloseableHttpResponse) httpclient.execute(httpPost);
if (response != null) {
StatusLine status = response.getStatusLine();
int code = status.getStatusCode();
if (code != 200) {
returnDto.setSuccess(false);
returnDto.setMessage("http response code is " + code + "|reason:" + status.getReasonPhrase() + "|url:" + url);
return returnDto;
}
HttpEntity entity = response.getEntity();
if (entity == null) {
returnDto.setSuccess(false);
returnDto.setMessage("http response entity is null|url:" + url);
return returnDto;
}
result = EntityUtils.toString(response.getEntity(), HTTP.UTF_8);
}else{
returnDto.setSuccess(false);
returnDto.setMessage("http response is null|url:" + url);
return returnDto;
}
stringBuilder.append("\r\nresult--"+result);
SystemLogSwitch.println("result--"+result);
this.writeMessage(logPatch,"发票信息回传",stringBuilder.toString());
//解析返回结果
PddInvoiceDetailUploadResponseDto responseDto = JSON.parseObject(result,PddInvoiceDetailUploadResponseDto.class);
if(responseDto.getErrorResponse()!=null){
returnDto.setSuccess(false);
returnDto.setMessage(responseDto.getErrorResponse().getErrorMsg());
return returnDto;
}else{
returnDto.setData(responseDto.getInvoiceDetailUploadResponse().getSerialNno());
}
}catch (Exception ex){
ex.printStackTrace();
returnDto.setSuccess(false);
returnDto.setMessage(ex.getMessage());
}finally {
// 关闭连接,释放资源
try {if(httpclient!=null) httpclient.close();} catch (Exception e) {}
try {if(response!=null) response.close();} catch (Exception e) {}
}
return returnDto;
}
标签:配置 basic treemap try 版本 pps mil success stack
原文地址:https://www.cnblogs.com/childofheaven/p/10610289.html