Visitar URL original
修复更新票据锁调用时机 by jnLaoA · Pull Request #1820 · binarywang/WxJava · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix:调整获取相关票据的锁处理时机
  • Loading branch information
nplus-xingweiwei committed Oct 23, 2020
commit cdac6192fcbdd4e5034b008b8cadfe957b9d1808
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@ public String getCardApiTicket() throws WxErrorException {

@Override
public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
Lock lock = this.wxMaService.getWxMaConfig().getCardApiTicketLock();
lock.lock();
try {
if (forceRefresh) {
this.wxMaService.getWxMaConfig().expireCardApiTicket();
}

if (this.wxMaService.getWxMaConfig().isCardApiTicketExpired()) {
if (forceRefresh) {
this.wxMaService.getWxMaConfig().expireCardApiTicket();
}

if (this.wxMaService.getWxMaConfig().isCardApiTicketExpired()) {
Lock lock = this.wxMaService.getWxMaConfig().getCardApiTicketLock();
lock.lock();
try {
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=wx_card", null);
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.wxMaService.getWxMaConfig().updateCardApiTicket(jsapiTicket, expiresInSeconds);
} finally {
lock.unlock();
}
} finally {
lock.unlock();
}
return this.wxMaService.getWxMaConfig().getCardApiTicket();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,24 @@ public String getTicket(TicketType type) throws WxErrorException {

@Override
public String getTicket(TicketType type, boolean forceRefresh) throws WxErrorException {
Lock lock = this.getWxMpConfigStorage().getTicketLock(type);
lock.lock();
try {
if (forceRefresh) {
this.getWxMpConfigStorage().expireTicket(type);
}

if (this.getWxMpConfigStorage().isTicketExpired(type)) {
if (forceRefresh) {
this.getWxMpConfigStorage().expireTicket(type);
}

if (this.getWxMpConfigStorage().isTicketExpired(type)) {
Lock lock = this.getWxMpConfigStorage().getTicketLock(type);
lock.lock();
try {
String responseContent = execute(SimpleGetRequestExecutor.create(this),
GET_TICKET_URL.getUrl(this.getWxMpConfigStorage()) + type.getCode(), null);
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.getWxMpConfigStorage().updateTicket(type, jsapiTicket, expiresInSeconds);
} finally {
lock.unlock();
}
} finally {
lock.unlock();
}

return this.getWxMpConfigStorage().getTicket(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ public String getCardApiTicket() throws WxErrorException {
@Override
public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
final TicketType type = TicketType.WX_CARD;
Lock lock = getWxMpService().getWxMpConfigStorage().getTicketLock(type);
lock.lock();
try {

if (forceRefresh) {
this.getWxMpService().getWxMpConfigStorage().expireTicket(type);
}
if (forceRefresh) {
this.getWxMpService().getWxMpConfigStorage().expireTicket(type);
}

if (this.getWxMpService().getWxMpConfigStorage().isTicketExpired(type)) {
if (this.getWxMpService().getWxMpConfigStorage().isTicketExpired(type)) {
Lock lock = getWxMpService().getWxMpConfigStorage().getTicketLock(type);
lock.lock();
try {
String responseContent = this.wxMpService.execute(SimpleGetRequestExecutor
.create(this.getWxMpService().getRequestHttp()), WxMpApiUrl.Card.CARD_GET_TICKET, null);
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String cardApiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.getWxMpService().getWxMpConfigStorage().updateTicket(type, cardApiTicket, expiresInSeconds);
} finally {
lock.unlock();
}
} finally {
lock.unlock();
}
return this.getWxMpService().getWxMpConfigStorage().getTicket(type);
}
Expand Down