mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-05 13:17:46 +08:00
🎨 #1700 公众号WxMpConfigStorage接口提供setHostConfig()方法,方便设置相关信息
This commit is contained in:
parent
edf8e18c5b
commit
c588303d8a
@ -1,9 +1,9 @@
|
||||
package me.chanjar.weixin.mp.config;
|
||||
|
||||
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.common.enums.TicketType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@ -14,10 +14,25 @@ import java.util.concurrent.locks.Lock;
|
||||
* @author chanjarster
|
||||
*/
|
||||
public interface WxMpConfigStorage {
|
||||
/**
|
||||
* Gets access token.
|
||||
*
|
||||
* @return the access token
|
||||
*/
|
||||
String getAccessToken();
|
||||
|
||||
/**
|
||||
* Gets access token lock.
|
||||
*
|
||||
* @return the access token lock
|
||||
*/
|
||||
Lock getAccessTokenLock();
|
||||
|
||||
/**
|
||||
* Is access token expired boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean isAccessTokenExpired();
|
||||
|
||||
/**
|
||||
@ -40,14 +55,34 @@ public interface WxMpConfigStorage {
|
||||
*/
|
||||
void updateAccessToken(String accessToken, int expiresInSeconds);
|
||||
|
||||
/**
|
||||
* Gets ticket.
|
||||
*
|
||||
* @param type the type
|
||||
* @return the ticket
|
||||
*/
|
||||
String getTicket(TicketType type);
|
||||
|
||||
/**
|
||||
* Gets ticket lock.
|
||||
*
|
||||
* @param type the type
|
||||
* @return the ticket lock
|
||||
*/
|
||||
Lock getTicketLock(TicketType type);
|
||||
|
||||
/**
|
||||
* Is ticket expired boolean.
|
||||
*
|
||||
* @param type the type
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean isTicketExpired(TicketType type);
|
||||
|
||||
/**
|
||||
* 强制将ticket过期掉.
|
||||
*
|
||||
* @param type the type
|
||||
*/
|
||||
void expireTicket(TicketType type);
|
||||
|
||||
@ -61,44 +96,115 @@ public interface WxMpConfigStorage {
|
||||
*/
|
||||
void updateTicket(TicketType type, String ticket, int expiresInSeconds);
|
||||
|
||||
/**
|
||||
* Gets app id.
|
||||
*
|
||||
* @return the app id
|
||||
*/
|
||||
String getAppId();
|
||||
|
||||
/**
|
||||
* Gets secret.
|
||||
*
|
||||
* @return the secret
|
||||
*/
|
||||
String getSecret();
|
||||
|
||||
/**
|
||||
* Gets token.
|
||||
*
|
||||
* @return the token
|
||||
*/
|
||||
String getToken();
|
||||
|
||||
/**
|
||||
* Gets aes key.
|
||||
*
|
||||
* @return the aes key
|
||||
*/
|
||||
String getAesKey();
|
||||
|
||||
/**
|
||||
* Gets template id.
|
||||
*
|
||||
* @return the template id
|
||||
*/
|
||||
String getTemplateId();
|
||||
|
||||
/**
|
||||
* Gets expires time.
|
||||
*
|
||||
* @return the expires time
|
||||
*/
|
||||
long getExpiresTime();
|
||||
|
||||
/**
|
||||
* Gets oauth 2 redirect uri.
|
||||
*
|
||||
* @return the oauth 2 redirect uri
|
||||
*/
|
||||
String getOauth2redirectUri();
|
||||
|
||||
/**
|
||||
* Gets http proxy host.
|
||||
*
|
||||
* @return the http proxy host
|
||||
*/
|
||||
String getHttpProxyHost();
|
||||
|
||||
/**
|
||||
* Gets http proxy port.
|
||||
*
|
||||
* @return the http proxy port
|
||||
*/
|
||||
int getHttpProxyPort();
|
||||
|
||||
/**
|
||||
* Gets http proxy username.
|
||||
*
|
||||
* @return the http proxy username
|
||||
*/
|
||||
String getHttpProxyUsername();
|
||||
|
||||
/**
|
||||
* Gets http proxy password.
|
||||
*
|
||||
* @return the http proxy password
|
||||
*/
|
||||
String getHttpProxyPassword();
|
||||
|
||||
/**
|
||||
* Gets tmp dir file.
|
||||
*
|
||||
* @return the tmp dir file
|
||||
*/
|
||||
File getTmpDirFile();
|
||||
|
||||
/**
|
||||
* http client builder.
|
||||
*
|
||||
* @return ApacheHttpClientBuilder
|
||||
* @return ApacheHttpClientBuilder apache http client builder
|
||||
*/
|
||||
ApacheHttpClientBuilder getApacheHttpClientBuilder();
|
||||
|
||||
/**
|
||||
* 是否自动刷新token.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean autoRefreshToken();
|
||||
|
||||
/**
|
||||
* 得到微信接口地址域名部分的自定义设置信息.
|
||||
*
|
||||
* @return the host config
|
||||
*/
|
||||
WxMpHostConfig getHostConfig();
|
||||
|
||||
/**
|
||||
* 设置微信接口地址域名部分的自定义设置信息.
|
||||
*
|
||||
* @param hostConfig host config
|
||||
*/
|
||||
void setHostConfig(WxMpHostConfig hostConfig);
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
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.Serializable;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
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,在实际生产环境中应该将这些配置持久化.
|
||||
*
|
||||
@ -46,15 +46,17 @@ public class WxMpDefaultConfigImpl implements WxMpConfigStorage, Serializable {
|
||||
protected volatile String cardApiTicket;
|
||||
protected volatile long cardApiTicketExpiresTime;
|
||||
|
||||
protected Lock accessTokenLock = new ReentrantLock();
|
||||
protected Lock jsapiTicketLock = new ReentrantLock();
|
||||
protected Lock sdkTicketLock = new ReentrantLock();
|
||||
protected Lock cardApiTicketLock = new ReentrantLock();
|
||||
protected volatile Lock accessTokenLock = new ReentrantLock();
|
||||
protected volatile Lock jsapiTicketLock = new ReentrantLock();
|
||||
protected volatile Lock sdkTicketLock = new ReentrantLock();
|
||||
protected volatile Lock cardApiTicketLock = new ReentrantLock();
|
||||
|
||||
protected volatile File tmpDirFile;
|
||||
|
||||
protected volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
|
||||
|
||||
private WxMpHostConfig hostConfig = null;
|
||||
|
||||
@Override
|
||||
public boolean isAccessTokenExpired() {
|
||||
return System.currentTimeMillis() > this.expiresTime;
|
||||
@ -183,7 +185,12 @@ public class WxMpDefaultConfigImpl implements WxMpConfigStorage, Serializable {
|
||||
|
||||
@Override
|
||||
public WxMpHostConfig getHostConfig() {
|
||||
return null;
|
||||
return this.hostConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHostConfig(WxMpHostConfig hostConfig) {
|
||||
this.hostConfig = hostConfig;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user