com.zopen.wechat.work.task.WechatWorkTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zopen-ato-starter Show documentation
Show all versions of zopen-ato-starter Show documentation
Alibaba Tencent And Others For Spring Boot.
package com.zopen.wechat.work.task;
import com.zopen.wechat.work.service.WechatWorkAccessTokenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component("atoWechatWorkTask")
@EnableScheduling
public class WechatWorkTask {
private static final Logger logger = LoggerFactory.getLogger(WechatWorkTask.class);
@Autowired
private WechatWorkAccessTokenService wechatWorkAccessTokenService;
@Scheduled(fixedRate = 1 * 60 * 60 * 1000)
private void refreshAccessToken() {
logger.info("开始刷新所有企业微信的 access_token");
for (WechatWorkInfo wechatWorkInfo : WechatWorkInfo.getAgentIdInfoMap().values()) {
try {
wechatWorkAccessTokenService.init(wechatWorkInfo.getCorpId(), wechatWorkInfo.getAgentId(), wechatWorkInfo.getCorpSecret());
} catch (Exception e) {
logger.warn("刷新 access_token 失败,corp_id[{}],agent_id[{}] 错误原因[{}]",
wechatWorkInfo.getCorpId(), wechatWorkInfo.getAgentId(), e.getMessage());
}
}
logger.info("刷新所有 access_token 结束");
}
}