|
2 | 2 |
|
3 | 3 | import cn.binarywang.wx.miniapp.api.*; |
4 | 4 | import cn.binarywang.wx.miniapp.config.WxMaConfig; |
| 5 | +import cn.binarywang.wx.miniapp.constant.WxMaConstants; |
5 | 6 | import com.google.gson.JsonParser; |
6 | 7 | import me.chanjar.weixin.common.bean.WxAccessToken; |
7 | 8 | import me.chanjar.weixin.common.bean.result.WxError; |
@@ -147,6 +148,7 @@ public String post(String url, String postData) throws WxErrorException { |
147 | 148 | /** |
148 | 149 | * 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求 |
149 | 150 | */ |
| 151 | + @Override |
150 | 152 | public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException { |
151 | 153 | int retryTimes = 0; |
152 | 154 | do { |
@@ -195,11 +197,10 @@ public synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, Str |
195 | 197 | WxError error = e.getError(); |
196 | 198 | /* |
197 | 199 | * 发生以下情况时尝试刷新access_token |
198 | | - * 40001 获取access_token时AppSecret错误,或者access_token无效 |
199 | | - * 42001 access_token超时 |
200 | | - * 40014 不合法的access_token,请开发者认真比对access_token的有效性(如是否过期) |
201 | 200 | */ |
202 | | - if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) { |
| 201 | + if (error.getErrorCode() == WxMaConstants.ErrorCode.ERR_40001 |
| 202 | + || error.getErrorCode() == WxMaConstants.ErrorCode.ERR_42001 |
| 203 | + || error.getErrorCode() == WxMaConstants.ErrorCode.ERR_40014) { |
203 | 204 | // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token |
204 | 205 | this.getWxMaConfig().expireAccessToken(); |
205 | 206 | if (this.getWxMaConfig().autoRefreshToken()) { |
|
0 commit comments