提交 6733e58b 编写于 作者: nancy's avatar nancy

优化代码

上级 4779be16
...@@ -223,7 +223,7 @@ public class UserDingtalkRegisterService { ...@@ -223,7 +223,7 @@ public class UserDingtalkRegisterService {
return returnObj; return returnObj;
} }
private static Map<String, List<String>> tokenMapping = new HashMap<>(); private static Map<String,TokenInfo> tokenMapping = new HashMap<>();
/** /**
...@@ -236,19 +236,19 @@ public class UserDingtalkRegisterService { ...@@ -236,19 +236,19 @@ public class UserDingtalkRegisterService {
if (!tokenMapping.containsKey(appkey)) if (!tokenMapping.containsKey(appkey))
return true; return true;
List<String> accessTokenInfo = tokenMapping.get(appkey); TokenInfo accessTokenInfo = tokenMapping.get(appkey);
if (CollectionUtils.isEmpty(accessTokenInfo) || accessTokenInfo.size() != 2) if (accessTokenInfo == null)
return true; return true;
String accessToken = accessTokenInfo.get(0); String accessToken = accessTokenInfo.accessToken;
String refreshtime = accessTokenInfo.get(1); Long refreshtime = accessTokenInfo.lastRefreshTime;
if (StringUtils.isEmpty(accessToken) || StringUtils.isEmpty(refreshtime)) if (StringUtils.isEmpty(accessToken) || refreshtime == null)
return true; return true;
if (System.currentTimeMillis() < (Long.valueOf(refreshtime) + 7100000)) { if (System.currentTimeMillis() < refreshtime + 7100000) {
System.currentTimeMillis(); System.currentTimeMillis();
return false; return false;
} }
...@@ -260,21 +260,20 @@ public class UserDingtalkRegisterService { ...@@ -260,21 +260,20 @@ public class UserDingtalkRegisterService {
return; return;
if (!tokenMapping.containsKey(appkey)) { if (!tokenMapping.containsKey(appkey)) {
List<String> tokenInfo = new ArrayList<>(2); tokenMapping.put(appkey, new TokenInfo());
tokenMapping.put(appkey, tokenInfo);
} }
List<String> tokenInfo = tokenMapping.get(appkey); TokenInfo tokenInfo = tokenMapping.get(appkey);
tokenInfo.set(0, token); tokenInfo.accessToken = token;
tokenInfo.set(1, String.valueOf(refreshTime)); tokenInfo.lastRefreshTime = refreshTime;
} }
private String getToken(String appkey){ private String getToken(String appkey){
if(!StringUtils.isEmpty(appkey)){ if (!StringUtils.isEmpty(appkey)){
List<String> tokenInfo = tokenMapping.get(appkey); TokenInfo tokenInfo = tokenMapping.get(appkey);
if(!CollectionUtils.isEmpty(tokenInfo) && tokenInfo.size()==2) if (tokenInfo != null)
return tokenMapping.get(appkey).get(0); return tokenMapping.get(appkey).accessToken;
} }
return null; return null;
} }
...@@ -282,17 +281,18 @@ public class UserDingtalkRegisterService { ...@@ -282,17 +281,18 @@ public class UserDingtalkRegisterService {
* 钉钉默认超时时间为2小时(7200秒),防止程序卡点,换成7100秒(100秒预留) * 钉钉默认超时时间为2小时(7200秒),防止程序卡点,换成7100秒(100秒预留)
*/ */
private Long getLastRefreshTime(String appkey){ private Long getLastRefreshTime(String appkey){
if(!StringUtils.isEmpty(appkey)){ if (!StringUtils.isEmpty(appkey)){
List<String> tokenInfo = tokenMapping.get(appkey); TokenInfo tokenInfo = tokenMapping.get(appkey);
if(!CollectionUtils.isEmpty(tokenInfo) && tokenInfo.size()==2) { if (tokenInfo != null){
String refreshtime = tokenMapping.get(appkey).get(1); return tokenInfo.lastRefreshTime;
try {
return Long.valueOf(refreshtime);
} catch (Exception e) {
e.printStackTrace();
}
} }
} }
return System.currentTimeMillis()-7100001; return System.currentTimeMillis()-7100001;
} }
class TokenInfo{
String accessToken;
Long lastRefreshTime;
}
} }
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册