package info.aspirecn.iov.sjjh.supplier10000053.task; import info.aspirecn.iov.sjjh.supplier10000053.constant.CommonConstant; import info.aspirecn.iov.sjjh.supplier10000053.service.ChannelService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; /** * @author xusonglin * @version V1.0 **/ @Component @Slf4j public class TokenTask { @Autowired StringRedisTemplate stringRedisTemplate; @Autowired ChannelService channelService; @Scheduled(cron = "0 0/10 * * * ?") public void tokenTask() { String redisToken = stringRedisTemplate.opsForValue().get(CommonConstant.REDIS_TOKEN_KEY); if (StringUtils.isNotBlank(redisToken)) { String[] redisTokenArray = redisToken.split("&&"); String accessTokenTimestamp = redisTokenArray[1]; if (System.currentTimeMillis() - Long.parseLong(accessTokenTimestamp) >= 1800000) { String token = channelService.queryAccessToken(1500); log.info("supplier10000053.tokenTask-token即将过期,间隔{},重新获取token:{}", System.currentTimeMillis() - Long.parseLong(accessTokenTimestamp), token); } else { log.info("supplier10000053.tokenTask-还在有效期内,token间隔毫秒:{}", System.currentTimeMillis() - Long.parseLong(accessTokenTimestamp)); } } else { String token = channelService.queryAccessToken(1500); log.info("supplier10000053.tokenTask-token不存在,重新获取token:{}", token); } } }