继续优化
This commit is contained in:
parent
aa8e1c759d
commit
845c4d111b
@ -95,7 +95,7 @@ public class WeixinRequestExecutor {
|
||||
return doRequest(request);
|
||||
}
|
||||
|
||||
public WeixinResponse doRequest(HttpRequest request) throws WeixinException {
|
||||
protected WeixinResponse doRequest(HttpRequest request) throws WeixinException {
|
||||
request.setParams(params);
|
||||
try {
|
||||
logger.info("weixin request >> " + request.getMethod() + " "
|
||||
|
||||
@ -17,9 +17,9 @@ import com.foxinmy.weixin4j.type.TicketType;
|
||||
* @author jy
|
||||
* @date 2015年1月10日
|
||||
* @since JDK 1.6
|
||||
* @see <a
|
||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN">JS
|
||||
* TICKET</a>
|
||||
* @see <a href=
|
||||
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN">
|
||||
* JS TICKET</a>
|
||||
*/
|
||||
public class WeixinTicketCreator implements TokenCreator {
|
||||
|
||||
@ -38,8 +38,7 @@ public class WeixinTicketCreator implements TokenCreator {
|
||||
* @param weixinTokenHolder
|
||||
* <font color="red">公众平台的access_token</font>
|
||||
*/
|
||||
public WeixinTicketCreator(String appid, TicketType ticketType,
|
||||
TokenHolder weixinTokenHolder) {
|
||||
public WeixinTicketCreator(String appid, TicketType ticketType, TokenHolder weixinTokenHolder) {
|
||||
this.appid = appid;
|
||||
this.ticketType = ticketType;
|
||||
this.weixinTokenHolder = weixinTokenHolder;
|
||||
@ -48,14 +47,13 @@ public class WeixinTicketCreator implements TokenCreator {
|
||||
|
||||
@Override
|
||||
public String getCacheKey() {
|
||||
return String.format("weixin4j_mp_ticket_%s_%s", appid, ticketType.name());
|
||||
return String.format("weixin4j_mp_ticket_%s_%s", ticketType.name(), appid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token createToken() throws WeixinException {
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
URLConsts.TICKET_URL, weixinTokenHolder.getToken()
|
||||
.getAccessToken(), ticketType.name()));
|
||||
WeixinResponse response = weixinExecutor.get(
|
||||
String.format(URLConsts.TICKET_URL, weixinTokenHolder.getToken().getAccessToken(), ticketType.name()));
|
||||
JSONObject result = response.getAsJson();
|
||||
Token token = new Token(result.getString("ticket"));
|
||||
token.setExpiresIn(result.getIntValue("expires_in"));
|
||||
|
||||
@ -45,7 +45,7 @@ public class SuitePerCodeHolder {
|
||||
* @return
|
||||
*/
|
||||
public String getCacheKey() {
|
||||
return String.format("weixin4j_qy_suite_percode_%s:%s", suiteId,
|
||||
return String.format("weixin4j_qy_suite_percode_%s_%s", suiteId,
|
||||
authCorpId);
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ public class SuiteTicketHolder {
|
||||
* @return
|
||||
*/
|
||||
public String getCacheKey() {
|
||||
return String.format("qy_suite_ticket_%s", suiteId);
|
||||
return String.format("weixin4j_qy_suite_ticket_%s", suiteId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -42,7 +42,7 @@ public class WeixinTokenSuiteCreator implements TokenCreator {
|
||||
|
||||
@Override
|
||||
public String getCacheKey() {
|
||||
return String.format("weixin4j_qy_token_suite_%s:%s",
|
||||
return String.format("weixin4j_qy_token_suite_%s_%s",
|
||||
perCodeHolder.getSuiteId(), perCodeHolder.getAuthCorpId()
|
||||
|
||||
);
|
||||
|
||||
@ -35,8 +35,7 @@ public class WeixinTicketCreator implements TokenCreator {
|
||||
* @param weixinTokenHolder
|
||||
* <font color="red">企业号的的access_token</font>
|
||||
*/
|
||||
public WeixinTicketCreator(String corpid, TicketType ticketType,
|
||||
TokenHolder weixinTokenHolder) {
|
||||
public WeixinTicketCreator(String corpid, TicketType ticketType, TokenHolder weixinTokenHolder) {
|
||||
this.corpid = corpid;
|
||||
this.ticketType = ticketType;
|
||||
this.weixinTokenHolder = weixinTokenHolder;
|
||||
@ -45,20 +44,18 @@ public class WeixinTicketCreator implements TokenCreator {
|
||||
|
||||
@Override
|
||||
public String getCacheKey() {
|
||||
return String.format("weixin4j_qy_ticket_%s_%s", corpid, ticketType.name());
|
||||
return String.format("weixin4j_qy_ticket_%s_%s", ticketType.name(), corpid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token createToken() throws WeixinException {
|
||||
WeixinResponse response = null;
|
||||
if (ticketType == TicketType.jsapi) {
|
||||
response = weixinExecutor.get(String.format(
|
||||
URLConsts.JS_TICKET_URL, weixinTokenHolder.getToken()
|
||||
.getAccessToken()));
|
||||
response = weixinExecutor
|
||||
.get(String.format(URLConsts.JS_TICKET_URL, weixinTokenHolder.getToken().getAccessToken()));
|
||||
} else {
|
||||
response = weixinExecutor.get(String.format(URLConsts.TICKET_URL,
|
||||
weixinTokenHolder.getToken().getAccessToken(),
|
||||
ticketType.name()));
|
||||
weixinTokenHolder.getToken().getAccessToken(), ticketType.name()));
|
||||
}
|
||||
JSONObject result = response.getAsJson();
|
||||
Token token = new Token(result.getString("ticket"));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user