Skip to content

Commit c588303

Browse files
committed
🎨 #1700 公众号WxMpConfigStorage接口提供setHostConfig()方法,方便设置相关信息
1 parent edf8e18 commit c588303

File tree

2 files changed

+127
-14
lines changed

2 files changed

+127
-14
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/WxMpConfigStorage.java

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package me.chanjar.weixin.mp.config;
22

33
import me.chanjar.weixin.common.bean.WxAccessToken;
4+
import me.chanjar.weixin.common.enums.TicketType;
45
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
56
import me.chanjar.weixin.mp.bean.WxMpHostConfig;
6-
import me.chanjar.weixin.common.enums.TicketType;
77

88
import java.io.File;
99
import java.util.concurrent.locks.Lock;
@@ -14,10 +14,25 @@
1414
* @author chanjarster
1515
*/
1616
public interface WxMpConfigStorage {
17+
/**
18+
* Gets access token.
19+
*
20+
* @return the access token
21+
*/
1722
String getAccessToken();
1823

24+
/**
25+
* Gets access token lock.
26+
*
27+
* @return the access token lock
28+
*/
1929
Lock getAccessTokenLock();
2030

31+
/**
32+
* Is access token expired boolean.
33+
*
34+
* @return the boolean
35+
*/
2136
boolean isAccessTokenExpired();
2237

2338
/**
@@ -40,14 +55,34 @@ public interface WxMpConfigStorage {
4055
*/
4156
void updateAccessToken(String accessToken, int expiresInSeconds);
4257

58+
/**
59+
* Gets ticket.
60+
*
61+
* @param type the type
62+
* @return the ticket
63+
*/
4364
String getTicket(TicketType type);
4465

66+
/**
67+
* Gets ticket lock.
68+
*
69+
* @param type the type
70+
* @return the ticket lock
71+
*/
4572
Lock getTicketLock(TicketType type);
4673

74+
/**
75+
* Is ticket expired boolean.
76+
*
77+
* @param type the type
78+
* @return the boolean
79+
*/
4780
boolean isTicketExpired(TicketType type);
4881

4982
/**
5083
* 强制将ticket过期掉.
84+
*
85+
* @param type the type
5186
*/
5287
void expireTicket(TicketType type);
5388

@@ -61,44 +96,115 @@ public interface WxMpConfigStorage {
6196
*/
6297
void updateTicket(TicketType type, String ticket, int expiresInSeconds);
6398

99+
/**
100+
* Gets app id.
101+
*
102+
* @return the app id
103+
*/
64104
String getAppId();
65105

106+
/**
107+
* Gets secret.
108+
*
109+
* @return the secret
110+
*/
66111
String getSecret();
67112

113+
/**
114+
* Gets token.
115+
*
116+
* @return the token
117+
*/
68118
String getToken();
69119

120+
/**
121+
* Gets aes key.
122+
*
123+
* @return the aes key
124+
*/
70125
String getAesKey();
71126

127+
/**
128+
* Gets template id.
129+
*
130+
* @return the template id
131+
*/
72132
String getTemplateId();
73133

134+
/**
135+
* Gets expires time.
136+
*
137+
* @return the expires time
138+
*/
74139
long getExpiresTime();
75140

141+
/**
142+
* Gets oauth 2 redirect uri.
143+
*
144+
* @return the oauth 2 redirect uri
145+
*/
76146
String getOauth2redirectUri();
77147

148+
/**
149+
* Gets http proxy host.
150+
*
151+
* @return the http proxy host
152+
*/
78153
String getHttpProxyHost();
79154

155+
/**
156+
* Gets http proxy port.
157+
*
158+
* @return the http proxy port
159+
*/
80160
int getHttpProxyPort();
81161

162+
/**
163+
* Gets http proxy username.
164+
*
165+
* @return the http proxy username
166+
*/
82167
String getHttpProxyUsername();
83168

169+
/**
170+
* Gets http proxy password.
171+
*
172+
* @return the http proxy password
173+
*/
84174
String getHttpProxyPassword();
85175

176+
/**
177+
* Gets tmp dir file.
178+
*
179+
* @return the tmp dir file
180+
*/
86181
File getTmpDirFile();
87182

88183
/**
89184
* http client builder.
90185
*
91-
* @return ApacheHttpClientBuilder
186+
* @return ApacheHttpClientBuilder apache http client builder
92187
*/
93188
ApacheHttpClientBuilder getApacheHttpClientBuilder();
94189

95190
/**
96191
* 是否自动刷新token.
192+
*
193+
* @return the boolean
97194
*/
98195
boolean autoRefreshToken();
99196

100197
/**
101198
* 得到微信接口地址域名部分的自定义设置信息.
199+
*
200+
* @return the host config
102201
*/
103202
WxMpHostConfig getHostConfig();
203+
204+
/**
205+
* 设置微信接口地址域名部分的自定义设置信息.
206+
*
207+
* @param hostConfig host config
208+
*/
209+
void setHostConfig(WxMpHostConfig hostConfig);
104210
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/impl/WxMpDefaultConfigImpl.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package me.chanjar.weixin.mp.config.impl;
22

3-
import java.io.File;
4-
import java.io.Serializable;
5-
import java.util.concurrent.locks.Lock;
6-
import java.util.concurrent.locks.ReentrantLock;
7-
83
import lombok.Data;
94
import me.chanjar.weixin.common.bean.WxAccessToken;
5+
import me.chanjar.weixin.common.enums.TicketType;
106
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
11-
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
127
import me.chanjar.weixin.mp.bean.WxMpHostConfig;
13-
import me.chanjar.weixin.common.enums.TicketType;
8+
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
149
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
1510

11+
import java.io.File;
12+
import java.io.Serializable;
13+
import java.util.concurrent.locks.Lock;
14+
import java.util.concurrent.locks.ReentrantLock;
15+
1616
/**
1717
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化.
1818
*
@@ -46,15 +46,17 @@ public class WxMpDefaultConfigImpl implements WxMpConfigStorage, Serializable {
4646
protected volatile String cardApiTicket;
4747
protected volatile long cardApiTicketExpiresTime;
4848

49-
protected Lock accessTokenLock = new ReentrantLock();
50-
protected Lock jsapiTicketLock = new ReentrantLock();
51-
protected Lock sdkTicketLock = new ReentrantLock();
52-
protected Lock cardApiTicketLock = new ReentrantLock();
49+
protected volatile Lock accessTokenLock = new ReentrantLock();
50+
protected volatile Lock jsapiTicketLock = new ReentrantLock();
51+
protected volatile Lock sdkTicketLock = new ReentrantLock();
52+
protected volatile Lock cardApiTicketLock = new ReentrantLock();
5353

5454
protected volatile File tmpDirFile;
5555

5656
protected volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
5757

58+
private WxMpHostConfig hostConfig = null;
59+
5860
@Override
5961
public boolean isAccessTokenExpired() {
6062
return System.currentTimeMillis() > this.expiresTime;
@@ -183,7 +185,12 @@ public boolean autoRefreshToken() {
183185

184186
@Override
185187
public WxMpHostConfig getHostConfig() {
186-
return null;
188+
return this.hostConfig;
189+
}
190+
191+
@Override
192+
public void setHostConfig(WxMpHostConfig hostConfig) {
193+
this.hostConfig = hostConfig;
187194
}
188195

189196
}

0 commit comments

Comments
 (0)