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

优化代码

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