新增MemoryTokenStorager
This commit is contained in:
parent
9a2a91b78d
commit
8c4d5a2798
@ -28,7 +28,8 @@ public abstract class HttpClientFactory {
|
||||
private static volatile HttpClientFactory defaultFactory = newDefaultFactory();
|
||||
|
||||
/**
|
||||
* NettyHttpClient -> ApacheHttpClient -> SimpleHttpClient(HttpURLConnection)
|
||||
* NettyHttpClient -> ApacheHttpClient ->
|
||||
* SimpleHttpClient(HttpURLConnection)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
package com.foxinmy.weixin4j.token;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
|
||||
/**
|
||||
* 用内存保存TOKEN(不推荐使用)
|
||||
*
|
||||
* @className MemoryTokenStorager
|
||||
* @author jy
|
||||
* @date 2016年1月24日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class MemoryTokenStorager implements TokenStorager {
|
||||
|
||||
private final Map<String, Token> CONMAP;
|
||||
|
||||
public MemoryTokenStorager() {
|
||||
this.CONMAP = new ConcurrentHashMap<String, Token>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token lookup(String cacheKey) throws WeixinException {
|
||||
Token token = this.CONMAP.get(cacheKey);
|
||||
if (token != null) {
|
||||
if ((token.getCreateTime() + (token.getExpiresIn() * 1000l) - 2) > System
|
||||
.currentTimeMillis()) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caching(String cacheKey, Token token) throws WeixinException {
|
||||
this.CONMAP.put(cacheKey, token);
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
|
||||
/**
|
||||
* 用REDIS保存TOKEN
|
||||
* 用REDIS保存TOKEN(推荐使用)
|
||||
*
|
||||
* @className RedisTokenStorager
|
||||
* @author jy
|
||||
|
||||
@ -10,8 +10,9 @@ import com.foxinmy.weixin4j.model.Token;
|
||||
* @date 2014年9月27日
|
||||
* @since JDK 1.6
|
||||
* @see com.foxinmy.weixin4j.model.Token
|
||||
* @see com.foxinmy.weixin4j.token.FileTokenStorager
|
||||
* @see com.foxinmy.weixin4j.token.RedisTokenStorager
|
||||
* @see MemoryTokenStorager
|
||||
* @see FileTokenStorager
|
||||
* @see RedisTokenStorager
|
||||
*/
|
||||
public interface TokenStorager extends CacheStorager<Token> {
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user