🎨 格式化部分代码

This commit is contained in:
Binary Wang 2021-06-02 19:55:53 +08:00
parent c9fad3121c
commit fdd3a94131
7 changed files with 857 additions and 149 deletions

View File

@ -24,13 +24,31 @@ public interface WxCpConfigStorage {
/** /**
* 读取企业微信 API Url. * 读取企业微信 API Url.
* 支持私有化企业微信服务器. * 支持私有化企业微信服务器.
*
* @param path the path
* @return the api url
*/ */
String getApiUrl(String path); String getApiUrl(String path);
/**
* 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();
/** /**
@ -38,14 +56,40 @@ public interface WxCpConfigStorage {
*/ */
void expireAccessToken(); void expireAccessToken();
/**
* Update access token.
*
* @param accessToken the access token
*/
void updateAccessToken(WxAccessToken accessToken); void updateAccessToken(WxAccessToken accessToken);
/**
* Update access token.
*
* @param accessToken the access token
* @param expiresIn the expires in
*/
void updateAccessToken(String accessToken, int expiresIn); void updateAccessToken(String accessToken, int expiresIn);
/**
* Gets jsapi ticket.
*
* @return the jsapi ticket
*/
String getJsapiTicket(); String getJsapiTicket();
/**
* Gets jsapi ticket lock.
*
* @return the jsapi ticket lock
*/
Lock getJsapiTicketLock(); Lock getJsapiTicketLock();
/**
* Is jsapi ticket expired boolean.
*
* @return the boolean
*/
boolean isJsapiTicketExpired(); boolean isJsapiTicketExpired();
/** /**
@ -55,13 +99,31 @@ public interface WxCpConfigStorage {
/** /**
* 应该是线程安全的. * 应该是线程安全的.
*
* @param jsapiTicket the jsapi ticket
* @param expiresInSeconds the expires in seconds
*/ */
void updateJsapiTicket(String jsapiTicket, int expiresInSeconds); void updateJsapiTicket(String jsapiTicket, int expiresInSeconds);
/**
* Gets agent jsapi ticket.
*
* @return the agent jsapi ticket
*/
String getAgentJsapiTicket(); String getAgentJsapiTicket();
/**
* Gets agent jsapi ticket lock.
*
* @return the agent jsapi ticket lock
*/
Lock getAgentJsapiTicketLock(); Lock getAgentJsapiTicketLock();
/**
* Is agent jsapi ticket expired boolean.
*
* @return the boolean
*/
boolean isAgentJsapiTicketExpired(); boolean isAgentJsapiTicketExpired();
/** /**
@ -71,51 +133,114 @@ public interface WxCpConfigStorage {
/** /**
* 应该是线程安全的. * 应该是线程安全的.
*
* @param jsapiTicket the jsapi ticket
* @param expiresInSeconds the expires in seconds
*/ */
void updateAgentJsapiTicket(String jsapiTicket, int expiresInSeconds); void updateAgentJsapiTicket(String jsapiTicket, int expiresInSeconds);
/**
* Gets corp id.
*
* @return the corp id
*/
String getCorpId(); String getCorpId();
/**
* Gets corp secret.
*
* @return the corp secret
*/
String getCorpSecret(); String getCorpSecret();
/**
* Gets agent id.
*
* @return the agent id
*/
Integer getAgentId(); Integer getAgentId();
/**
* Gets token.
*
* @return the token
*/
String getToken(); String getToken();
/**
* Gets aes key.
*
* @return the aes key
*/
String getAesKey(); String getAesKey();
/**
* 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 . * @return . boolean
*/ */
boolean autoRefreshToken(); boolean autoRefreshToken();
/** /**
* 获取群机器人webhook的key * 获取群机器人webhook的key
* *
* @return key * @return key webhook key
*/ */
String getWebhookKey(); String getWebhookKey();
} }

View File

@ -25,106 +25,361 @@ public interface WxCpTpConfigStorage {
/** /**
* 读取企业微信 API Url. * 读取企业微信 API Url.
* 支持私有化企业微信服务器. * 支持私有化企业微信服务器.
*
* @param path the path
* @return the api url
*/ */
String getApiUrl(String path); String getApiUrl(String path);
/** /**
* 第三方应用的suite access token相关 * 第三方应用的suite access token相关
*
* @return the suite access token
*/ */
String getSuiteAccessToken(); String getSuiteAccessToken();
/** /**
* 获取suite_access_token和剩余过期时间 * 获取suite_access_token和剩余过期时间
*
* @return suite access token and the remaining expiration time * @return suite access token and the remaining expiration time
*/ */
WxAccessToken getSuiteAccessTokenEntity(); WxAccessToken getSuiteAccessTokenEntity();
/**
* Is suite access token expired boolean.
*
* @return the boolean
*/
boolean isSuiteAccessTokenExpired(); boolean isSuiteAccessTokenExpired();
/**
* Expire suite access token.
*/
//强制将suite access token过期掉. //强制将suite access token过期掉.
void expireSuiteAccessToken(); void expireSuiteAccessToken();
/**
* Update suite access token.
*
* @param suiteAccessToken the suite access token
*/
void updateSuiteAccessToken(WxAccessToken suiteAccessToken); void updateSuiteAccessToken(WxAccessToken suiteAccessToken);
/**
* Update suite access token.
*
* @param suiteAccessToken the suite access token
* @param expiresInSeconds the expires in seconds
*/
void updateSuiteAccessToken(String suiteAccessToken, int expiresInSeconds); void updateSuiteAccessToken(String suiteAccessToken, int expiresInSeconds);
/** /**
* 第三方应用的suite ticket相关 * 第三方应用的suite ticket相关
*
* @return the suite ticket
*/ */
String getSuiteTicket(); String getSuiteTicket();
/**
* Is suite ticket expired boolean.
*
* @return the boolean
*/
boolean isSuiteTicketExpired(); boolean isSuiteTicketExpired();
/**
* Expire suite ticket.
*/
//强制将suite ticket过期掉. //强制将suite ticket过期掉.
void expireSuiteTicket(); void expireSuiteTicket();
/**
* Update suite ticket.
*
* @param suiteTicket the suite ticket
* @param expiresInSeconds the expires in seconds
*/
//应该是线程安全的 //应该是线程安全的
void updateSuiteTicket(String suiteTicket, int expiresInSeconds); void updateSuiteTicket(String suiteTicket, int expiresInSeconds);
/** /**
* 第三方应用的其他配置来自于企微配置 * 第三方应用的其他配置来自于企微配置
*
* @return the suite id
*/ */
String getSuiteId(); String getSuiteId();
/**
* Gets suite secret.
*
* @return the suite secret
*/
String getSuiteSecret(); String getSuiteSecret();
/**
* Gets token.
*
* @return the token
*/
// 第三方应用的token用来检查应用的签名 // 第三方应用的token用来检查应用的签名
String getToken(); String getToken();
/**
* Gets aes key.
*
* @return the aes key
*/
//第三方应用的EncodingAESKey用来检查签名 //第三方应用的EncodingAESKey用来检查签名
String getAesKey(); String getAesKey();
/** /**
* 企微服务商企业ID & 企业secret * 企微服务商企业ID & 企业secret
*
* @return the corp id
*/ */
String getCorpId(); String getCorpId();
/**
* Gets corp secret.
*
* @return the corp secret
*/
String getCorpSecret(); String getCorpSecret();
/** /**
* 服务商secret * 服务商secret
*
* @return the provider secret
*/ */
String getProviderSecret(); String getProviderSecret();
/** /**
* 授权企业的access token相关 * 授权企业的access token相关
*
* @param authCorpId the auth corp id
* @return the access token
*/ */
String getAccessToken(String authCorpId); String getAccessToken(String authCorpId);
/**
* Gets access token entity.
*
* @param authCorpId the auth corp id
* @return the access token entity
*/
WxAccessToken getAccessTokenEntity(String authCorpId); WxAccessToken getAccessTokenEntity(String authCorpId);
/**
* Is access token expired boolean.
*
* @param authCorpId the auth corp id
* @return the boolean
*/
boolean isAccessTokenExpired(String authCorpId); boolean isAccessTokenExpired(String authCorpId);
/**
* Expire access token.
*
* @param authCorpId the auth corp id
*/
void expireAccessToken(String authCorpId); void expireAccessToken(String authCorpId);
/**
* Update access token.
*
* @param authCorpId the auth corp id
* @param accessToken the access token
* @param expiredInSeconds the expired in seconds
*/
void updateAccessToken(String authCorpId, String accessToken, int expiredInSeconds); void updateAccessToken(String authCorpId, String accessToken, int expiredInSeconds);
/** /**
* 授权企业的js api ticket相关 * 授权企业的js api ticket相关
*
* @param authCorpId the auth corp id
* @return the auth corp js api ticket
*/ */
String getAuthCorpJsApiTicket(String authCorpId); String getAuthCorpJsApiTicket(String authCorpId);
/**
* Is auth corp js api ticket expired boolean.
*
* @param authCorpId the auth corp id
* @return the boolean
*/
boolean isAuthCorpJsApiTicketExpired(String authCorpId); boolean isAuthCorpJsApiTicketExpired(String authCorpId);
/**
* Expire auth corp js api ticket.
*
* @param authCorpId the auth corp id
*/
void expireAuthCorpJsApiTicket(String authCorpId); void expireAuthCorpJsApiTicket(String authCorpId);
/**
* Update auth corp js api ticket.
*
* @param authCorpId the auth corp id
* @param jsApiTicket the js api ticket
* @param expiredInSeconds the expired in seconds
*/
void updateAuthCorpJsApiTicket(String authCorpId, String jsApiTicket, int expiredInSeconds); void updateAuthCorpJsApiTicket(String authCorpId, String jsApiTicket, int expiredInSeconds);
/** /**
* 授权企业的第三方应用js api ticket相关 * 授权企业的第三方应用js api ticket相关
*
* @param authCorpId the auth corp id
* @return the auth suite js api ticket
*/ */
String getAuthSuiteJsApiTicket(String authCorpId); String getAuthSuiteJsApiTicket(String authCorpId);
boolean isAuthSuiteJsApiTicketExpired(String authCorpId);
void expireAuthSuiteJsApiTicket(String authCorpId);
void updateAuthSuiteJsApiTicket(String authCorpId, String jsApiTicket, int expiredInSeconds);;
/**
* Is auth suite js api ticket expired boolean.
*
* @param authCorpId the auth corp id
* @return the boolean
*/
boolean isAuthSuiteJsApiTicketExpired(String authCorpId);
/**
* Expire auth suite js api ticket.
*
* @param authCorpId the auth corp id
*/
void expireAuthSuiteJsApiTicket(String authCorpId);
/**
* Update auth suite js api ticket.
*
* @param authCorpId the auth corp id
* @param jsApiTicket the js api ticket
* @param expiredInSeconds the expired in seconds
*/
void updateAuthSuiteJsApiTicket(String authCorpId, String jsApiTicket, int expiredInSeconds);
;
/**
* Is provider token expired boolean.
*
* @return the boolean
*/
boolean isProviderTokenExpired(); boolean isProviderTokenExpired();
/**
* Update provider token.
*
* @param providerToken the provider token
* @param expiredInSeconds the expired in seconds
*/
void updateProviderToken(String providerToken, int expiredInSeconds); void updateProviderToken(String providerToken, int expiredInSeconds);
/**
* Gets provider token.
*
* @return the provider token
*/
String getProviderToken(); String getProviderToken();
/**
* Gets provider token entity.
*
* @return the provider token entity
*/
WxCpProviderToken getProviderTokenEntity(); WxCpProviderToken getProviderTokenEntity();
/**
* Expire provider token.
*/
// 强制过期 // 强制过期
void expireProviderToken(); void expireProviderToken();
/** /**
* 网络代理相关 * 网络代理相关
*
* @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 apache http client builder.
*
* @return the apache http client builder
*/
ApacheHttpClientBuilder getApacheHttpClientBuilder(); ApacheHttpClientBuilder getApacheHttpClientBuilder();
/**
* Auto refresh token boolean.
*
* @return the boolean
*/
boolean autoRefreshToken(); boolean autoRefreshToken();
/**
* Gets tmp dir file.
*
* @return the tmp dir file
*/
// 毫无相关性的代码 // 毫无相关性的代码
@Deprecated @Deprecated
File getTmpDirFile(); File getTmpDirFile();
/**
* Gets provider access token lock.
*
* @return the provider access token lock
*/
Lock getProviderAccessTokenLock(); Lock getProviderAccessTokenLock();
/**
* Gets suite access token lock.
*
* @return the suite access token lock
*/
Lock getSuiteAccessTokenLock(); Lock getSuiteAccessTokenLock();
/**
* Gets access token lock.
*
* @param authCorpId the auth corp id
* @return the access token lock
*/
Lock getAccessTokenLock(String authCorpId); Lock getAccessTokenLock(String authCorpId);
/**
* Gets auth corp jsapi ticket lock.
*
* @param authCorpId the auth corp id
* @return the auth corp jsapi ticket lock
*/
Lock getAuthCorpJsapiTicketLock(String authCorpId); Lock getAuthCorpJsapiTicketLock(String authCorpId);
/**
* Gets suite jsapi ticket lock.
*
* @param authCorpId the auth corp id
* @return the suite jsapi ticket lock
*/
Lock getSuiteJsapiTicketLock(String authCorpId); Lock getSuiteJsapiTicketLock(String authCorpId);
} }

View File

@ -18,30 +18,39 @@ import java.util.concurrent.locks.ReentrantLock;
*/ */
public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable { public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
private static final long serialVersionUID = 1154541446729462780L; private static final long serialVersionUID = 1154541446729462780L;
/**
* The Access token.
*/
protected volatile String accessToken;
/**
* The Access token lock.
*/
protected transient Lock accessTokenLock = new ReentrantLock();
/**
* The Agent id.
*/
protected volatile Integer agentId;
/**
* The Jsapi ticket lock.
*/
protected transient Lock jsapiTicketLock = new ReentrantLock();
/**
* The Agent jsapi ticket lock.
*/
protected transient Lock agentJsapiTicketLock = new ReentrantLock();
private volatile String corpId; private volatile String corpId;
private volatile String corpSecret; private volatile String corpSecret;
private volatile String token; private volatile String token;
protected volatile String accessToken;
protected transient Lock accessTokenLock = new ReentrantLock();
private volatile String aesKey; private volatile String aesKey;
protected volatile Integer agentId;
private volatile long expiresTime; private volatile long expiresTime;
private volatile String oauth2redirectUri; private volatile String oauth2redirectUri;
private volatile String httpProxyHost; private volatile String httpProxyHost;
private volatile int httpProxyPort; private volatile int httpProxyPort;
private volatile String httpProxyUsername; private volatile String httpProxyUsername;
private volatile String httpProxyPassword; private volatile String httpProxyPassword;
private volatile String jsapiTicket; private volatile String jsapiTicket;
protected transient Lock jsapiTicketLock = new ReentrantLock();
private volatile long jsapiTicketExpiresTime; private volatile long jsapiTicketExpiresTime;
private volatile String agentJsapiTicket; private volatile String agentJsapiTicket;
protected transient Lock agentJsapiTicketLock = new ReentrantLock();
private volatile long agentJsapiTicketExpiresTime; private volatile long agentJsapiTicketExpiresTime;
private volatile File tmpDirFile; private volatile File tmpDirFile;
@ -70,15 +79,20 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.accessToken; return this.accessToken;
} }
/**
* Sets access token.
*
* @param accessToken the access token
*/
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
@Override @Override
public Lock getAccessTokenLock() { public Lock getAccessTokenLock() {
return this.accessTokenLock; return this.accessTokenLock;
} }
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
@Override @Override
public boolean isAccessTokenExpired() { public boolean isAccessTokenExpired() {
return System.currentTimeMillis() > this.expiresTime; return System.currentTimeMillis() > this.expiresTime;
@ -105,19 +119,34 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.jsapiTicket; return this.jsapiTicket;
} }
/**
* Sets jsapi ticket.
*
* @param jsapiTicket the jsapi ticket
*/
public void setJsapiTicket(String jsapiTicket) {
this.jsapiTicket = jsapiTicket;
}
@Override @Override
public Lock getJsapiTicketLock() { public Lock getJsapiTicketLock() {
return this.jsapiTicketLock; return this.jsapiTicketLock;
} }
public void setJsapiTicket(String jsapiTicket) { /**
this.jsapiTicket = jsapiTicket; * Gets jsapi ticket expires time.
} *
* @return the jsapi ticket expires time
*/
public long getJsapiTicketExpiresTime() { public long getJsapiTicketExpiresTime() {
return this.jsapiTicketExpiresTime; return this.jsapiTicketExpiresTime;
} }
/**
* Sets jsapi ticket expires time.
*
* @param jsapiTicketExpiresTime the jsapi ticket expires time
*/
public void setJsapiTicketExpiresTime(long jsapiTicketExpiresTime) { public void setJsapiTicketExpiresTime(long jsapiTicketExpiresTime) {
this.jsapiTicketExpiresTime = jsapiTicketExpiresTime; this.jsapiTicketExpiresTime = jsapiTicketExpiresTime;
} }
@ -171,6 +200,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.corpId; return this.corpId;
} }
/**
* Sets corp id.
*
* @param corpId the corp id
*/
public void setCorpId(String corpId) { public void setCorpId(String corpId) {
this.corpId = corpId; this.corpId = corpId;
} }
@ -180,6 +214,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.corpSecret; return this.corpSecret;
} }
/**
* Sets corp secret.
*
* @param corpSecret the corp secret
*/
public void setCorpSecret(String corpSecret) { public void setCorpSecret(String corpSecret) {
this.corpSecret = corpSecret; this.corpSecret = corpSecret;
} }
@ -189,6 +228,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.token; return this.token;
} }
/**
* Sets token.
*
* @param token the token
*/
public void setToken(String token) { public void setToken(String token) {
this.token = token; this.token = token;
} }
@ -198,6 +242,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.expiresTime; return this.expiresTime;
} }
/**
* Sets expires time.
*
* @param expiresTime the expires time
*/
public void setExpiresTime(long expiresTime) { public void setExpiresTime(long expiresTime) {
this.expiresTime = expiresTime; this.expiresTime = expiresTime;
} }
@ -207,6 +256,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.aesKey; return this.aesKey;
} }
/**
* Sets aes key.
*
* @param aesKey the aes key
*/
public void setAesKey(String aesKey) { public void setAesKey(String aesKey) {
this.aesKey = aesKey; this.aesKey = aesKey;
} }
@ -216,6 +270,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.agentId; return this.agentId;
} }
/**
* Sets agent id.
*
* @param agentId the agent id
*/
public void setAgentId(Integer agentId) { public void setAgentId(Integer agentId) {
this.agentId = agentId; this.agentId = agentId;
} }
@ -225,6 +284,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.oauth2redirectUri; return this.oauth2redirectUri;
} }
/**
* Sets oauth 2 redirect uri.
*
* @param oauth2redirectUri the oauth 2 redirect uri
*/
public void setOauth2redirectUri(String oauth2redirectUri) { public void setOauth2redirectUri(String oauth2redirectUri) {
this.oauth2redirectUri = oauth2redirectUri; this.oauth2redirectUri = oauth2redirectUri;
} }
@ -234,6 +298,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.httpProxyHost; return this.httpProxyHost;
} }
/**
* Sets http proxy host.
*
* @param httpProxyHost the http proxy host
*/
public void setHttpProxyHost(String httpProxyHost) { public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost; this.httpProxyHost = httpProxyHost;
} }
@ -243,6 +312,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.httpProxyPort; return this.httpProxyPort;
} }
/**
* Sets http proxy port.
*
* @param httpProxyPort the http proxy port
*/
public void setHttpProxyPort(int httpProxyPort) { public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort; this.httpProxyPort = httpProxyPort;
} }
@ -252,6 +326,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.httpProxyUsername; return this.httpProxyUsername;
} }
/**
* Sets http proxy username.
*
* @param httpProxyUsername the http proxy username
*/
public void setHttpProxyUsername(String httpProxyUsername) { public void setHttpProxyUsername(String httpProxyUsername) {
this.httpProxyUsername = httpProxyUsername; this.httpProxyUsername = httpProxyUsername;
} }
@ -261,6 +340,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.httpProxyPassword; return this.httpProxyPassword;
} }
/**
* Sets http proxy password.
*
* @param httpProxyPassword the http proxy password
*/
public void setHttpProxyPassword(String httpProxyPassword) { public void setHttpProxyPassword(String httpProxyPassword) {
this.httpProxyPassword = httpProxyPassword; this.httpProxyPassword = httpProxyPassword;
} }
@ -275,6 +359,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.tmpDirFile; return this.tmpDirFile;
} }
/**
* Sets tmp dir file.
*
* @param tmpDirFile the tmp dir file
*/
public void setTmpDirFile(File tmpDirFile) { public void setTmpDirFile(File tmpDirFile) {
this.tmpDirFile = tmpDirFile; this.tmpDirFile = tmpDirFile;
} }
@ -284,6 +373,15 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.apacheHttpClientBuilder; return this.apacheHttpClientBuilder;
} }
/**
* Sets apache http client builder.
*
* @param apacheHttpClientBuilder the apache http client builder
*/
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
@Override @Override
public boolean autoRefreshToken() { public boolean autoRefreshToken() {
return true; return true;
@ -294,10 +392,12 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.webhookKey; return this.webhookKey;
} }
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) { /**
this.apacheHttpClientBuilder = apacheHttpClientBuilder; * Sets webhook key.
} *
* @param webhookKey the webhook key
* @return the webhook key
*/
public WxCpDefaultConfigImpl setWebhookKey(String webhookKey) { public WxCpDefaultConfigImpl setWebhookKey(String webhookKey) {
this.webhookKey = webhookKey; this.webhookKey = webhookKey;
return this; return this;

View File

@ -17,9 +17,9 @@ import java.util.concurrent.locks.ReentrantLock;
* 使用说明本实现仅供参考并不完整. * 使用说明本实现仅供参考并不完整.
* 比如为减少项目依赖未加入redis分布式锁的实现如有需要请自行实现 * 比如为减少项目依赖未加入redis分布式锁的实现如有需要请自行实现
* </pre> * </pre>
* @deprecated 不建议使用如有需要请自行改造实现加入到自己的项目中并引用
* *
* @author gaigeshen * @author gaigeshen
* @deprecated 不建议使用 如有需要请自行改造实现加入到自己的项目中并引用
*/ */
@Deprecated @Deprecated
public class WxCpRedisConfigImpl implements WxCpConfigStorage { public class WxCpRedisConfigImpl implements WxCpConfigStorage {
@ -31,6 +31,10 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
private static final String AGENT_JSAPI_TICKET_EXPIRES_TIME_KEY = "WX_CP_AGENT_%s_JSAPI_TICKET_EXPIRES_TIME"; private static final String AGENT_JSAPI_TICKET_EXPIRES_TIME_KEY = "WX_CP_AGENT_%s_JSAPI_TICKET_EXPIRES_TIME";
private final JedisPool jedisPool; private final JedisPool jedisPool;
/**
* The Base api url.
*/
protected volatile String baseApiUrl;
private volatile String corpId; private volatile String corpId;
private volatile String corpSecret; private volatile String corpSecret;
private volatile String token; private volatile String token;
@ -43,11 +47,65 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
private volatile String httpProxyPassword; private volatile String httpProxyPassword;
private volatile File tmpDirFile; private volatile File tmpDirFile;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder; private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
protected volatile String baseApiUrl;
private volatile String webhookKey; private volatile String webhookKey;
/**
* Instantiates a new Wx cp redis config.
*
* @param jedisPool the jedis pool
*/
public WxCpRedisConfigImpl(JedisPool jedisPool) {
this.jedisPool = jedisPool;
}
/**
* Instantiates a new Wx cp redis config.
*
* @param host the host
* @param port the port
*/
public WxCpRedisConfigImpl(String host, int port) {
jedisPool = new JedisPool(host, port);
}
/**
* Instantiates a new Wx cp redis config.
*
* @param poolConfig the pool config
* @param host the host
* @param port the port
*/
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port) {
jedisPool = new JedisPool(poolConfig, host, port);
}
/**
* Instantiates a new Wx cp redis config.
*
* @param poolConfig the pool config
* @param host the host
* @param port the port
* @param timeout the timeout
* @param password the password
*/
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port, int timeout, String password) {
jedisPool = new JedisPool(poolConfig, host, port, timeout, password);
}
/**
* Instantiates a new Wx cp redis config.
*
* @param poolConfig the pool config
* @param host the host
* @param port the port
* @param timeout the timeout
* @param password the password
* @param database the database
*/
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port, int timeout, String password, int database) {
jedisPool = new JedisPool(poolConfig, host, port, timeout, password, database);
}
@Override @Override
public void setBaseApiUrl(String baseUrl) { public void setBaseApiUrl(String baseUrl) {
this.baseApiUrl = baseUrl; this.baseApiUrl = baseUrl;
@ -61,26 +119,6 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return baseApiUrl + path; return baseApiUrl + path;
} }
public WxCpRedisConfigImpl(JedisPool jedisPool) {
this.jedisPool = jedisPool;
}
public WxCpRedisConfigImpl(String host, int port) {
jedisPool = new JedisPool(host, port);
}
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port) {
jedisPool = new JedisPool(poolConfig, host, port);
}
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port, int timeout, String password) {
jedisPool = new JedisPool(poolConfig, host, port, timeout, password);
}
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port, int timeout, String password, int database) {
jedisPool = new JedisPool(poolConfig, host, port, timeout, password, database);
}
/** /**
* This method will be destroy jedis pool * This method will be destroy jedis pool
*/ */
@ -226,6 +264,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.corpId; return this.corpId;
} }
/**
* Sets corp id.
*
* @param corpId the corp id
*/
public void setCorpId(String corpId) { public void setCorpId(String corpId) {
this.corpId = corpId; this.corpId = corpId;
} }
@ -235,6 +278,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.corpSecret; return this.corpSecret;
} }
/**
* Sets corp secret.
*
* @param corpSecret the corp secret
*/
public void setCorpSecret(String corpSecret) { public void setCorpSecret(String corpSecret) {
this.corpSecret = corpSecret; this.corpSecret = corpSecret;
} }
@ -244,6 +292,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.agentId; return this.agentId;
} }
/**
* Sets agent id.
*
* @param agentId the agent id
*/
public void setAgentId(Integer agentId) { public void setAgentId(Integer agentId) {
this.agentId = agentId; this.agentId = agentId;
} }
@ -253,6 +306,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.token; return this.token;
} }
/**
* Sets token.
*
* @param token the token
*/
public void setToken(String token) { public void setToken(String token) {
this.token = token; this.token = token;
} }
@ -262,6 +320,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.aesKey; return this.aesKey;
} }
/**
* Sets aes key.
*
* @param aesKey the aes key
*/
public void setAesKey(String aesKey) { public void setAesKey(String aesKey) {
this.aesKey = aesKey; this.aesKey = aesKey;
} }
@ -285,6 +348,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.oauth2redirectUri; return this.oauth2redirectUri;
} }
/**
* Sets oauth 2 redirect uri.
*
* @param oauth2redirectUri the oauth 2 redirect uri
*/
public void setOauth2redirectUri(String oauth2redirectUri) { public void setOauth2redirectUri(String oauth2redirectUri) {
this.oauth2redirectUri = oauth2redirectUri; this.oauth2redirectUri = oauth2redirectUri;
} }
@ -294,6 +362,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.httpProxyHost; return this.httpProxyHost;
} }
/**
* Sets http proxy host.
*
* @param httpProxyHost the http proxy host
*/
public void setHttpProxyHost(String httpProxyHost) { public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost; this.httpProxyHost = httpProxyHost;
} }
@ -303,6 +376,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.httpProxyPort; return this.httpProxyPort;
} }
/**
* Sets http proxy port.
*
* @param httpProxyPort the http proxy port
*/
public void setHttpProxyPort(int httpProxyPort) { public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort; this.httpProxyPort = httpProxyPort;
} }
@ -314,6 +392,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
// ============================ Setters below // ============================ Setters below
/**
* Sets http proxy username.
*
* @param httpProxyUsername the http proxy username
*/
public void setHttpProxyUsername(String httpProxyUsername) { public void setHttpProxyUsername(String httpProxyUsername) {
this.httpProxyUsername = httpProxyUsername; this.httpProxyUsername = httpProxyUsername;
} }
@ -323,6 +406,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.httpProxyPassword; return this.httpProxyPassword;
} }
/**
* Sets http proxy password.
*
* @param httpProxyPassword the http proxy password
*/
public void setHttpProxyPassword(String httpProxyPassword) { public void setHttpProxyPassword(String httpProxyPassword) {
this.httpProxyPassword = httpProxyPassword; this.httpProxyPassword = httpProxyPassword;
} }
@ -332,6 +420,11 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.tmpDirFile; return this.tmpDirFile;
} }
/**
* Sets tmp dir file.
*
* @param tmpDirFile the tmp dir file
*/
public void setTmpDirFile(File tmpDirFile) { public void setTmpDirFile(File tmpDirFile) {
this.tmpDirFile = tmpDirFile; this.tmpDirFile = tmpDirFile;
} }
@ -341,6 +434,15 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.apacheHttpClientBuilder; return this.apacheHttpClientBuilder;
} }
/**
* Sets apache http client builder.
*
* @param apacheHttpClientBuilder the apache http client builder
*/
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
@Override @Override
public boolean autoRefreshToken() { public boolean autoRefreshToken() {
return true; return true;
@ -351,8 +453,4 @@ public class WxCpRedisConfigImpl implements WxCpConfigStorage {
return this.getWebhookKey(); return this.getWebhookKey();
} }
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
} }

View File

@ -17,30 +17,69 @@ import java.util.concurrent.locks.Lock;
* @date 2020 /5/13 * @date 2020 /5/13
*/ */
public class WxCpRedissonConfigImpl extends WxCpDefaultConfigImpl { public class WxCpRedissonConfigImpl extends WxCpDefaultConfigImpl {
/**
* The constant LOCK_KEY.
*/
protected final static String LOCK_KEY = "wechat_cp_lock:"; protected final static String LOCK_KEY = "wechat_cp_lock:";
/**
* The constant CP_ACCESS_TOKEN_KEY.
*/
protected final static String CP_ACCESS_TOKEN_KEY = "wechat_cp_access_token_key:"; protected final static String CP_ACCESS_TOKEN_KEY = "wechat_cp_access_token_key:";
/**
* The constant CP_JSAPI_TICKET_KEY.
*/
protected final static String CP_JSAPI_TICKET_KEY = "wechat_cp_jsapi_ticket_key:"; protected final static String CP_JSAPI_TICKET_KEY = "wechat_cp_jsapi_ticket_key:";
/**
* The constant CP_AGENT_JSAPI_TICKET_KEY.
*/
protected final static String CP_AGENT_JSAPI_TICKET_KEY = "wechat_cp_agent_jsapi_ticket_key:"; protected final static String CP_AGENT_JSAPI_TICKET_KEY = "wechat_cp_agent_jsapi_ticket_key:";
private final WxRedisOps redisOps;
/** /**
* redis 存储的 key 的前缀可为空 * redis 存储的 key 的前缀可为空
*/ */
protected String keyPrefix; protected String keyPrefix;
/**
* The Access token key.
*/
protected String accessTokenKey; protected String accessTokenKey;
/**
* The Jsapi ticket key.
*/
protected String jsapiTicketKey; protected String jsapiTicketKey;
/**
* The Agent jsapi ticket key.
*/
protected String agentJsapiTicketKey; protected String agentJsapiTicketKey;
/**
* The Lock key.
*/
protected String lockKey; protected String lockKey;
private final WxRedisOps redisOps; /**
* Instantiates a new Wx cp redisson config.
*
* @param redissonClient the redisson client
* @param keyPrefix the key prefix
*/
public WxCpRedissonConfigImpl(@NonNull RedissonClient redissonClient, String keyPrefix) { public WxCpRedissonConfigImpl(@NonNull RedissonClient redissonClient, String keyPrefix) {
this(new RedissonWxRedisOps(redissonClient), keyPrefix); this(new RedissonWxRedisOps(redissonClient), keyPrefix);
} }
/**
* Instantiates a new Wx cp redisson config.
*
* @param redissonClient the redisson client
*/
public WxCpRedissonConfigImpl(@NonNull RedissonClient redissonClient) { public WxCpRedissonConfigImpl(@NonNull RedissonClient redissonClient) {
this(redissonClient, null); this(redissonClient, null);
} }
/**
* Instantiates a new Wx cp redisson config.
*
* @param redisOps the redis ops
* @param keyPrefix the key prefix
*/
public WxCpRedissonConfigImpl(@NonNull WxRedisOps redisOps, String keyPrefix) { public WxCpRedissonConfigImpl(@NonNull WxRedisOps redisOps, String keyPrefix) {
this.redisOps = redisOps; this.redisOps = redisOps;
this.keyPrefix = keyPrefix; this.keyPrefix = keyPrefix;
@ -63,6 +102,12 @@ public class WxCpRedissonConfigImpl extends WxCpDefaultConfigImpl {
agentJsapiTicketKey = prefix + CP_AGENT_JSAPI_TICKET_KEY.concat(ukey); agentJsapiTicketKey = prefix + CP_AGENT_JSAPI_TICKET_KEY.concat(ukey);
} }
/**
* Gets lock by key.
*
* @param key the key
* @return the lock by key
*/
protected Lock getLockByKey(String key) { protected Lock getLockByKey(String key) {
return redisOps.getLock(key); return redisOps.getLock(key);
} }

View File

@ -22,7 +22,12 @@ import java.util.concurrent.locks.ReentrantLock;
*/ */
public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializable { public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializable {
private static final long serialVersionUID = 6678780920621872824L; private static final long serialVersionUID = 6678780920621872824L;
// locker
private final transient Map<String, Lock> providerAccessTokenLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> suiteAccessTokenLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> accessTokenLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> authCorpJsapiTicketLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> authSuiteJsapiTicketLocker = new ConcurrentHashMap<>();
private volatile String corpId; private volatile String corpId;
private volatile String corpSecret; private volatile String corpSecret;
/** /**
@ -31,46 +36,29 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
private volatile String providerSecret; private volatile String providerSecret;
private volatile String providerToken; private volatile String providerToken;
private volatile long providerTokenExpiresTime; private volatile long providerTokenExpiresTime;
private volatile String suiteId; private volatile String suiteId;
private volatile String suiteSecret; private volatile String suiteSecret;
private volatile String token; private volatile String token;
private volatile String suiteAccessToken; private volatile String suiteAccessToken;
private volatile long suiteAccessTokenExpiresTime; private volatile long suiteAccessTokenExpiresTime;
private volatile String aesKey; private volatile String aesKey;
private volatile String suiteTicket; private volatile String suiteTicket;
private volatile long suiteTicketExpiresTime; private volatile long suiteTicketExpiresTime;
private volatile String oauth2redirectUri; private volatile String oauth2redirectUri;
private volatile Map<String, String> authCorpAccessTokenMap = new HashMap<>(); private volatile Map<String, String> authCorpAccessTokenMap = new HashMap<>();
private volatile Map<String, Long> authCorpAccessTokenExpireTimeMap = new HashMap<>(); private volatile Map<String, Long> authCorpAccessTokenExpireTimeMap = new HashMap<>();
private volatile Map<String, String> authCorpJsApiTicketMap = new HashMap<>(); private volatile Map<String, String> authCorpJsApiTicketMap = new HashMap<>();
private volatile Map<String, Long> authCorpJsApiTicketExpireTimeMap = new HashMap<>(); private volatile Map<String, Long> authCorpJsApiTicketExpireTimeMap = new HashMap<>();
private volatile Map<String, String> authSuiteJsApiTicketMap = new HashMap<>(); private volatile Map<String, String> authSuiteJsApiTicketMap = new HashMap<>();
private volatile Map<String, Long> authSuiteJsApiTicketExpireTimeMap = new HashMap<>(); private volatile Map<String, Long> authSuiteJsApiTicketExpireTimeMap = new HashMap<>();
private volatile String httpProxyHost; private volatile String httpProxyHost;
private volatile int httpProxyPort; private volatile int httpProxyPort;
private volatile String httpProxyUsername; private volatile String httpProxyUsername;
private volatile String httpProxyPassword; private volatile String httpProxyPassword;
private volatile File tmpDirFile; private volatile File tmpDirFile;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder; private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
private volatile String baseApiUrl; private volatile String baseApiUrl;
// locker
private final transient Map<String, Lock> providerAccessTokenLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> suiteAccessTokenLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> accessTokenLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> authCorpJsapiTicketLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> authSuiteJsapiTicketLocker = new ConcurrentHashMap<>();
@Override @Override
public void setBaseApiUrl(String baseUrl) { public void setBaseApiUrl(String baseUrl) {
this.baseApiUrl = baseUrl; this.baseApiUrl = baseUrl;
@ -89,6 +77,15 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.suiteAccessToken; return this.suiteAccessToken;
} }
/**
* Sets suite access token.
*
* @param suiteAccessToken the suite access token
*/
public void setSuiteAccessToken(String suiteAccessToken) {
this.suiteAccessToken = suiteAccessToken;
}
@Override @Override
public WxAccessToken getSuiteAccessTokenEntity() { public WxAccessToken getSuiteAccessTokenEntity() {
WxAccessToken accessToken = new WxAccessToken(); WxAccessToken accessToken = new WxAccessToken();
@ -98,10 +95,6 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return accessToken; return accessToken;
} }
public void setSuiteAccessToken(String suiteAccessToken) {
this.suiteAccessToken = suiteAccessToken;
}
@Override @Override
public boolean isSuiteAccessTokenExpired() { public boolean isSuiteAccessTokenExpired() {
return System.currentTimeMillis() > this.suiteAccessTokenExpiresTime; return System.currentTimeMillis() > this.suiteAccessTokenExpiresTime;
@ -123,6 +116,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
this.suiteAccessTokenExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L; this.suiteAccessTokenExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
} }
/**
* Sets suite access token expires time.
*
* @param suiteAccessTokenExpiresTime the suite access token expires time
*/
@Deprecated @Deprecated
public void setSuiteAccessTokenExpiresTime(long suiteAccessTokenExpiresTime) { public void setSuiteAccessTokenExpiresTime(long suiteAccessTokenExpiresTime) {
this.suiteAccessTokenExpiresTime = suiteAccessTokenExpiresTime; this.suiteAccessTokenExpiresTime = suiteAccessTokenExpiresTime;
@ -133,6 +131,16 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.suiteTicket; return this.suiteTicket;
} }
/**
* Sets suite ticket.
*
* @param suiteTicket the suite ticket
*/
@Deprecated
public void setSuiteTicket(String suiteTicket) {
this.suiteTicket = suiteTicket;
}
@Override @Override
public boolean isSuiteTicketExpired() { public boolean isSuiteTicketExpired() {
return System.currentTimeMillis() > this.suiteTicketExpiresTime; return System.currentTimeMillis() > this.suiteTicketExpiresTime;
@ -150,17 +158,21 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
this.suiteTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L; this.suiteTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
} }
/**
@Deprecated * Gets suite ticket expires time.
public void setSuiteTicket(String suiteTicket) { *
this.suiteTicket = suiteTicket; * @return the suite ticket expires time
} */
@Deprecated @Deprecated
public long getSuiteTicketExpiresTime() { public long getSuiteTicketExpiresTime() {
return this.suiteTicketExpiresTime; return this.suiteTicketExpiresTime;
} }
/**
* Sets suite ticket expires time.
*
* @param suiteTicketExpiresTime the suite ticket expires time
*/
@Deprecated @Deprecated
public void setSuiteTicketExpiresTime(long suiteTicketExpiresTime) { public void setSuiteTicketExpiresTime(long suiteTicketExpiresTime) {
this.suiteTicketExpiresTime = suiteTicketExpiresTime; this.suiteTicketExpiresTime = suiteTicketExpiresTime;
@ -171,6 +183,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.suiteId; return this.suiteId;
} }
/**
* Sets suite id.
*
* @param corpId the corp id
*/
@Deprecated @Deprecated
public void setSuiteId(String corpId) { public void setSuiteId(String corpId) {
this.suiteId = corpId; this.suiteId = corpId;
@ -181,6 +198,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.suiteSecret; return this.suiteSecret;
} }
/**
* Sets suite secret.
*
* @param corpSecret the corp secret
*/
@Deprecated @Deprecated
public void setSuiteSecret(String corpSecret) { public void setSuiteSecret(String corpSecret) {
this.suiteSecret = corpSecret; this.suiteSecret = corpSecret;
@ -191,6 +213,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.token; return this.token;
} }
/**
* Sets token.
*
* @param token the token
*/
@Deprecated @Deprecated
public void setToken(String token) { public void setToken(String token) {
this.token = token; this.token = token;
@ -201,6 +228,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.aesKey; return this.aesKey;
} }
/**
* Sets aes key.
*
* @param aesKey the aes key
*/
@Deprecated @Deprecated
public void setAesKey(String aesKey) { public void setAesKey(String aesKey) {
this.aesKey = aesKey; this.aesKey = aesKey;
@ -212,6 +244,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.corpId; return this.corpId;
} }
/**
* Sets corp id.
*
* @param corpId the corp id
*/
@Deprecated @Deprecated
public void setCorpId(String corpId) { public void setCorpId(String corpId) {
this.corpId = corpId; this.corpId = corpId;
@ -222,16 +259,20 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.corpSecret; return this.corpSecret;
} }
@Override /**
public String getProviderSecret() { * Sets corp secret.
return providerSecret; *
} * @param corpSecret the corp secret
*/
@Deprecated @Deprecated
public void setCorpSecret(String corpSecret) { public void setCorpSecret(String corpSecret) {
this.corpSecret = corpSecret; this.corpSecret = corpSecret;
} }
@Override
public String getProviderSecret() {
return providerSecret;
}
@Override @Override
public String getAccessToken(String authCorpId) { public String getAccessToken(String authCorpId) {
@ -353,6 +394,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
this.providerTokenExpiresTime = 0L; this.providerTokenExpiresTime = 0L;
} }
/**
* Sets oauth 2 redirect uri.
*
* @param oauth2redirectUri the oauth 2 redirect uri
*/
public void setOauth2redirectUri(String oauth2redirectUri) { public void setOauth2redirectUri(String oauth2redirectUri) {
this.oauth2redirectUri = oauth2redirectUri; this.oauth2redirectUri = oauth2redirectUri;
} }
@ -362,6 +408,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.httpProxyHost; return this.httpProxyHost;
} }
/**
* Sets http proxy host.
*
* @param httpProxyHost the http proxy host
*/
public void setHttpProxyHost(String httpProxyHost) { public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost; this.httpProxyHost = httpProxyHost;
} }
@ -371,6 +422,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.httpProxyPort; return this.httpProxyPort;
} }
/**
* Sets http proxy port.
*
* @param httpProxyPort the http proxy port
*/
public void setHttpProxyPort(int httpProxyPort) { public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort; this.httpProxyPort = httpProxyPort;
} }
@ -380,6 +436,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.httpProxyUsername; return this.httpProxyUsername;
} }
/**
* Sets http proxy username.
*
* @param httpProxyUsername the http proxy username
*/
public void setHttpProxyUsername(String httpProxyUsername) { public void setHttpProxyUsername(String httpProxyUsername) {
this.httpProxyUsername = httpProxyUsername; this.httpProxyUsername = httpProxyUsername;
} }
@ -389,6 +450,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.httpProxyPassword; return this.httpProxyPassword;
} }
/**
* Sets http proxy password.
*
* @param httpProxyPassword the http proxy password
*/
public void setHttpProxyPassword(String httpProxyPassword) { public void setHttpProxyPassword(String httpProxyPassword) {
this.httpProxyPassword = httpProxyPassword; this.httpProxyPassword = httpProxyPassword;
} }
@ -403,6 +469,15 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.tmpDirFile; return this.tmpDirFile;
} }
/**
* Sets tmp dir file.
*
* @param tmpDirFile the tmp dir file
*/
public void setTmpDirFile(File tmpDirFile) {
this.tmpDirFile = tmpDirFile;
}
@Override @Override
public Lock getProviderAccessTokenLock() { public Lock getProviderAccessTokenLock() {
return this.providerAccessTokenLocker return this.providerAccessTokenLocker
@ -432,21 +507,22 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
.computeIfAbsent(String.join(":", this.suiteId, authCorpId), key -> new ReentrantLock()); .computeIfAbsent(String.join(":", this.suiteId, authCorpId), key -> new ReentrantLock());
} }
public void setTmpDirFile(File tmpDirFile) {
this.tmpDirFile = tmpDirFile;
}
@Override @Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() { public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder; return this.apacheHttpClientBuilder;
} }
/**
* Sets apache http client builder.
*
* @param apacheHttpClientBuilder the apache http client builder
*/
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
@Override @Override
public boolean autoRefreshToken() { public boolean autoRefreshToken() {
return true; return true;
} }
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
} }

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.cp.config.impl;
import lombok.Builder; import lombok.Builder;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter;
import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.redis.WxRedisOps; import me.chanjar.weixin.common.redis.WxRedisOps;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
@ -21,26 +22,46 @@ import java.util.concurrent.locks.Lock;
*/ */
@Builder @Builder
public class WxCpTpRedissonConfigImpl implements WxCpTpConfigStorage, Serializable { public class WxCpTpRedissonConfigImpl implements WxCpTpConfigStorage, Serializable {
private static final long serialVersionUID = -5385639031981770319L;
/**
* The constant LOCK_KEY.
*/
// lock key
protected static final String LOCK_KEY = "wechat_tp_lock:";
/**
* The constant LOCKER_PROVIDER_ACCESS_TOKEN.
*/
protected static final String LOCKER_PROVIDER_ACCESS_TOKEN = "providerAccessTokenLock";
/**
* The constant LOCKER_SUITE_ACCESS_TOKEN.
*/
protected static final String LOCKER_SUITE_ACCESS_TOKEN = "suiteAccessTokenLock";
/**
* The constant LOCKER_ACCESS_TOKEN.
*/
protected static final String LOCKER_ACCESS_TOKEN = "accessTokenLock";
/**
* The constant LOCKER_CORP_JSAPI_TICKET.
*/
protected static final String LOCKER_CORP_JSAPI_TICKET = "corpJsapiTicketLock";
/**
* The constant LOCKER_SUITE_JSAPI_TICKET.
*/
protected static final String LOCKER_SUITE_JSAPI_TICKET = "suiteJsapiTicketLock";
@NonNull @NonNull
private final WxRedisOps wxRedisOps; private final WxRedisOps wxRedisOps;
//redis里面key的统一前缀
//private final String keyPrefix = "";//4.0.9.B 有final为不可设置,去掉final改为可设置
private String keyPrefix = "";
private final String suiteAccessTokenKey = ":suiteAccessTokenKey:"; private final String suiteAccessTokenKey = ":suiteAccessTokenKey:";
private final String suiteTicketKey = ":suiteTicketKey:"; private final String suiteTicketKey = ":suiteTicketKey:";
private final String accessTokenKey = ":accessTokenKey:"; private final String accessTokenKey = ":accessTokenKey:";
private final String authCorpJsApiTicketKey = ":authCorpJsApiTicketKey:"; private final String authCorpJsApiTicketKey = ":authCorpJsApiTicketKey:";
private final String authSuiteJsApiTicketKey = ":authSuiteJsApiTicketKey:"; private final String authSuiteJsApiTicketKey = ":authSuiteJsApiTicketKey:";
private final String providerTokenKey = ":providerTokenKey:"; private final String providerTokenKey = ":providerTokenKey:";
/**
* redis里面key的统一前缀
*/
@Setter
private String keyPrefix = "";
private volatile String baseApiUrl; private volatile String baseApiUrl;
private volatile String httpProxyHost; private volatile String httpProxyHost;
private volatile int httpProxyPort; private volatile int httpProxyPort;
@ -48,36 +69,29 @@ public class WxCpTpRedissonConfigImpl implements WxCpTpConfigStorage, Serializab
private volatile String httpProxyPassword; private volatile String httpProxyPassword;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder; private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
private volatile File tmpDirFile; private volatile File tmpDirFile;
/** /**
* 第三方应用的其他配置来自于企微配置 * 第三方应用的其他配置来自于企微配置
*/ */
private volatile String suiteId; private volatile String suiteId;
private volatile String suiteSecret; private volatile String suiteSecret;
// 第三方应用的token用来检查应用的签名 /**
* 第三方应用的token用来检查应用的签名
*/
private volatile String token; private volatile String token;
//第三方应用的EncodingAESKey用来检查签名 /**
* 第三方应用的EncodingAESKey用来检查签名
*/
private volatile String aesKey; private volatile String aesKey;
/** /**
* 企微服务商企业ID & 企业secret来自于企微配置 * 企微服务商企业ID & 企业secret来自于企微配置
*/ */
private volatile String corpId; private volatile String corpId;
private volatile String corpSecret; private volatile String corpSecret;
/** /**
* 服务商secret * 服务商secret
*/ */
private volatile String providerSecret; private volatile String providerSecret;
// lock key
protected static final String LOCK_KEY = "wechat_tp_lock:";
protected static final String LOCKER_PROVIDER_ACCESS_TOKEN = "providerAccessTokenLock";
protected static final String LOCKER_SUITE_ACCESS_TOKEN = "suiteAccessTokenLock";
protected static final String LOCKER_ACCESS_TOKEN = "accessTokenLock";
protected static final String LOCKER_CORP_JSAPI_TICKET = "corpJsapiTicketLock";
protected static final String LOCKER_SUITE_JSAPI_TICKET = "suiteJsapiTicketLock";
@Override @Override
public void setBaseApiUrl(String baseUrl) { public void setBaseApiUrl(String baseUrl) {
this.baseApiUrl = baseUrl; this.baseApiUrl = baseUrl;
@ -393,8 +407,6 @@ public class WxCpTpRedissonConfigImpl implements WxCpTpConfigStorage, Serializab
/** /**
* 单独处理provider,且不应和suite 有关系 * 单独处理provider,且不应和suite 有关系
* @param key
* @return
*/ */
private Lock getProviderLockByKey(String key) { private Lock getProviderLockByKey(String key) {
return this.wxRedisOps.getLock(String.join(":", providerKeyWithPrefix(LOCK_KEY), key)); return this.wxRedisOps.getLock(String.join(":", providerKeyWithPrefix(LOCK_KEY), key));
@ -412,14 +424,12 @@ public class WxCpTpRedissonConfigImpl implements WxCpTpConfigStorage, Serializab
@Override @Override
public String toString() { public String toString() {
//TODO:
return WxCpGsonBuilder.create().toJson(this); return WxCpGsonBuilder.create().toJson(this);
} }
/** /**
* 一个provider 会有多个suite,需要唯一标识作为前缀 * 一个provider 会有多个suite,需要唯一标识作为前缀
* @param key *
* @return
*/ */
private String keyWithPrefix(String key) { private String keyWithPrefix(String key) {
return keyPrefix + ":" + suiteId + ":" + key; return keyPrefix + ":" + suiteId + ":" + key;
@ -428,8 +438,7 @@ public class WxCpTpRedissonConfigImpl implements WxCpTpConfigStorage, Serializab
/** /**
* provider 应该独享一个key,且不和任何suite关联 * provider 应该独享一个key,且不和任何suite关联
* 一个provider 会有多个suite,不同的suite 都应该指向同一个provider 的数据 * 一个provider 会有多个suite,不同的suite 都应该指向同一个provider 的数据
* @param key *
* @return
*/ */
private String providerKeyWithPrefix(String key) { private String providerKeyWithPrefix(String key) {
return keyPrefix + ":" + corpId + ":" + key; return keyPrefix + ":" + corpId + ":" + key;