|
|
|
@@ -2,6 +2,7 @@ package com.iformall.douyin.miniapp.api.impl; |
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
|
|
|
import cn.binarywang.wx.miniapp.config.WxMaConfig; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.google.common.base.Joiner; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.google.gson.JsonParser; |
|
|
|
@@ -22,6 +23,8 @@ 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.StringEntity; |
|
|
|
import org.apache.http.impl.client.BasicResponseHandler; |
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
|
|
|
|
@@ -101,15 +104,22 @@ public class TtMaServiceImpl implements TtMaService, RequestHttp<CloseableHttpCl |
|
|
|
Lock lock = this.getWxMaConfig().getAccessTokenLock(); |
|
|
|
lock.lock(); |
|
|
|
try { |
|
|
|
String url = String.format(this.GET_ACCESS_TOKEN_URL, this.getWxMaConfig().getAppid(), |
|
|
|
this.getWxMaConfig().getSecret()); |
|
|
|
// String url = String.format(this.GET_ACCESS_TOKEN_URL, this.getWxMaConfig().getAppid(), |
|
|
|
// this.getWxMaConfig().getSecret()); |
|
|
|
try { |
|
|
|
HttpGet httpGet = new HttpGet(url); |
|
|
|
HttpPost httpPost = new HttpPost(this.GET_ACCESS_TOKEN_URL); |
|
|
|
httpPost.addHeader("Content-Type","application/json"); |
|
|
|
Map<String,Object> param = new HashMap<>(); |
|
|
|
param.put("appid",this.getWxMaConfig().getAppid()); |
|
|
|
param.put("secret",this.getWxMaConfig().getSecret()); |
|
|
|
param.put("grant_type","client_credential"); |
|
|
|
httpPost.setEntity(new StringEntity(JSON.toJSONString(param))); |
|
|
|
// HttpGet httpGet = new HttpGet(url); |
|
|
|
if (this.getRequestHttpProxy() != null) { |
|
|
|
RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build(); |
|
|
|
httpGet.setConfig(config); |
|
|
|
httpPost.setConfig(config); |
|
|
|
} |
|
|
|
try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) { |
|
|
|
try (CloseableHttpResponse response = getRequestHttpClient().execute(httpPost)) { |
|
|
|
String resultContent = new BasicResponseHandler().handleResponse(response); |
|
|
|
WxError error = WxError.fromJson(resultContent, WxType.MiniApp); |
|
|
|
if (error.getErrorCode() != 0) { |
|
|
|
@@ -120,7 +130,7 @@ public class TtMaServiceImpl implements TtMaService, RequestHttp<CloseableHttpCl |
|
|
|
|
|
|
|
return this.getWxMaConfig().getAccessToken(); |
|
|
|
} finally { |
|
|
|
httpGet.releaseConnection(); |
|
|
|
httpPost.releaseConnection(); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
@@ -141,7 +151,8 @@ public class TtMaServiceImpl implements TtMaService, RequestHttp<CloseableHttpCl |
|
|
|
params.put("secret", config.getSecret()); |
|
|
|
params.put("code", jsCode); |
|
|
|
|
|
|
|
String result = get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params)); |
|
|
|
String result =post(this.JSCODE_TO_SESSION_URL,params); |
|
|
|
// String result = get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params)); |
|
|
|
return WxMaJscode2SessionResult.fromJson(result); |
|
|
|
} |
|
|
|
|
|
|
|
|