Skip to content

Commit 415ea95

Browse files
committed
issue binarywang#29 http代理支持
1 parent 3067468 commit 415ea95

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,23 @@
1111

1212
/**
1313
* http请求执行器
14-
* @author Daniel Qian
1514
*
1615
* @param <T> 返回值类型
1716
* @param <E> 请求参数类型
1817
*/
1918
public interface RequestExecutor<T, E> {
2019

20+
/**
21+
*
22+
* @param httpclient 传入的httpClient
23+
* @param httpProxy http代理对象,如果没有配置代理则为空
24+
* @param uri uri
25+
* @param data 数据
26+
* @return
27+
* @throws WxErrorException
28+
* @throws ClientProtocolException
29+
* @throws IOException
30+
*/
2131
public T execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, E data) throws WxErrorException, ClientProtocolException, IOException;
2232

2333
}

‎weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.http.auth.UsernamePasswordCredentials;
2626
import org.apache.http.client.ClientProtocolException;
2727
import org.apache.http.client.CredentialsProvider;
28+
import org.apache.http.client.config.RequestConfig;
2829
import org.apache.http.client.methods.CloseableHttpResponse;
2930
import org.apache.http.client.methods.HttpGet;
3031
import org.apache.http.impl.client.BasicCredentialsProvider;
@@ -85,6 +86,10 @@ public void accessTokenRefresh() throws WxErrorException {
8586
+ "&corpsecret=" + wxCpConfigStorage.getCorpSecret();
8687
try {
8788
HttpGet httpGet = new HttpGet(url);
89+
if (httpProxy != null) {
90+
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
91+
httpGet.setConfig(config);
92+
}
8893
CloseableHttpClient httpclient = getHttpclient();
8994
CloseableHttpResponse response = httpclient.execute(httpGet);
9095
String resultContent = new BasicResponseHandler().handleResponse(response);

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.http.auth.UsernamePasswordCredentials;
2525
import org.apache.http.client.ClientProtocolException;
2626
import org.apache.http.client.CredentialsProvider;
27+
import org.apache.http.client.config.RequestConfig;
2728
import org.apache.http.client.methods.CloseableHttpResponse;
2829
import org.apache.http.client.methods.HttpGet;
2930
import org.apache.http.client.methods.HttpPost;
@@ -75,6 +76,10 @@ public void accessTokenRefresh() throws WxErrorException {
7576
;
7677
try {
7778
HttpGet httpGet = new HttpGet(url);
79+
if (httpProxy != null) {
80+
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
81+
httpGet.setConfig(config);
82+
}
7883
CloseableHttpClient httpclient = getHttpclient();
7984
CloseableHttpResponse response = httpclient.execute(httpGet);
8085
String resultContent = new BasicResponseHandler().handleResponse(response);

0 commit comments

Comments
 (0)