8000 #567 微信开放平台增加 HTTP proxy 机制 · devandroid/weixin-java-tools@04ec788 · GitHub
[go: up one dir, main page]

Skip to content

Commit 04ec788

Browse files
charmingohbinarywang
authored andcommitted
binarywang#567 微信开放平台增加 HTTP proxy 机制
* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀; * 微信开放平台:增加小程序代码模板库管理 * 小程序:增加代码管理相关 API * 小程序:增加修改服务器地址、成员管理 API * 小程序:增加数据分析相关 API * 微信开放平台:增加 HTTP proxy 机制
1 parent 3c2249e commit 04ec788

File tree

4 files changed

+75
-8
lines changed

4 files changed

+75
-8
lines changed

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public interface WxOpenConfigStorage {
3838

3939
void updateComponentAccessTokent(WxOpenComponentAccessToken componentAccessToken);
4040

41+
String getHttpProxyHost();
42+
43+
int getHttpProxyPort();
44+
45+
String getHttpProxyUsername();
46+
47+
String getHttpProxyPassword();
48+
4149
WxMpConfigStorage getWxMpConfigStorage(String appId);
4250

4351
WxMaConfig getWxMaConfig(String appId);
@@ -117,5 +125,4 @@ public interface WxOpenConfigStorage {
117125
* @param expiresInSeconds 过期时间,以秒为单位
118126
*/
119127
void updateCardApiTicket(String appId, String cardApiTicket, int expiresInSeconds);
120-
121128
}

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
3030
private String componentAccessToken;
3131
private long componentExpiresTime;
3232

33+
private String httpProxyHost;
34+
private int httpProxyPort;
35+
private String httpProxyUsername;
36+
private String httpProxyPassword;
37+
3338
private Map<String, Token> authorizerRefreshTokens = new Hashtable<>();
3439
private Map<String, Token> authorizerAccessTokens = new Hashtable<>();
3540
private Map<String, Token> jsapiTickets = new Hashtable<>();
@@ -105,6 +110,42 @@ public void updateComponentAccessTokent(WxOpenComponentAccessToken componentAcce
105110
updateComponentAccessTokent(componentAccessToken.getComponentAccessToken(), componentAccessToken.getExpiresIn());
106111
}
107112

113+
@Override
114+
public String getHttpProxyHost() {
115+
return httpProxyHost;
116+
}
117+
118+
public void setHttpProxyHost(String httpProxyHost) {
119+
this.httpProxyHost = httpProxyHost;
120+
}
121+
122+
@Override
123+
public int getHttpProxyPort() {
124+
return httpProxyPort;
125+
}
126+
127+
public void setHttpProxyPort(int httpProxyPort) {
128+
this.httpProxyPort = httpProxyPort;
129+
}
130+
131+
@Override
132+
public String getHttpProxyUsername() {
133+
return httpProxyUsername;
134+
}
135+
136+
public void setHttpProxyUsername(String httpProxyUsername) {
137+
this.httpProxyUsername = httpProxyUsername;
138+
}
139+
140+
@Override
141+
public String getHttpProxyPassword() {
142+
return httpProxyPassword;
143+
}
144+
145+
public void setHttpProxyPassword(String httpProxyPassword) {
146+
this.httpProxyPassword = httpProxyPassword;
147+
}
148+
108149
@Override
109150
public WxMpConfigStorage getWxMpConfigStorage(String appId) {
110151
return new WxOpenInnerConfigStorage(this, appId);
@@ -377,22 +418,22 @@ public String getOauth2redirectUri() {
377418

378419
@Override
379420
public String getHttpProxyHost() {
380-
return null;
421+
return this.wxOpenConfigStorage.getHttpProxyHost();
381422
}
382423

383424
@Override
384425
public int getHttpProxyPort() {
385-
return 0;
426+
return this.wxOpenConfigStorage.getHttpProxyPort();
386427
}
387428

388429
@Override
389430
public String getHttpProxyUsername() {
390-
return null;
431+
return this.wxOpenConfigStorage.getHttpProxyUsername();
391432
}
392433

393434
@Override
394435
public String getHttpProxyPassword() {
395-
return null;
436+
return this.wxOpenConfigStorage.getHttpProxyPassword();
396437
}
397438

398439
@Override

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceAbstractImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ public WxOpenConfigStorage getWxOpenConfigStorage() {
3333
@Override< B41A /span>
3434
public void setWxOpenConfigStorage(WxOpenConfigStorage wxOpenConfigStorage) {
3535
this.wxOpenConfigStorage = wxOpenConfigStorage;
36+
this.initHttp();
3637
}
3738

39+
/**
40+
* 初始化 RequestHttp
41+
*/
42+
public abstract void initHttp();
43+
3844
protected synchronized <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
3945
try {
4046
T result = executor.execute(uri, data);

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
66
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
77
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
8+
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
89
import org.apache.http.HttpHost;
910
import org.apache.http.impl.client.CloseableHttpClient;
1011

@@ -14,8 +15,21 @@
1415
* @author <a href="https://github.com/007gzs">007</a>
1516
*/
1617
public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl<CloseableHttpClient, HttpHost> {
17-
private CloseableHttpClient httpClient = DefaultApacheHttpClientBuilder.get().build();
18-
private HttpHost httpProxy = null;
18+
private CloseableHttpClient httpClient;
19+
private HttpHost httpProxy;
20+
21+
@Override
22+
public void initHttp() {
23+
WxOpenConfigStorage configStorage = this.getWxOpenConfigStorage();
24+
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
25+
this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());
26+
}
27+
this.httpClient = DefaultApacheHttpClientBuilder.get()
28+
.httpProxyHost(configStorage.getHttpProxyHost())
29+
.httpProxyPort(configStorage.getHttpProxyPort())
30+
.httpProxyUsername(configStorage.getHttpProxyUsername())
31+
.httpProxyPassword(configStorage.getHttpProxyPassword()).build();
32+
}
1933

2034
@Override
2135
public CloseableHttpClient getRequestHttpClient() {
@@ -41,5 +55,4 @@ public String get(String url, String queryParam) throws WxErrorException {
4155
public String post(String url, String postData) throws WxErrorException {
4256
return execute(SimplePostRequestExecutor.create(this), url, postData);
4357
}
44-
4558
}

0 commit comments

Comments
 (0)
0