|
@@ -10,6 +10,7 @@ import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
|
|
+import org.apache.http.entity.ContentType;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
import org.apache.http.impl.client.HttpClients;
|
|
@@ -116,14 +117,20 @@ public class WxOfficeAccountClient {
|
|
|
return cachedToken;
|
|
return cachedToken;
|
|
|
}
|
|
}
|
|
|
//2.如果Redis中没有,则调用微信接口获取
|
|
//2.如果Redis中没有,则调用微信接口获取
|
|
|
- String url = "https://api.weixin.qq.com/cgi-bin/stable_token" +
|
|
|
|
|
- "?grant_type=client_credential" +
|
|
|
|
|
- "&appid=" + appId +
|
|
|
|
|
- "&secret=" + secret;
|
|
|
|
|
|
|
+ String url = "https://api.weixin.qq.com/cgi-bin/stable_token";
|
|
|
|
|
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
- HttpGet httpGet = new HttpGet(url);
|
|
|
|
|
- try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
|
|
|
|
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
+
|
|
|
|
|
+ String jsonBody = String.format(
|
|
|
|
|
+ "{\"grant_type\": \"client_credential\", \"appid\": \"%s\", \"secret\": \"%s\"}",
|
|
|
|
|
+ appId, secret
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ StringEntity requestEntity = new StringEntity(jsonBody, ContentType.APPLICATION_JSON);
|
|
|
|
|
+ httpPost.setEntity(requestEntity);
|
|
|
|
|
+
|
|
|
|
|
+ try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
|
|
HttpEntity entity = response.getEntity();
|
|
HttpEntity entity = response.getEntity();
|
|
|
String result = EntityUtils.toString(entity);
|
|
String result = EntityUtils.toString(entity);
|
|
|
Map<String, Object> map = gson.fromJson(result, Map.class);
|
|
Map<String, Object> map = gson.fromJson(result, Map.class);
|