11package me .chanjar .weixin .mp .api ;
22
3+ import me .chanjar .weixin .common .bean .WxAccessToken ;
4+ import me .chanjar .weixin .common .util .ToStringUtils ;
5+ import me .chanjar .weixin .common .util .http .ApacheHttpClientBuilder ;
6+ import org .apache .http .ssl .SSLContexts ;
7+
8+ import javax .net .ssl .SSLContext ;
39import java .io .File ;
410import java .io .FileInputStream ;
511import java .security .KeyStore ;
612import java .util .concurrent .locks .Lock ;
713import java .util .concurrent .locks .ReentrantLock ;
814
9- import javax .net .ssl .SSLContext ;
10-
11- import org .apache .http .ssl .SSLContexts ;
12-
13- import me .chanjar .weixin .common .bean .WxAccessToken ;
14- import me .chanjar .weixin .common .util .ToStringUtils ;
15- import me .chanjar .weixin .common .util .http .ApacheHttpClientBuilder ;
16-
1715/**
1816 * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
19- * @author chanjarster
2017 *
18+ * @author chanjarster
2119 */
2220public class WxMpInMemoryConfigStorage implements WxMpConfigStorage {
2321
@@ -63,6 +61,10 @@ public String getAccessToken() {
6361 return this .accessToken ;
6462 }
6563
64+ public void setAccessToken (String accessToken ) {
65+ this .accessToken = accessToken ;
66+ }
67+
6668 @ Override
6769 public Lock getAccessTokenLock () {
6870 return this .accessTokenLock ;
@@ -94,15 +96,15 @@ public String getJsapiTicket() {
9496 return this .jsapiTicket ;
9597 }
9698
99+ public void setJsapiTicket (String jsapiTicket ) {
100+ this .jsapiTicket = jsapiTicket ;
101+ }
102+
97103 @ Override
98104 public Lock getJsapiTicketLock () {
99105 return this .jsapiTicketLock ;
100106 }
101107
102- public void setJsapiTicket (String jsapiTicket ) {
103- this .jsapiTicket = jsapiTicket ;
104- }
105-
106108 public long getJsapiTicketExpiresTime () {
107109 return this .jsapiTicketExpiresTime ;
108110 }
@@ -163,31 +165,35 @@ public String getAppId() {
163165 return this .appId ;
164166 }
165167
168+ public void setAppId (String appId ) {
169+ this .appId = appId ;
170+ }
171+
166172 @ Override
167173 public String getSecret () {
168174 return this .secret ;
169175 }
170176
177+ public void setSecret (String secret ) {
178+ this .secret = secret ;
179+ }
180+
171181 @ Override
172182 public String getToken () {
173183 return this .token ;
174184 }
175185
186+ public void setToken (String token ) {
187+ this .token = token ;
188+ }
189+
176190 @ Override
177191 public long getExpiresTime () {
178192 return this .expiresTime ;
179193 }
180194
181- public void setAppId (String appId ) {
182- this .appId = appId ;
183- }
184-
185- public void setSecret (String secret ) {
186- this .secret = secret ;
187- }
188-
189- public void setToken (String token ) {
190- this .token = token ;
195+ public void setExpiresTime (long expiresTime ) {
196+ this .expiresTime = expiresTime ;
191197 }
192198
193199 @ Override
@@ -199,14 +205,6 @@ public void setAesKey(String aesKey) {
199205 this .aesKey = aesKey ;
200206 }
201207
202- public void setAccessToken (String accessToken ) {
203- this .accessToken = accessToken ;
204- }
205-
206- public void setExpiresTime (long expiresTime ) {
207- this .expiresTime = expiresTime ;
208- }
209-
210208 @ Override
211209 public String getOauth2redirectUri () {
212210 return this .oauth2redirectUri ;
@@ -259,40 +257,40 @@ public String toString() {
259257
260258 @ Override
261259 public String getPartnerId () {
262- return this .partnerId ;
260+ return this .partnerId ;
263261 }
264262
265263 public void setPartnerId (String partnerId ) {
266- this .partnerId = partnerId ;
264+ this .partnerId = partnerId ;
267265 }
268266
269267 @ Override
270268 public String getPartnerKey () {
271- return this .partnerKey ;
269+ return this .partnerKey ;
272270 }
273271
274272 public void setPartnerKey (String partnerKey ) {
275- this .partnerKey = partnerKey ;
273+ this .partnerKey = partnerKey ;
274+ }
275+
276+
277+ public String getNotifyURL () {
278+ return notifyURL ;
276279 }
277-
278-
279- public String getNotifyURL () {
280- return notifyURL ;
281- }
282280
283- public void setNotifyURL (String notifyURL ) {
284- this .notifyURL = notifyURL ;
285- }
281+ public void setNotifyURL (String notifyURL ) {
282+ this .notifyURL = notifyURL ;
283+ }
286284
287- public String getTradeType () {
288- return tradeType ;
289- }
285+ public String getTradeType () {
286+ return tradeType ;
287+ }
290288
291- public void setTradeType (String tradeType ) {
292- this .tradeType = tradeType ;
293- }
289+ public void setTradeType (String tradeType ) {
290+ this .tradeType = tradeType ;
291+ }
294292
295- @ Override
293+ @ Override
296294 public File getTmpDirFile () {
297295 return this .tmpDirFile ;
298296 }
@@ -302,47 +300,43 @@ public void setTmpDirFile(File tmpDirFile) {
302300 }
303301
304302 @ Override
305- public SSLContext getSSLContext () {
303+ public SSLContext getSslContext () {
306304 return this .sslContext ;
307305 }
308-
306+
309307 @ Override
310- public SSLContext getSslContext () {
311- return this .sslContext ;
312- }
313-
314- @ Override
315- public void setSslContextFilePath (String filePath ) throws Exception {
316- if (null == partnerId ) {
317- throw new Exception ("请先将partnerId进行赋值" );
318- }
319- File file = new File (filePath );
320- if (!file .exists ()) {
321- throw new RuntimeException (file .getPath () + ":文件不存在!在设置SSLContext的时候" );
322- }
323- FileInputStream inputStream = new FileInputStream (file );
324- KeyStore keystore = KeyStore .getInstance ("PKCS12" );
325- char [] partnerId2charArray = partnerId .toCharArray ();
326- keystore .load (inputStream , partnerId2charArray );
327- this .sslContext = SSLContexts .custom ().loadKeyMaterial (keystore , partnerId2charArray ).build ();
328- }
329-
330- @ Override
331- public void setSslContext (SSLContext context ) {
332- this .sslContext = context ;
333- }
334-
308+ public void setSslContext (SSLContext context ) {
309+ this .sslContext = context ;
310+ }
311+
335312 @ Override
336- public ApacheHttpClientBuilder getApacheHttpClientBuilder () {
337- return this .apacheHttpClientBuilder ;
313+ public void setSslContextFilePath (String filePath ) throws Exception {
314+ if (null == partnerId ) {
315+ throw new Exception ("请先将partnerId进行赋值" );
316+ }
317+
318+ File file = new File (filePath );
319+ if (!file .exists ()) {
320+ throw new RuntimeException (file .getPath () + ":文件不存在!在设置SSLContext的时候" );
321+ }
322+ FileInputStream inputStream = new FileInputStream (file );
323+ KeyStore keystore = KeyStore .getInstance ("PKCS12" );
324+ char [] partnerId2charArray = partnerId .toCharArray ();
325+ keystore .load (inputStream , partnerId2charArray );
326+ this .sslContext = SSLContexts .custom ().loadKeyMaterial (keystore , partnerId2charArray ).build ();
338327 }
339328
340329 @ Override
341- public boolean autoRefreshToken () {
342- return true ;
330+ public ApacheHttpClientBuilder getApacheHttpClientBuilder () {
331+ return this . apacheHttpClientBuilder ;
343332 }
344333
345334 public void setApacheHttpClientBuilder (ApacheHttpClientBuilder apacheHttpClientBuilder ) {
346335 this .apacheHttpClientBuilder = apacheHttpClientBuilder ;
347336 }
337+
338+ @ Override
339+ public boolean autoRefreshToken () {
340+ return true ;
341+ }
348342}
0 commit comments