|
|
|
@ -126,6 +126,47 @@ public class HttpsUtils { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static JSONObject doGet(String url, Map<String, String> params , Map<String , String> headers) { |
|
|
|
|
String apiUrl = url; |
|
|
|
|
StringBuffer param = new StringBuffer(); |
|
|
|
|
int i = 0; |
|
|
|
|
for (String key : params.keySet()) { |
|
|
|
|
if (i == 0) |
|
|
|
|
param.append("?"); |
|
|
|
|
else |
|
|
|
|
param.append("&"); |
|
|
|
|
param.append(key).append("=").append(params.get(key)); |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
apiUrl += param; |
|
|
|
|
String result = null; |
|
|
|
|
HttpClient httpClient = null; |
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
if (apiUrl.startsWith("https")) { |
|
|
|
|
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) |
|
|
|
|
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build(); |
|
|
|
|
} else { |
|
|
|
|
httpClient = HttpClients.createDefault(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HttpGet httpGet = new HttpGet(apiUrl); |
|
|
|
|
for (Map.Entry<String, String> e : headers.entrySet()) { |
|
|
|
|
httpGet.addHeader(e.getKey(), e.getValue()); |
|
|
|
|
} |
|
|
|
|
HttpResponse response = httpClient.execute(httpGet); |
|
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
|
if (entity != null) { |
|
|
|
|
InputStream instream = entity.getContent(); |
|
|
|
|
result = IOUtils.toString(instream, "UTF-8"); |
|
|
|
|
} |
|
|
|
|
return JSON.parseObject(result); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error(e.getMessage(),e); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static JSONObject doWxGet(String url, Map<String, Object> params) { |
|
|
|
|
String apiUrl = url; |
|
|
|
|
StringBuffer param = new StringBuffer(); |
|
|
|
|