All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zopen.wechat.work.task.WechatWorkTask Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
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 结束");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy