|
|
|
@ -303,6 +303,45 @@ public class HttpsUtils { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static JSONObject doPost(String apiUrl, String str, String token, String sign, Long ts) { |
|
|
|
|
CloseableHttpClient httpClient = null; |
|
|
|
|
if (apiUrl.startsWith("https")) { |
|
|
|
|
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) |
|
|
|
|
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build(); |
|
|
|
|
} else { |
|
|
|
|
httpClient = HttpClients.createDefault(); |
|
|
|
|
} |
|
|
|
|
String httpStr = null; |
|
|
|
|
CloseableHttpResponse response = null; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
HttpPost httpPost = new HttpPost(apiUrl); |
|
|
|
|
httpPost.setConfig(requestConfig); |
|
|
|
|
httpPost.setHeader("token", token); |
|
|
|
|
httpPost.setHeader("sign", sign); |
|
|
|
|
httpPost.setHeader("ts", ts.toString()); |
|
|
|
|
StringEntity stringEntity = new StringEntity(str, "UTF-8");// 解决中文乱码问题
|
|
|
|
|
stringEntity.setContentEncoding("UTF-8"); |
|
|
|
|
stringEntity.setContentType("application/json"); |
|
|
|
|
httpPost.setEntity(stringEntity); |
|
|
|
|
response = httpClient.execute(httpPost); |
|
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
|
httpStr = EntityUtils.toString(entity, "UTF-8"); |
|
|
|
|
return JSON.parseObject(httpStr); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error(e.getMessage(),e); |
|
|
|
|
} finally { |
|
|
|
|
if (response != null) { |
|
|
|
|
try { |
|
|
|
|
EntityUtils.consume(response.getEntity()); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
log.error(e.getMessage(),e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 创建SSL安全连接 |
|
|
|
|
* |
|
|
|
|