From e689c750f4390575ff619c212573be2f12e64618 Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Thu, 23 Jan 2025 11:33:11 +0800 Subject: [PATCH] refactor(mall): 重构小程序定时任务获取 access_token 方式 - 移除 XcxProperties 类的使用 - 使用 @Value 注解直接注入小程序 appid 和 secret - 优化代码结构,提高可读性和维护性 --- src/main/java/cc/mrbird/febs/mall/quartz/WxxcxJob.java | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/quartz/WxxcxJob.java b/src/main/java/cc/mrbird/febs/mall/quartz/WxxcxJob.java index c7d8063..09959ed 100644 --- a/src/main/java/cc/mrbird/febs/mall/quartz/WxxcxJob.java +++ b/src/main/java/cc/mrbird/febs/mall/quartz/WxxcxJob.java @@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.extension.exceptions.ApiException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -27,8 +28,6 @@ @Component @ConditionalOnProperty(prefix = "system", name = "job", havingValue = "true") public class WxxcxJob { - - private final XcxProperties xcxProperties = SpringContextHolder.getBean(XcxProperties.class); @Autowired private RedisUtils redisUtils; @@ -44,11 +43,16 @@ * 获取access_token * 有效期两小时 */ + @Value("${xcx.xcx_appid}") + private String xcxAppid; + // 文件保存目录URL + @Value("${xcx.xcx_secret}") + private String xcxSecret; @Scheduled(cron = "0 0 0/1 * * ? ") public void getAccessToken() throws IOException { log.info("执行access_token刷新"); - String appId = xcxProperties.getXcxAppid(); - String appSecret = xcxProperties.getXcxSecret(); + String appId = xcxAppid; + String appSecret = xcxSecret; String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret; String jsonStr = restTemplate.getForObject(url, String.class); -- Gitblit v1.9.1