删除AbstractTokenCreator,引入CacheCreator<T>类
This commit is contained in:
parent
eb54ea9079
commit
f6c12e07f3
14
CHANGE.md
14
CHANGE.md
@ -687,4 +687,16 @@
|
|||||||
|
|
||||||
* 2016-05-12
|
* 2016-05-12
|
||||||
|
|
||||||
+ 添加MemcacheTokenStorager支持
|
+ weixin4j-base:添加MemcacheTokenStorager支持
|
||||||
|
|
||||||
|
* 2016-05-24
|
||||||
|
|
||||||
|
+ weixin4j-mp:优化OauthApi授权
|
||||||
|
|
||||||
|
+ openid 修正为 openId
|
||||||
|
|
||||||
|
+ 修改@author注释为jinyu(foxinmy@gmail.com)
|
||||||
|
|
||||||
|
+ weixin4j-base:删除AbstractTokenCreator,引入CacheCreator<T>类
|
||||||
|
|
||||||
|
+ weixin4j-base:修改Memcached-Java-Client的依赖
|
||||||
@ -1,36 +0,0 @@
|
|||||||
package com.foxinmy.weixin4j.token;
|
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @className: AbstractTokenCreator
|
|
||||||
* @author jinyu
|
|
||||||
* @date 2016年4月21日
|
|
||||||
* @since JDK 1.6
|
|
||||||
* @see
|
|
||||||
*/
|
|
||||||
public abstract class AbstractTokenCreator implements TokenCreator {
|
|
||||||
|
|
||||||
protected final WeixinRequestExecutor weixinExecutor;
|
|
||||||
|
|
||||||
public AbstractTokenCreator() {
|
|
||||||
this.weixinExecutor = new WeixinRequestExecutor();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存key:附加weixin4j_前缀
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getCacheKey() {
|
|
||||||
return String.format("weixin4j_%s", getCacheKey0());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 返回缓存KEY的名称:建议接口类型命名 如 mp_token_{appid}
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public abstract String getCacheKey0();
|
|
||||||
}
|
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package com.foxinmy.weixin4j.token;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache的创建
|
||||||
|
*
|
||||||
|
* @className CacheCreator
|
||||||
|
* @author jinyu(foxinmy@gmail.com)
|
||||||
|
* @date 2016年5月24日
|
||||||
|
* @since JDK 1.6
|
||||||
|
* @see
|
||||||
|
*/
|
||||||
|
public interface CacheCreator<T> {
|
||||||
|
/**
|
||||||
|
* CacheKey
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String key();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建Cache
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public T create() throws WeixinException;
|
||||||
|
}
|
||||||
@ -3,7 +3,7 @@ package com.foxinmy.weixin4j.token;
|
|||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cache存储
|
* Cache的存储
|
||||||
*
|
*
|
||||||
* @className CacheStorager
|
* @className CacheStorager
|
||||||
* @author jinyu(foxinmy@gmail.com)
|
* @author jinyu(foxinmy@gmail.com)
|
||||||
@ -15,33 +15,33 @@ public interface CacheStorager<T> {
|
|||||||
/**
|
/**
|
||||||
* 查找缓存中的对象
|
* 查找缓存中的对象
|
||||||
*
|
*
|
||||||
* @param cacheKey
|
* @param key
|
||||||
* 缓存key
|
* 缓存key
|
||||||
* @return 缓存对象
|
* @return 缓存对象
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
T lookup(String cacheKey) throws WeixinException;
|
T lookup(String key) throws WeixinException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存新的对象
|
* 缓存新的对象
|
||||||
*
|
*
|
||||||
* @param cacheKey
|
* @param key
|
||||||
* 缓存key
|
* 缓存key
|
||||||
*
|
*
|
||||||
* @param t
|
* @param cache
|
||||||
* 将要缓存的对象
|
* 将要缓存的对象
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
void caching(String cacheKey, T t) throws WeixinException;
|
void caching(String key, T cache) throws WeixinException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除缓存对象
|
* 移除缓存对象
|
||||||
*
|
*
|
||||||
* @param cacheKey
|
* @param key
|
||||||
* 缓存key
|
* 缓存key
|
||||||
* @return 移除的对象
|
* @return 移除的对象
|
||||||
*/
|
*/
|
||||||
T evict(String cacheKey) throws WeixinException;
|
T evict(String key) throws WeixinException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除所有缓存对象(<font color="red">请慎重</font>)
|
* 清除所有缓存对象(<font color="red">请慎重</font>)
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
package com.foxinmy.weixin4j.token;
|
package com.foxinmy.weixin4j.token;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TOKEN创建者
|
* Token的创建
|
||||||
*
|
*
|
||||||
* @className TokenCreator
|
* @className TokenCreator
|
||||||
* @author jinyu(foxinmy@gmail.com)
|
* @author jinyu(foxinmy@gmail.com)
|
||||||
@ -12,19 +12,27 @@ import com.foxinmy.weixin4j.model.Token;
|
|||||||
* @since JDK 1.6
|
* @since JDK 1.6
|
||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
public interface TokenCreator {
|
public abstract class TokenCreator implements CacheCreator<Token> {
|
||||||
/**
|
protected final WeixinRequestExecutor weixinExecutor;
|
||||||
* 返回缓存KEY的名称
|
|
||||||
*
|
public TokenCreator() {
|
||||||
* @return
|
this.weixinExecutor = new WeixinRequestExecutor();
|
||||||
*/
|
}
|
||||||
public String getCacheKey();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建token
|
* 缓存key:附加weixin4j_前缀
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* @throws WeixinException
|
|
||||||
*/
|
*/
|
||||||
public Token createToken() throws WeixinException;
|
@Override
|
||||||
|
public String key() {
|
||||||
|
return String.format("weixin4j_%s", key0());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回缓存KEY的名称:建议接口类型命名 如 mp_token_{appid}
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract String key0();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,10 +43,10 @@ public class TokenHolder {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public Token getToken() throws WeixinException {
|
public Token getToken() throws WeixinException {
|
||||||
String cacheKey = tokenCreator.getCacheKey();
|
String cacheKey = tokenCreator.key();
|
||||||
Token token = tokenStorager.lookup(cacheKey);
|
Token token = tokenStorager.lookup(cacheKey);
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
token = tokenCreator.createToken();
|
token = tokenCreator.create();
|
||||||
tokenStorager.caching(cacheKey, token);
|
tokenStorager.caching(cacheKey, token);
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
@ -69,8 +69,8 @@ public class TokenHolder {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public Token refreshToken() throws WeixinException {
|
public Token refreshToken() throws WeixinException {
|
||||||
String cacheKey = tokenCreator.getCacheKey();
|
String cacheKey = tokenCreator.key();
|
||||||
Token token = tokenCreator.createToken();
|
Token token = tokenCreator.create();
|
||||||
tokenStorager.caching(cacheKey, token);
|
tokenStorager.caching(cacheKey, token);
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ public class TokenHolder {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public Token evictToken() throws WeixinException {
|
public Token evictToken() throws WeixinException {
|
||||||
String cacheKey = tokenCreator.getCacheKey();
|
String cacheKey = tokenCreator.key();
|
||||||
return tokenStorager.evict(cacheKey);
|
return tokenStorager.evict(cacheKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package com.foxinmy.weixin4j.token;
|
|||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* token的存储
|
* Token的存储
|
||||||
*
|
*
|
||||||
* @className TokenStorager
|
* @className TokenStorager
|
||||||
* @author jinyu(foxinmy@gmail.com)
|
* @author jinyu(foxinmy@gmail.com)
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.mp.type.URLConsts;
|
import com.foxinmy.weixin4j.mp.type.URLConsts;
|
||||||
import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
import com.foxinmy.weixin4j.type.TicketType;
|
import com.foxinmy.weixin4j.type.TicketType;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ import com.foxinmy.weixin4j.type.TicketType;
|
|||||||
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN">
|
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN">
|
||||||
* JS TICKET</a>
|
* JS TICKET</a>
|
||||||
*/
|
*/
|
||||||
public class WeixinTicketCreator extends AbstractTokenCreator {
|
public class WeixinTicketCreator extends TokenCreator {
|
||||||
|
|
||||||
private final String appid;
|
private final String appid;
|
||||||
private final TicketType ticketType;
|
private final TicketType ticketType;
|
||||||
@ -43,12 +43,12 @@ public class WeixinTicketCreator extends AbstractTokenCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCacheKey0() {
|
public String key0() {
|
||||||
return String.format("mp_ticket_%s_%s", ticketType.name(), appid);
|
return String.format("mp_ticket_%s_%s", ticketType.name(), appid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token createToken() throws WeixinException {
|
public Token create() throws WeixinException {
|
||||||
WeixinResponse response = weixinExecutor.get(
|
WeixinResponse response = weixinExecutor.get(
|
||||||
String.format(URLConsts.JS_TICKET_URL, weixinTokenHolder.getToken().getAccessToken(), ticketType.name()));
|
String.format(URLConsts.JS_TICKET_URL, weixinTokenHolder.getToken().getAccessToken(), ticketType.name()));
|
||||||
JSONObject result = response.getAsJson();
|
JSONObject result = response.getAsJson();
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.mp.type.URLConsts;
|
import com.foxinmy.weixin4j.mp.type.URLConsts;
|
||||||
import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信公众平台TOKEN创建者
|
* 微信公众平台TOKEN创建者
|
||||||
@ -18,7 +18,7 @@ import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
|||||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183&token=&lang=zh_CN">微信公众平台获取token说明</a>
|
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183&token=&lang=zh_CN">微信公众平台获取token说明</a>
|
||||||
* @see com.foxinmy.weixin4j.model.Token
|
* @see com.foxinmy.weixin4j.model.Token
|
||||||
*/
|
*/
|
||||||
public class WeixinTokenCreator extends AbstractTokenCreator {
|
public class WeixinTokenCreator extends TokenCreator {
|
||||||
|
|
||||||
private final String appid;
|
private final String appid;
|
||||||
private final String secret;
|
private final String secret;
|
||||||
@ -36,12 +36,12 @@ public class WeixinTokenCreator extends AbstractTokenCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCacheKey0() {
|
public String key0() {
|
||||||
return String.format("mp_token_%s", appid);
|
return String.format("mp_token_%s", appid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token createToken() throws WeixinException {
|
public Token create() throws WeixinException {
|
||||||
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, appid,
|
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, appid,
|
||||||
secret);
|
secret);
|
||||||
WeixinResponse response = weixinExecutor.get(tokenUrl);
|
WeixinResponse response = weixinExecutor.get(tokenUrl);
|
||||||
|
|||||||
@ -168,7 +168,7 @@ public class SuiteApi extends QyApi {
|
|||||||
Token token = new Token(obj.getString("access_token"));
|
Token token = new Token(obj.getString("access_token"));
|
||||||
token.setExpiresIn(obj.getIntValue("expires_in"));
|
token.setExpiresIn(obj.getIntValue("expires_in"));
|
||||||
suiteTicketHolder.getTokenStorager().caching(
|
suiteTicketHolder.getTokenStorager().caching(
|
||||||
tokenCreator.getCacheKey(), token);
|
tokenCreator.key(), token);
|
||||||
// 缓存微信企业号永久授权码
|
// 缓存微信企业号永久授权码
|
||||||
suitePerCodeHolder
|
suitePerCodeHolder
|
||||||
.cachingPermanentCode(obj.getString("permanent_code"));
|
.cachingPermanentCode(obj.getString("permanent_code"));
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||||
import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,7 +20,7 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
|||||||
* 获取应用套件预授权码</a>
|
* 获取应用套件预授权码</a>
|
||||||
* @see com.foxinmy.weixin4j.model.Token
|
* @see com.foxinmy.weixin4j.model.Token
|
||||||
*/
|
*/
|
||||||
public class WeixinSuitePreCodeCreator extends AbstractTokenCreator {
|
public class WeixinSuitePreCodeCreator extends TokenCreator {
|
||||||
|
|
||||||
private final TokenHolder suiteTokenHolder;
|
private final TokenHolder suiteTokenHolder;
|
||||||
private final String suiteId;
|
private final String suiteId;
|
||||||
@ -38,12 +38,12 @@ public class WeixinSuitePreCodeCreator extends AbstractTokenCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCacheKey0() {
|
public String key0() {
|
||||||
return String.format("qy_suite_precode_%s", suiteId);
|
return String.format("qy_suite_precode_%s", suiteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token createToken() throws WeixinException {
|
public Token create() throws WeixinException {
|
||||||
WeixinResponse response = weixinExecutor.post(
|
WeixinResponse response = weixinExecutor.post(
|
||||||
String.format(URLConsts.SUITE_PRE_CODE_URL, suiteTokenHolder.getAccessToken()),
|
String.format(URLConsts.SUITE_PRE_CODE_URL, suiteTokenHolder.getAccessToken()),
|
||||||
String.format("{\"suite_id\":\"%s\"}", suiteId));
|
String.format("{\"suite_id\":\"%s\"}", suiteId));
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||||
import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信企业号应用套件凭证创建
|
* 微信企业号应用套件凭证创建
|
||||||
@ -18,7 +18,7 @@ import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
|||||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E5.BA.94.E7.94.A8.E5.A5.97.E4.BB.B6.E4.BB.A4.E7.89.8C">获取应用套件凭证</a>
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E5.BA.94.E7.94.A8.E5.A5.97.E4.BB.B6.E4.BB.A4.E7.89.8C">获取应用套件凭证</a>
|
||||||
* @see com.foxinmy.weixin4j.model.Token
|
* @see com.foxinmy.weixin4j.model.Token
|
||||||
*/
|
*/
|
||||||
public class WeixinSuiteTokenCreator extends AbstractTokenCreator {
|
public class WeixinSuiteTokenCreator extends TokenCreator {
|
||||||
|
|
||||||
private final SuiteTicketHolder ticketHolder;
|
private final SuiteTicketHolder ticketHolder;
|
||||||
|
|
||||||
@ -32,12 +32,12 @@ public class WeixinSuiteTokenCreator extends AbstractTokenCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCacheKey0() {
|
public String key0() {
|
||||||
return String.format("qy_suite_token_%s", ticketHolder.getSuiteId());
|
return String.format("qy_suite_token_%s", ticketHolder.getSuiteId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token createToken() throws WeixinException {
|
public Token create() throws WeixinException {
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", ticketHolder.getSuiteId());
|
obj.put("suite_id", ticketHolder.getSuiteId());
|
||||||
obj.put("suite_secret", ticketHolder.getSuiteSecret());
|
obj.put("suite_secret", ticketHolder.getSuiteSecret());
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||||
import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,7 +20,7 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
|||||||
* 获取企业号access_token</a>
|
* 获取企业号access_token</a>
|
||||||
* @see com.foxinmy.weixin4j.model.Token
|
* @see com.foxinmy.weixin4j.model.Token
|
||||||
*/
|
*/
|
||||||
public class WeixinTokenSuiteCreator extends AbstractTokenCreator {
|
public class WeixinTokenSuiteCreator extends TokenCreator {
|
||||||
|
|
||||||
private final SuitePerCodeHolder perCodeHolder;
|
private final SuitePerCodeHolder perCodeHolder;
|
||||||
private final TokenHolder suiteTokenHolder;
|
private final TokenHolder suiteTokenHolder;
|
||||||
@ -38,12 +38,12 @@ public class WeixinTokenSuiteCreator extends AbstractTokenCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCacheKey0() {
|
public String key0() {
|
||||||
return String.format("qy_token_suite_%s_%s", perCodeHolder.getSuiteId(), perCodeHolder.getAuthCorpId());
|
return String.format("qy_token_suite_%s_%s", perCodeHolder.getSuiteId(), perCodeHolder.getAuthCorpId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token createToken() throws WeixinException {
|
public Token create() throws WeixinException {
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", perCodeHolder.getSuiteId());
|
obj.put("suite_id", perCodeHolder.getSuiteId());
|
||||||
obj.put("auth_corpid", perCodeHolder.getAuthCorpId());
|
obj.put("auth_corpid", perCodeHolder.getAuthCorpId());
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||||
import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信企业号应用提供商凭证创建
|
* 微信企业号应用提供商凭证创建
|
||||||
@ -19,7 +19,7 @@ import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
|||||||
* 获取应用提供商凭证</a>
|
* 获取应用提供商凭证</a>
|
||||||
* @see com.foxinmy.weixin4j.model.Token
|
* @see com.foxinmy.weixin4j.model.Token
|
||||||
*/
|
*/
|
||||||
public class WeixinProviderTokenCreator extends AbstractTokenCreator {
|
public class WeixinProviderTokenCreator extends TokenCreator {
|
||||||
|
|
||||||
private final String corpid;
|
private final String corpid;
|
||||||
private final String providersecret;
|
private final String providersecret;
|
||||||
@ -37,12 +37,12 @@ public class WeixinProviderTokenCreator extends AbstractTokenCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCacheKey0() {
|
public String key0() {
|
||||||
return String.format("qy_provider_token_%s", corpid);
|
return String.format("qy_provider_token_%s", corpid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token createToken() throws WeixinException {
|
public Token create() throws WeixinException {
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("corpid", corpid);
|
obj.put("corpid", corpid);
|
||||||
obj.put("provider_secret", providersecret);
|
obj.put("provider_secret", providersecret);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||||
import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
import com.foxinmy.weixin4j.type.TicketType;
|
import com.foxinmy.weixin4j.type.TicketType;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ import com.foxinmy.weixin4j.type.TicketType;
|
|||||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BE%AE%E4%BF%A1JS-SDK%E6%8E%A5%E5%8F%A3#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95"
|
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BE%AE%E4%BF%A1JS-SDK%E6%8E%A5%E5%8F%A3#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95"
|
||||||
* >JSTICKET</a>
|
* >JSTICKET</a>
|
||||||
*/
|
*/
|
||||||
public class WeixinTicketCreator extends AbstractTokenCreator {
|
public class WeixinTicketCreator extends TokenCreator {
|
||||||
|
|
||||||
private final String corpid;
|
private final String corpid;
|
||||||
private final TicketType ticketType;
|
private final TicketType ticketType;
|
||||||
@ -40,12 +40,12 @@ public class WeixinTicketCreator extends AbstractTokenCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCacheKey0() {
|
public String key0() {
|
||||||
return String.format("qy_ticket_%s_%s", ticketType.name(), corpid);
|
return String.format("qy_ticket_%s_%s", ticketType.name(), corpid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token createToken() throws WeixinException {
|
public Token create() throws WeixinException {
|
||||||
WeixinResponse response = null;
|
WeixinResponse response = null;
|
||||||
if (ticketType == TicketType.jsapi) {
|
if (ticketType == TicketType.jsapi) {
|
||||||
response = weixinExecutor
|
response = weixinExecutor
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||||
import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信企业号TOKEN创建
|
* 微信企业号TOKEN创建
|
||||||
@ -19,7 +19,7 @@ import com.foxinmy.weixin4j.token.AbstractTokenCreator;
|
|||||||
* 微信企业号获取token说明</a>
|
* 微信企业号获取token说明</a>
|
||||||
* @see com.foxinmy.weixin4j.model.Token
|
* @see com.foxinmy.weixin4j.model.Token
|
||||||
*/
|
*/
|
||||||
public class WeixinTokenCreator extends AbstractTokenCreator {
|
public class WeixinTokenCreator extends TokenCreator {
|
||||||
|
|
||||||
private final String corpid;
|
private final String corpid;
|
||||||
private final String corpsecret;
|
private final String corpsecret;
|
||||||
@ -37,12 +37,12 @@ public class WeixinTokenCreator extends AbstractTokenCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCacheKey0() {
|
public String key0() {
|
||||||
return String.format("qy_token_%s", corpid);
|
return String.format("qy_token_%s", corpid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token createToken() throws WeixinException {
|
public Token create() throws WeixinException {
|
||||||
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, corpid,
|
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, corpid,
|
||||||
corpsecret);
|
corpsecret);
|
||||||
WeixinResponse response = weixinExecutor.get(tokenUrl);
|
WeixinResponse response = weixinExecutor.get(tokenUrl);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user