|
|
@ -86,20 +86,24 @@ public class EnterpriseWeChatUtils { |
|
|
|
String resp; |
|
|
|
String resp; |
|
|
|
|
|
|
|
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
HttpGet httpGet = new HttpGet(enterpriseWeChatTokenUrlReplace); |
|
|
|
|
|
|
|
CloseableHttpResponse response = httpClient.execute(httpGet); |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
HttpGet httpGet = new HttpGet(enterpriseWeChatTokenUrlReplace); |
|
|
|
resp = EntityUtils.toString(entity, Constants.UTF_8); |
|
|
|
CloseableHttpResponse response = httpClient.execute(httpGet); |
|
|
|
EntityUtils.consume(entity); |
|
|
|
try { |
|
|
|
|
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
|
|
|
|
resp = EntityUtils.toString(entity, Constants.UTF_8); |
|
|
|
|
|
|
|
EntityUtils.consume(entity); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
response.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = JSON.parseObject(resp, |
|
|
|
|
|
|
|
new TypeToken<Map<String, Object>>() { |
|
|
|
|
|
|
|
}.getType()); |
|
|
|
|
|
|
|
return map.get("access_token").toString(); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
response.close(); |
|
|
|
httpClient.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = JSON.parseObject(resp, |
|
|
|
|
|
|
|
new TypeToken<Map<String, Object>>() { |
|
|
|
|
|
|
|
}.getType()); |
|
|
|
|
|
|
|
return map.get("access_token").toString(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -167,20 +171,25 @@ public class EnterpriseWeChatUtils { |
|
|
|
public static String sendEnterpriseWeChat(String charset, String data, String token) throws IOException { |
|
|
|
public static String sendEnterpriseWeChat(String charset, String data, String token) throws IOException { |
|
|
|
String enterpriseWeChatPushUrlReplace = enterpriseWeChatPushUrl.replaceAll("\\$token", token); |
|
|
|
String enterpriseWeChatPushUrlReplace = enterpriseWeChatPushUrl.replaceAll("\\$token", token); |
|
|
|
|
|
|
|
|
|
|
|
CloseableHttpClient httpclient = HttpClients.createDefault(); |
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
HttpPost httpPost = new HttpPost(enterpriseWeChatPushUrlReplace); |
|
|
|
|
|
|
|
httpPost.setEntity(new StringEntity(data, charset)); |
|
|
|
|
|
|
|
CloseableHttpResponse response = httpclient.execute(httpPost); |
|
|
|
|
|
|
|
String resp; |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
HttpPost httpPost = new HttpPost(enterpriseWeChatPushUrlReplace); |
|
|
|
resp = EntityUtils.toString(entity, charset); |
|
|
|
httpPost.setEntity(new StringEntity(data, charset)); |
|
|
|
EntityUtils.consume(entity); |
|
|
|
CloseableHttpResponse response = httpClient.execute(httpPost); |
|
|
|
|
|
|
|
String resp; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
|
|
|
|
resp = EntityUtils.toString(entity, charset); |
|
|
|
|
|
|
|
EntityUtils.consume(entity); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
response.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
logger.info("Enterprise WeChat send [{}], param:{}, resp:{}", |
|
|
|
|
|
|
|
enterpriseWeChatPushUrl, data, resp); |
|
|
|
|
|
|
|
return resp; |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
response.close(); |
|
|
|
httpClient.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
logger.info("Enterprise WeChat send [{}], param:{}, resp:{}", enterpriseWeChatPushUrl, data, resp); |
|
|
|
|
|
|
|
return resp; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|