Skip to content

Commit

Permalink
🎨 #1700 公众号WxMpConfigStorage接口提供setHostConfig()方法,方便设置相关信息
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Aug 8, 2020
1 parent edf8e18 commit c588303
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,10 +14,25 @@
* @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();

/**
Expand All @@ -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);

Expand All @@ -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);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package me.chanjar.weixin.mp.config.impl;

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.enums.TicketType;
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.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;

/**
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化.
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -183,7 +185,12 @@ public boolean autoRefreshToken() {

@Override
public WxMpHostConfig getHostConfig() {
return null;
return this.hostConfig;
}

@Override
public void setHostConfig(WxMpHostConfig hostConfig) {
this.hostConfig = hostConfig;
}

}

0 comments on commit c588303

Please sign in to comment.