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