...
|
...
|
@@ -36,17 +36,27 @@ public class WeixinAccessTokenServiceImpl implements IWeixinAccessTokenService { |
|
|
|
|
|
@Override
|
|
|
public AccessToken queryWeixinAccessToken() {
|
|
|
String accessTokenString = null;
|
|
|
String accessTokenKey = KeyBuilder.getAccesstokenKey();
|
|
|
try {
|
|
|
String value = pushRedisService.value_get(accessTokenKey);
|
|
|
if (StringUtils.isNotBlank(value)) {
|
|
|
return toObject(accessTokenString);
|
|
|
String accessTokenKey = KeyBuilder.getAccesstokenKey();
|
|
|
String redisValue = pushRedisService.value_get(accessTokenKey);
|
|
|
if (StringUtils.isNotBlank(redisValue)) {
|
|
|
return toAccessToken(redisValue);
|
|
|
} else {
|
|
|
return getAccessTokenFromUrl(accessTokenKey);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.info("get access_token from redis fail,error message {}", e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private static AccessToken toAccessToken(String tokenValue) {
|
|
|
if (StringUtils.isNotBlank(tokenValue)) {
|
|
|
String[] data = tokenValue.split(",");
|
|
|
AccessToken accessToken = new AccessToken();
|
|
|
accessToken.setToken(data[0]);
|
|
|
accessToken.setExpiresIn(Integer.valueOf(data[1]));
|
|
|
return accessToken;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
...
|
...
|
@@ -68,15 +78,4 @@ public class WeixinAccessTokenServiceImpl implements IWeixinAccessTokenService { |
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public static AccessToken toObject(String tokenValue) {
|
|
|
if (StringUtils.isNotBlank(tokenValue)) {
|
|
|
String[] data = tokenValue.split(",");
|
|
|
AccessToken accessToken = new AccessToken();
|
|
|
accessToken.setToken(data[0]);
|
|
|
accessToken.setExpiresIn(Integer.valueOf(String.valueOf(Long.valueOf(data[1]))));
|
|
|
return accessToken;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
} |
...
|
...
|
|