liukangdong
2024-08-07 b0a4d23b83b9cdbdee15263acdd4e7353a8286a1
server/web/src/main/java/com/doumee/api/ScheduleTool.java
@@ -5,7 +5,6 @@
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.HttpsUtil;
import com.doumee.core.wx.WXConstant;
import com.doumee.dao.system.model.SystemDictData;
import com.doumee.service.system.SystemDictDataService;
import lombok.extern.slf4j.Slf4j;
@@ -35,11 +34,10 @@
 * @date 2021-10-10 14:40:35
 * https://www.bejson.com/othertools/cron/  cron 表达式生成地址
 */
//@Component
//@EnableScheduling
@Component
@EnableScheduling
@Slf4j
public class ScheduleTool {
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
@@ -50,31 +48,6 @@
     */
    @Value("${debug_model}")
    private Boolean timing;
    /**
     * 更新微信公众号 ACCESS_TOKEN
     * @throws Exception
     */
    @Scheduled(fixedDelay=1000 * 60 * 90)
    public void updAccessToken(){
        DefaultSecurityManager securityManager = new DefaultSecurityManager();
        SecurityUtils.setSecurityManager(securityManager);
        String appId = systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_APPID).getCode();
        String appSecret = systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_SECRET).getCode();
        //生成微信token
        String url = WXConstant.GET_ACCESS_TOKEN_URL.replace("APPID",appId).replace("APPSECRET",appSecret);
        String response = HttpsUtil.get(url,false);
        JSONObject json = JSONObject.parseObject(response);
        System.out.println(json);
        SystemDictData systemDictData =  systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN);
        if(!Objects.isNull(systemDictData)){
            systemDictData.setCode(json.getString("access_token"));
            systemDictData.setUpdateTime(new Date());
            systemDictDataService.updateById(systemDictData);
            log.info(" 更新微信公众号 ACCESS_TOKEN =========> " + systemDictData.getCode() );
        }
    }