|
@@ -1,6 +1,7 @@
|
|
|
package cn.binarywang.wx.miniapp.api.impl;
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
+import cn.binarywang.wx.miniapp.bean.WxMaStableAccessTokenRequest;
|
|
|
import cn.binarywang.wx.miniapp.config.WxMaConfig;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.util.http.HttpType;
|
|
@@ -11,6 +12,9 @@ import org.apache.http.HttpHost;
|
|
|
import org.apache.http.client.config.RequestConfig;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.ContentType;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.BasicResponseHandler;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
|
@@ -93,4 +97,40 @@ public class WxMaServiceHttpClientImpl extends BaseWxMaServiceImpl {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected String doGetStableAccessTokenRequest(boolean forceRefresh) throws IOException {
|
|
|
+ String url = StringUtils.isNotEmpty(this.getWxMaConfig().getAccessTokenUrl()) ?
|
|
|
+ this.getWxMaConfig().getAccessTokenUrl() : StringUtils.isNotEmpty(this.getWxMaConfig().getApiHostUrl()) ?
|
|
|
+ GET_STABLE_ACCESS_TOKEN.replace("https://api.weixin.qq.com", this.getWxMaConfig().getApiHostUrl()) :
|
|
|
+ GET_STABLE_ACCESS_TOKEN;
|
|
|
+
|
|
|
+ HttpPost httpPost = null;
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
+ try {
|
|
|
+ httpPost = new HttpPost(url);
|
|
|
+ if (this.getRequestHttpProxy() != null) {
|
|
|
+ RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
|
|
|
+ httpPost.setConfig(config);
|
|
|
+ }
|
|
|
+ WxMaStableAccessTokenRequest wxMaAccessTokenRequest = new WxMaStableAccessTokenRequest();
|
|
|
+ wxMaAccessTokenRequest.setAppid(this.getWxMaConfig().getAppid());
|
|
|
+ wxMaAccessTokenRequest.setSecret(this.getWxMaConfig().getSecret());
|
|
|
+ wxMaAccessTokenRequest.setGrantType("client_credential");
|
|
|
+ wxMaAccessTokenRequest.setForceRefresh(forceRefresh);
|
|
|
+ httpPost.setEntity(new StringEntity(wxMaAccessTokenRequest.toJson(), ContentType.APPLICATION_JSON));
|
|
|
+ response = getRequestHttpClient().execute(httpPost);
|
|
|
+ return new BasicResponseHandler().handleResponse(response);
|
|
|
+ } finally {
|
|
|
+ if (httpPost != null) {
|
|
|
+ httpPost.releaseConnection();
|
|
|
+ }
|
|
|
+ if (response != null) {
|
|
|
+ try {
|
|
|
+ response.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|