public String getOrderEvidence(Map<String, String> parameters){
String json= JSON.toJSONString(parameters);
try {
String postURL = GlobalConstant.ORDER_EVIDENCE_URL;
PostMethod postMethod = null;
postMethod = new PostMethod(postURL) ;
postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") ;
//参数设置,需要注意的就是里边不能传NULL,要传空字符串
NameValuePair[] data = {
new NameValuePair("parameters",json)
};
postMethod.setRequestBody(data);
//连接超时设置为4秒
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(2000).build();
HttpPost httpPost = new HttpPost(postURL);
httpPost.setConfig(requestConfig);
org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
int response = httpClient.executeMethod(postMethod); // 执行POST方法
String result = postMethod.getResponseBodyAsString() ;
JSONObject jsonObject = new JSONObject(result);
if(jsonObject!=null){
JSONObject dataObject = jsonObject.getJSONObject("data");
if(dataObject!=null){
Integer errCode = dataObject.getInt("errCode");
/**
* 错误码 错误码定义
* 0 SUCCESS
* -1 模型不存在(表里没数据)
* -2 上链信息不存在(表里没数据)
* -3 数据未上链
* -4 查询信息缺少appkey信息(入参缺少appkey)
* -5 查询信息缺少primaryKey信息(入参缺少primaryKey)
* -6 查询信息缺少tableName信息(入参缺少tableName)
*/
if(errCode == 0){
String evidenceCode = dataObject.getString("data");
return evidenceCode;
}else{
log.error("====getOrderEvidence区块链错误码-1 模型不存在-2 上链信息不存在(表里没数据)-3 数据未上链 -4 参数缺少appkey -5 缺少primaryKey -6 缺少tableName==========" + errCode);
return "";
}
}else{
return "";
}
}else{
return "";
}
} catch (Exception e) {
log.error("getOrderEvidence请求异常"+e.getMessage(),e);
return "";
}
}