All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.jinglupeng.wechat.DefaultWechatCache Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
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);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy