50,528
社区成员
发帖
与我相关
我的任务
分享
public static OnlineServerResult onlineCompare(String name, String cardno, Integer businessTypes,
String picNameR, String picNameT, OnlineServerConfig onlineServerConfig)
throws IOException {
lock.writeLock().lock();
String transactionID = getTransactionId(onlineServerConfig.getSourceCode());
lock.writeLock().unlock();
Logger logger = Logger.getLogger("comparelog");
logger.info("本次请求流水号transactionID:" + transactionID);
JsonObject reqParam = new JsonObject();
reqParam.addProperty("busiCode", onlineServerConfig.getBusiCode());
reqParam.addProperty("sourceCode", onlineServerConfig.getSourceCode());
reqParam.addProperty("targetCode", onlineServerConfig.getTargetCode());
reqParam.addProperty("version", onlineServerConfig.getVersion());
reqParam.addProperty("transactionID", transactionID);
JsonObject reqInfo = new JsonObject();
reqInfo.addProperty("userName", onlineServerConfig.getUserName());
reqInfo.addProperty("password", onlineServerConfig.getPassword());
reqInfo.addProperty("billId", "");
reqInfo.addProperty("custName", name);
reqInfo.addProperty("custCertNo", cardno);
reqInfo.addProperty("busiType", "1");
String reqInfoStr = null;
try {
RealNameMsDesPlus ms = new RealNameMsDesPlus();
reqInfoStr = ms.encrypt(reqInfo.toString());
} catch (Exception e) {
logger.error("请求json参数加密失败", e);
e.printStackTrace();
return null;
}
logger.info("reqInfo:" + reqInfo);
reqParam.addProperty("reqInfo", reqInfoStr);
JsonObject images = new JsonObject();
images.addProperty("picNameR", picNameR);
images.addProperty("picNameT", picNameT);
reqParam.add("images", images);
//json参数
JsonObject param = new JsonObject();
param.add("reqParam", reqParam);
logger.info("向在线公司发送请求参数:" + param);
String result = HttpUtil.doPost(onlineServerConfig.getUrl(), param.toString(),"application/json", "utf-8");
logger.info("在线公司响应json:" + result);
return new Gson().fromJson(result, OnlineServerResult.class);
}
public static String doPost(String url, String jsonData, String contentType, String charset)
throws IOException {
HttpClient httpClient = getHttpClient();
HttpPost httpPost = new HttpPost(url);
//body参数
StringEntity s = new StringEntity(jsonData);
s.setContentEncoding(charset);
if (contentType != null && !"".equals(contentType)) {
s.setContentType(contentType);//发送数据需要设置contentType
}
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
String result = EntityUtils.toString(entity, charset);
httpPost.releaseConnection();
return result;
}