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

com.foxinmy.weixin4j.qy.suite.SuiteTicketHolder Maven / Gradle / Ivy

There is a newer version: 1.10.2
Show newest version
package com.foxinmy.weixin4j.qy.suite;

import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.token.TokenStorager;

/**
 * 应用套件ticket的存取
 * 
 * @className SuiteTicketHolder
 * @author jy
 * @date 2015年6月22日
 * @since JDK 1.6
 * @see
 */
public class SuiteTicketHolder {

	private final String suiteId;
	private final String suiteSecret;
	private final TokenStorager tokenStorager;

	public SuiteTicketHolder(String suiteId, String suiteSecret,
			TokenStorager tokenStorager) {
		this.suiteId = suiteId;
		this.suiteSecret = suiteSecret;
		this.tokenStorager = tokenStorager;
	}

	/**
	 * 获取ticket
	 * 
	 * @return
	 * @throws WeixinException
	 */
	public String getTicket() throws WeixinException {
		return tokenStorager.lookup(getCacheKey()).getAccessToken();
	}

	/**
	 * 获取ticket的key
	 * 
	 * @return
	 */
	public String getCacheKey() {
		return String.format("weixin4j_qy_suite_ticket_%s", suiteId);
	}

	/**
	 * 缓存ticket
	 * 
	 * @param ticket
	 * @throws WeixinException
	 */
	public void cachingTicket(String ticket) throws WeixinException {
		Token token = new Token(ticket);
		token.setExpiresIn(-1);
		tokenStorager.caching(getCacheKey(), token);
	}

	public String getSuiteId() {
		return this.suiteId;
	}

	public String getSuiteSecret() {
		return this.suiteSecret;
	}

	public TokenStorager getTokenStorager() {
		return this.tokenStorager;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy