Skip to content

Commit b87ec9a

Browse files
committed
🎨 #1554 优化小程序获取token逻辑,减少刷新请求次数
1 parent a219035 commit b87ec9a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
116116
Lock lock = this.getWxMaConfig().getAccessTokenLock();
117117
lock.lock();
118118
try {
119+
if (!this.getWxMaConfig().isAccessTokenExpired() && !forceRefresh) {
120+
return this.getWxMaConfig().getAccessToken();
121+
}
122+
119123
String url = String.format(WxMaService.GET_ACCESS_TOKEN_URL, this.getWxMaConfig().getAppid(),
120124
this.getWxMaConfig().getSecret());
121125
try {

0 commit comments

Comments
 (0)