From 20e0c1036ebc6d558e57644b770b9c9de8bcf383 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Thu, 23 Jan 2025 14:16:39 +0800
Subject: [PATCH] refactor(mall): 重构商品相关操作的验证逻辑
---
src/main/java/cc/mrbird/febs/mall/quartz/WxxcxJob.java | 69 +++++++++++++++++++---------------
1 files changed, 39 insertions(+), 30 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 2609206..09959ed 100644
--- a/src/main/java/cc/mrbird/febs/mall/quartz/WxxcxJob.java
+++ b/src/main/java/cc/mrbird/febs/mall/quartz/WxxcxJob.java
@@ -6,24 +6,28 @@
import cc.mrbird.febs.mall.entity.MallMemberCoupon;
import cc.mrbird.febs.mall.mapper.MallMemberCouponMapper;
import cc.mrbird.febs.mall.service.MallInvoiceService;
+import cc.mrbird.febs.pay.util.WechatConfigure;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONObject;
+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;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
+import java.io.IOException;
import java.util.List;
@Slf4j
@Component
@ConditionalOnProperty(prefix = "system", name = "job", havingValue = "true")
public class WxxcxJob {
-
- private final XcxProperties xcxProperties = SpringContextHolder.getBean(XcxProperties.class);
@Autowired
private RedisUtils redisUtils;
@@ -39,34 +43,39 @@
* 获取access_token
* 有效期两小时
*/
-// @Scheduled(cron = "0 0 0/1 * * ? ")
-// public void getAccessToken() throws IOException {
-// log.info("执行access_token刷新");
-// String appId = xcxProperties.getXcxAppid();
-// String appSecret = xcxProperties.getXcxSecret();
-// 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);
-//
-// /**
-// * 返回结果
-// * {"access_token":"ACCESS_TOKEN","expires_in":7200}
-// */
-// if (!jsonStr.contains("access_token")) {
-// System.out.println("获取微信access_token失败");
-// }
-//
-// String accessTokenKey = WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY;
-// JSONObject jsonObject = JSONObject.parseObject(jsonStr);
-// String accessToken = jsonObject.getString(accessTokenKey);
-// if (StrUtil.isEmpty(accessToken)) {
-// log.error("获取access token失败: {}" , jsonObject.getString("errmsg"));
-// throw new ApiException("获取access token失败");
-// } else {
-// log.info("wx access_token : {}",accessToken);
-// redisUtils.set(accessTokenKey,accessToken);
-// }
-//
-// }
+ @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 = 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);
+
+ /**
+ * 返回结果
+ * {"access_token":"ACCESS_TOKEN","expires_in":7200}
+ */
+ if (!jsonStr.contains("access_token")) {
+ System.out.println("获取微信access_token失败");
+ }
+
+ String accessTokenKey = WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY;
+ JSONObject jsonObject = JSONObject.parseObject(jsonStr);
+ String accessToken = jsonObject.getString(accessTokenKey);
+ if (StrUtil.isEmpty(accessToken)) {
+ log.error("获取access token失败: {}" , jsonObject.getString("errmsg"));
+ throw new ApiException("获取access token失败");
+ } else {
+ log.info("wx access_token : {}",accessToken);
+ redisUtils.set(accessTokenKey,accessToken);
+ }
+
+ }
@Scheduled(cron = "0 0 0/1 * * ? ")
public void expireCoupon() {
--
Gitblit v1.9.1