1
0
mirror of synced 2025-12-18 22:08:01 +08:00

🎨 #1700 公众号WxMpConfigStorage接口提供setHostConfig()方法,方便设置相关信息

This commit is contained in:
Binary Wang
2020-08-08 16:25:34 +08:00
parent edf8e18c5b
commit c588303d8a
2 changed files with 128 additions and 15 deletions

View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.mp.config; package me.chanjar.weixin.mp.config;
import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.enums.TicketType;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.mp.bean.WxMpHostConfig; import me.chanjar.weixin.mp.bean.WxMpHostConfig;
import me.chanjar.weixin.common.enums.TicketType;
import java.io.File; import java.io.File;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
@@ -14,10 +14,25 @@ import java.util.concurrent.locks.Lock;
* @author chanjarster * @author chanjarster
*/ */
public interface WxMpConfigStorage { public interface WxMpConfigStorage {
/**
* Gets access token.
*
* @return the access token
*/
String getAccessToken(); String getAccessToken();
/**
* Gets access token lock.
*
* @return the access token lock
*/
Lock getAccessTokenLock(); Lock getAccessTokenLock();
/**
* Is access token expired boolean.
*
* @return the boolean
*/
boolean isAccessTokenExpired(); boolean isAccessTokenExpired();
/** /**
@@ -40,14 +55,34 @@ public interface WxMpConfigStorage {
*/ */
void updateAccessToken(String accessToken, int expiresInSeconds); void updateAccessToken(String accessToken, int expiresInSeconds);
/**
* Gets ticket.
*
* @param type the type
* @return the ticket
*/
String getTicket(TicketType type); String getTicket(TicketType type);
/**
* Gets ticket lock.
*
* @param type the type
* @return the ticket lock
*/
Lock getTicketLock(TicketType type); Lock getTicketLock(TicketType type);
/**
* Is ticket expired boolean.
*
* @param type the type
* @return the boolean
*/
boolean isTicketExpired(TicketType type); boolean isTicketExpired(TicketType type);
/** /**
* 强制将ticket过期掉. * 强制将ticket过期掉.
*
* @param type the type
*/ */
void expireTicket(TicketType type); void expireTicket(TicketType type);
@@ -61,44 +96,115 @@ public interface WxMpConfigStorage {
*/ */
void updateTicket(TicketType type, String ticket, int expiresInSeconds); void updateTicket(TicketType type, String ticket, int expiresInSeconds);
/**
* Gets app id.
*
* @return the app id
*/
String getAppId(); String getAppId();
/**
* Gets secret.
*
* @return the secret
*/
String getSecret(); String getSecret();
/**
* Gets token.
*
* @return the token
*/
String getToken(); String getToken();
/**
* Gets aes key.
*
* @return the aes key
*/
String getAesKey(); String getAesKey();
/**
* Gets template id.
*
* @return the template id
*/
String getTemplateId(); String getTemplateId();
/**
* Gets expires time.
*
* @return the expires time
*/
long getExpiresTime(); long getExpiresTime();
/**
* Gets oauth 2 redirect uri.
*
* @return the oauth 2 redirect uri
*/
String getOauth2redirectUri(); String getOauth2redirectUri();
/**
* Gets http proxy host.
*
* @return the http proxy host
*/
String getHttpProxyHost(); String getHttpProxyHost();
/**
* Gets http proxy port.
*
* @return the http proxy port
*/
int getHttpProxyPort(); int getHttpProxyPort();
/**
* Gets http proxy username.
*
* @return the http proxy username
*/
String getHttpProxyUsername(); String getHttpProxyUsername();
/**
* Gets http proxy password.
*
* @return the http proxy password
*/
String getHttpProxyPassword(); String getHttpProxyPassword();
/**
* Gets tmp dir file.
*
* @return the tmp dir file
*/
File getTmpDirFile(); File getTmpDirFile();
/** /**
* http client builder. * http client builder.
* *
* @return ApacheHttpClientBuilder * @return ApacheHttpClientBuilder apache http client builder
*/ */
ApacheHttpClientBuilder getApacheHttpClientBuilder(); ApacheHttpClientBuilder getApacheHttpClientBuilder();
/** /**
* 是否自动刷新token. * 是否自动刷新token.
*
* @return the boolean
*/ */
boolean autoRefreshToken(); boolean autoRefreshToken();
/** /**
* 得到微信接口地址域名部分的自定义设置信息. * 得到微信接口地址域名部分的自定义设置信息.
*
* @return the host config
*/ */
WxMpHostConfig getHostConfig(); WxMpHostConfig getHostConfig();
/**
* 设置微信接口地址域名部分的自定义设置信息.
*
* @param hostConfig host config
*/
void setHostConfig(WxMpHostConfig hostConfig);
} }

View File

@@ -1,18 +1,18 @@
package me.chanjar.weixin.mp.config.impl; package me.chanjar.weixin.mp.config.impl;
import lombok.Data;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.enums.TicketType;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.mp.bean.WxMpHostConfig;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.File; import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import lombok.Data;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.bean.WxMpHostConfig;
import me.chanjar.weixin.common.enums.TicketType;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/** /**
* 基于内存的微信配置provider在实际生产环境中应该将这些配置持久化. * 基于内存的微信配置provider在实际生产环境中应该将这些配置持久化.
* *
@@ -46,15 +46,17 @@ public class WxMpDefaultConfigImpl implements WxMpConfigStorage, Serializable {
protected volatile String cardApiTicket; protected volatile String cardApiTicket;
protected volatile long cardApiTicketExpiresTime; protected volatile long cardApiTicketExpiresTime;
protected Lock accessTokenLock = new ReentrantLock(); protected volatile Lock accessTokenLock = new ReentrantLock();
protected Lock jsapiTicketLock = new ReentrantLock(); protected volatile Lock jsapiTicketLock = new ReentrantLock();
protected Lock sdkTicketLock = new ReentrantLock(); protected volatile Lock sdkTicketLock = new ReentrantLock();
protected Lock cardApiTicketLock = new ReentrantLock(); protected volatile Lock cardApiTicketLock = new ReentrantLock();
protected volatile File tmpDirFile; protected volatile File tmpDirFile;
protected volatile ApacheHttpClientBuilder apacheHttpClientBuilder; protected volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
private WxMpHostConfig hostConfig = null;
@Override @Override
public boolean isAccessTokenExpired() { public boolean isAccessTokenExpired() {
return System.currentTimeMillis() > this.expiresTime; return System.currentTimeMillis() > this.expiresTime;
@@ -183,7 +185,12 @@ public class WxMpDefaultConfigImpl implements WxMpConfigStorage, Serializable {
@Override @Override
public WxMpHostConfig getHostConfig() { public WxMpHostConfig getHostConfig() {
return null; return this.hostConfig;
}
@Override
public void setHostConfig(WxMpHostConfig hostConfig) {
this.hostConfig = hostConfig;
} }
} }