规范统一config部分代码
This commit is contained in:
@@ -14,7 +14,6 @@ public interface WxCpTpConfigStorage {
|
||||
|
||||
/**
|
||||
* 设置企业微信服务器 baseUrl.
|
||||
*
|
||||
* 默认值是 https://qyapi.weixin.qq.com , 如果使用默认值,则不需要调用 setBaseApiUrl
|
||||
*
|
||||
* @param baseUrl 企业微信服务器 Url
|
||||
@@ -23,7 +22,6 @@ public interface WxCpTpConfigStorage {
|
||||
|
||||
/**
|
||||
* 读取企业微信 API Url.
|
||||
*
|
||||
* 支持私有化企业微信服务器.
|
||||
*/
|
||||
String getApiUrl(String path);
|
||||
@@ -33,7 +31,7 @@ public interface WxCpTpConfigStorage {
|
||||
boolean isSuiteAccessTokenExpired();
|
||||
|
||||
/**
|
||||
* 强制将suite access token过期掉
|
||||
* 强制将suite access token过期掉.
|
||||
*/
|
||||
void expireSuiteAccessToken();
|
||||
|
||||
@@ -46,15 +44,15 @@ public interface WxCpTpConfigStorage {
|
||||
boolean isSuiteTicketExpired();
|
||||
|
||||
/**
|
||||
* 强制将suite ticket过期掉
|
||||
* 强制将suite ticket过期掉.
|
||||
*/
|
||||
void expireSuiteTicket();
|
||||
|
||||
/**
|
||||
* 应该是线程安全的
|
||||
* 应该是线程安全的.
|
||||
*/
|
||||
void updateSuiteTicket(String suiteTicket, int expiresInSeconds);
|
||||
|
||||
|
||||
String getCorpId();
|
||||
|
||||
String getCorpSecret();
|
||||
@@ -80,7 +78,7 @@ public interface WxCpTpConfigStorage {
|
||||
File getTmpDirFile();
|
||||
|
||||
/**
|
||||
* http client builder
|
||||
* http client builder.
|
||||
*
|
||||
* @return ApacheHttpClientBuilder
|
||||
*/
|
||||
|
||||
@@ -1,45 +1,49 @@
|
||||
package me.chanjar.weixin.cp.config;
|
||||
package me.chanjar.weixin.cp.config.impl;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
|
||||
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化.
|
||||
*
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
|
||||
protected volatile String corpId;
|
||||
protected volatile String corpSecret;
|
||||
public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
|
||||
private static final long serialVersionUID = 1154541446729462780L;
|
||||
|
||||
protected volatile String token;
|
||||
private volatile String corpId;
|
||||
private volatile String corpSecret;
|
||||
|
||||
private volatile String token;
|
||||
protected volatile String accessToken;
|
||||
protected volatile String aesKey;
|
||||
private volatile String aesKey;
|
||||
protected volatile Integer agentId;
|
||||
protected volatile long expiresTime;
|
||||
private volatile long expiresTime;
|
||||
|
||||
protected volatile String oauth2redirectUri;
|
||||
private volatile String oauth2redirectUri;
|
||||
|
||||
protected volatile String httpProxyHost;
|
||||
protected volatile int httpProxyPort;
|
||||
protected volatile String httpProxyUsername;
|
||||
protected volatile String httpProxyPassword;
|
||||
private volatile String httpProxyHost;
|
||||
private volatile int httpProxyPort;
|
||||
private volatile String httpProxyUsername;
|
||||
private volatile String httpProxyPassword;
|
||||
|
||||
protected volatile String jsapiTicket;
|
||||
protected volatile long jsapiTicketExpiresTime;
|
||||
private volatile String jsapiTicket;
|
||||
private volatile long jsapiTicketExpiresTime;
|
||||
|
||||
protected volatile String agentJsapiTicket;
|
||||
protected volatile long agentJsapiTicketExpiresTime;
|
||||
private volatile String agentJsapiTicket;
|
||||
private volatile long agentJsapiTicketExpiresTime;
|
||||
|
||||
protected volatile File tmpDirFile;
|
||||
private volatile File tmpDirFile;
|
||||
|
||||
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
|
||||
|
||||
protected volatile String baseApiUrl;
|
||||
private volatile String baseApiUrl;
|
||||
|
||||
@Override
|
||||
public void setBaseApiUrl(String baseUrl) {
|
||||
@@ -1,7 +1,8 @@
|
||||
package me.chanjar.weixin.cp.config;
|
||||
package me.chanjar.weixin.cp.config.impl;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
@@ -17,7 +18,7 @@ import java.io.File;
|
||||
*
|
||||
* @author gaigeshen
|
||||
*/
|
||||
public class WxCpJedisConfigStorage implements WxCpConfigStorage {
|
||||
public class WxCpRedisConfigImpl implements WxCpConfigStorage {
|
||||
private static final String ACCESS_TOKEN_KEY = "WX_CP_ACCESS_TOKEN";
|
||||
private static final String ACCESS_TOKEN_EXPIRES_TIME_KEY = "WX_CP_ACCESS_TOKEN_EXPIRES_TIME";
|
||||
private static final String JS_API_TICKET_KEY = "WX_CP_JS_API_TICKET";
|
||||
@@ -54,23 +55,23 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage {
|
||||
return baseApiUrl + path;
|
||||
}
|
||||
|
||||
public WxCpJedisConfigStorage(JedisPool jedisPool) {
|
||||
public WxCpRedisConfigImpl(JedisPool jedisPool) {
|
||||
this.jedisPool = jedisPool;
|
||||
}
|
||||
|
||||
public WxCpJedisConfigStorage(String host, int port) {
|
||||
public WxCpRedisConfigImpl(String host, int port) {
|
||||
jedisPool = new JedisPool(host, port);
|
||||
}
|
||||
|
||||
public WxCpJedisConfigStorage(JedisPoolConfig poolConfig, String host, int port) {
|
||||
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port) {
|
||||
jedisPool = new JedisPool(poolConfig, host, port);
|
||||
}
|
||||
|
||||
public WxCpJedisConfigStorage(JedisPoolConfig poolConfig, String host, int port, int timeout, String password) {
|
||||
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port, int timeout, String password) {
|
||||
jedisPool = new JedisPool(poolConfig, host, port, timeout, password);
|
||||
}
|
||||
|
||||
public WxCpJedisConfigStorage(JedisPoolConfig poolConfig, String host, int port, int timeout, String password, int database) {
|
||||
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port, int timeout, String password, int database) {
|
||||
jedisPool = new JedisPool(poolConfig, host, port, timeout, password, database);
|
||||
}
|
||||
|
||||
@@ -1,44 +1,47 @@
|
||||
package me.chanjar.weixin.cp.config;
|
||||
package me.chanjar.weixin.cp.config.impl;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
|
||||
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化.
|
||||
*
|
||||
* @author Daniel Qian
|
||||
* @author someone
|
||||
*/
|
||||
public class WxCpTpInMemoryConfigStorage implements WxCpTpConfigStorage {
|
||||
protected volatile String corpId;
|
||||
protected volatile String corpSecret;
|
||||
|
||||
protected volatile String suiteId;
|
||||
protected volatile String suiteSecret;
|
||||
public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializable {
|
||||
private static final long serialVersionUID = 6678780920621872824L;
|
||||
|
||||
protected volatile String token;
|
||||
protected volatile String suiteAccessToken;
|
||||
protected volatile String aesKey;
|
||||
protected volatile long expiresTime;
|
||||
private volatile String corpId;
|
||||
private volatile String corpSecret;
|
||||
|
||||
protected volatile String oauth2redirectUri;
|
||||
private volatile String suiteId;
|
||||
private volatile String suiteSecret;
|
||||
|
||||
protected volatile String httpProxyHost;
|
||||
protected volatile int httpProxyPort;
|
||||
protected volatile String httpProxyUsername;
|
||||
protected volatile String httpProxyPassword;
|
||||
private volatile String token;
|
||||
private volatile String suiteAccessToken;
|
||||
private volatile String aesKey;
|
||||
private volatile long expiresTime;
|
||||
|
||||
protected volatile String suiteTicket;
|
||||
protected volatile long suiteTicketExpiresTime;
|
||||
private volatile String oauth2redirectUri;
|
||||
|
||||
private volatile String httpProxyHost;
|
||||
private volatile int httpProxyPort;
|
||||
private volatile String httpProxyUsername;
|
||||
private volatile String httpProxyPassword;
|
||||
|
||||
protected volatile File tmpDirFile;
|
||||
private volatile String suiteTicket;
|
||||
private volatile long suiteTicketExpiresTime;
|
||||
|
||||
private volatile File tmpDirFile;
|
||||
|
||||
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
|
||||
|
||||
protected volatile String baseApiUrl;
|
||||
private volatile String baseApiUrl;
|
||||
|
||||
@Override
|
||||
public void setBaseApiUrl(String baseUrl) {
|
||||
@@ -57,7 +60,7 @@ public class WxCpTpInMemoryConfigStorage implements WxCpTpConfigStorage {
|
||||
public String getSuiteAccessToken() {
|
||||
return this.suiteAccessToken;
|
||||
}
|
||||
|
||||
|
||||
public void setSuiteAccessToken(String suiteAccessToken) {
|
||||
this.suiteAccessToken = suiteAccessToken;
|
||||
}
|
||||
@@ -82,25 +85,25 @@ public class WxCpTpInMemoryConfigStorage implements WxCpTpConfigStorage {
|
||||
this.suiteAccessToken = suiteAccessToken;
|
||||
this.expiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getCorpId() {
|
||||
return this.corpId;
|
||||
}
|
||||
|
||||
|
||||
public void setCorpId(String corpId) {
|
||||
this.corpId = corpId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getCorpSecret() {
|
||||
return this.corpSecret;
|
||||
}
|
||||
|
||||
|
||||
public void setCorpSecret(String corpSecret) {
|
||||
this.corpSecret = corpSecret;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSuiteTicket() {
|
||||
return this.suiteTicket;
|
||||
@@ -12,7 +12,7 @@ import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.config.WxCpInMemoryConfigStorage;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
||||
|
||||
public class ApiTestModule implements Module {
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
@@ -44,7 +44,7 @@ public class ApiTestModule implements Module {
|
||||
}
|
||||
|
||||
@XStreamAlias("xml")
|
||||
public static class WxXmlCpInMemoryConfigStorage extends WxCpInMemoryConfigStorage {
|
||||
public static class WxXmlCpInMemoryConfigStorage extends WxCpDefaultConfigImpl {
|
||||
|
||||
protected String userId;
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@ import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.ToString;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
import me.chanjar.weixin.cp.config.WxCpInMemoryConfigStorage;
|
||||
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
||||
|
||||
/**
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
@ToString
|
||||
public class WxCpDemoInMemoryConfigStorage extends WxCpInMemoryConfigStorage {
|
||||
public class WxCpDemoInMemoryConfigStorage extends WxCpDefaultConfigImpl {
|
||||
public static WxCpDemoInMemoryConfigStorage fromXml(InputStream is) {
|
||||
XStream xstream = XStreamInitializer.getInstance();
|
||||
xstream.processAnnotations(WxCpDemoInMemoryConfigStorage.class);
|
||||
|
||||
Reference in New Issue
Block a user