From fe25b624917bce6d8f7a6153bed43e188914532b Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Tue, 23 Sep 2025 05:43:29 +0000
Subject: [PATCH] 企微通信redis锁问题修改(二次修改)

---
 eladmin-master/eladmin-system/src/main/java/me/zhengjie/config/WxCpConfig.java |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/config/WxCpConfig.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/config/WxCpConfig.java
index 12ec6dd..f6b2085 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/config/WxCpConfig.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/config/WxCpConfig.java
@@ -1,21 +1,70 @@
 package me.zhengjie.config;
 
+import com.binarywang.spring.starter.wxjava.cp.properties.WxCpProperties;
 import me.chanjar.weixin.cp.api.WxCpService;
 import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
 import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
+import me.chanjar.weixin.cp.config.impl.WxCpRedisTemplateConfigImpl;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.core.StringRedisTemplate;
 
 /**
  * @author baoLh
  * @date 2025-09-22
  */
 @Configuration
+@EnableConfigurationProperties(WxCpProperties.class)
 public class WxCpConfig {
+
+    private final WxCpProperties wxCpProperties;
+    private final ApplicationContext applicationContext;
+
+    public WxCpConfig(WxCpProperties wxCpProperties, ApplicationContext applicationContext) {
+        this.wxCpProperties = wxCpProperties;
+        this.applicationContext = applicationContext;
+    }
 
     @Bean
     public WxCpService wxCpService() {
-        WxCpDefaultConfigImpl configStorage = new WxCpDefaultConfigImpl();
+//        // 默认缓存配置
+//        WxCpDefaultConfigImpl configStorage = new WxCpDefaultConfigImpl();
+
+        // redis缓存配置
+        StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
+        WxCpDefaultConfigImpl configStorage = new WxCpRedisTemplateConfigImpl(redisTemplate, wxCpProperties.getConfigStorage().getKeyPrefix());
+        configStorage.setCorpId(wxCpProperties.getCorpId());
+        configStorage.setAgentId(wxCpProperties.getAgentId());
+        configStorage.setCorpSecret(wxCpProperties.getCorpSecret());
+        if (StringUtils.isNotBlank(wxCpProperties.getToken())) {
+            configStorage.setToken(wxCpProperties.getToken());
+        }
+        if (StringUtils.isNotBlank(wxCpProperties.getAesKey())) {
+            configStorage.setAesKey(wxCpProperties.getAesKey());
+        }
+        if (StringUtils.isNotBlank(wxCpProperties.getMsgAuditPriKey())) {
+            configStorage.setMsgAuditPriKey(wxCpProperties.getMsgAuditPriKey());
+        }
+        if (StringUtils.isNotBlank(wxCpProperties.getMsgAuditLibPath())) {
+            configStorage.setMsgAuditLibPath(wxCpProperties.getMsgAuditLibPath());
+        }
+
+        WxCpProperties.ConfigStorage storage = wxCpProperties.getConfigStorage();
+        if (StringUtils.isNotBlank(storage.getHttpProxyHost())) {
+            configStorage.setHttpProxyHost(storage.getHttpProxyHost());
+            if (storage.getHttpProxyPort() != null) {
+                configStorage.setHttpProxyPort(storage.getHttpProxyPort());
+            }
+            if (StringUtils.isNotBlank(storage.getHttpProxyUsername())) {
+                configStorage.setHttpProxyUsername(storage.getHttpProxyUsername());
+            }
+            if (StringUtils.isNotBlank(storage.getHttpProxyPassword())) {
+                configStorage.setHttpProxyPassword(storage.getHttpProxyPassword());
+            }
+        }
 
         WxCpService wxCpService = new WxCpServiceImpl();
         wxCpService.setWxCpConfigStorage(configStorage);

--
Gitblit v1.9.3