cc.jinglupeng.wechat.DefaultWechatCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wechat Show documentation
Show all versions of wechat Show documentation
this is a java lib for wechat develop.
package cc.jinglupeng.wechat;
import java.util.HashMap;
import java.util.Map;
import cc.jinglupeng.wechat.bean.AccessToken;
import cc.jinglupeng.wechat.bean.JSAPITicket;
public class DefaultWechatCache implements WechatCache {
private static final Map JSAPITICKET_CACHE = new HashMap();
private static final Map ACCESSTOKEN_CACHE = new HashMap();
@Override
public AccessToken getAccessToken(String appId) {
AccessToken token = ACCESSTOKEN_CACHE.get(appId);
if (token == null)
return null;
Long now = System.currentTimeMillis();
Long old = token.getCreateTime();
if (now - old > 6000 * 1000) {
return null;
}
return token;
}
@Override
public void cacheAccessToken(String appId, AccessToken accessToken) {
ACCESSTOKEN_CACHE.put(appId, accessToken);
}
@Override
public JSAPITicket getJSAPITicket(String appId) {
JSAPITicket ticket = JSAPITICKET_CACHE.get(appId);
if (ticket == null)
return null;
Long now = System.currentTimeMillis();
Long old = ticket.getCreateTime();
if (now - old > 6000 * 1000) {
return null;
}
return ticket;
}
@Override
public void cacheJSAPITicket(String appId, JSAPITicket ticket) {
JSAPITICKET_CACHE.put(appId, ticket);
}
}