From 08c514a901b0e7e1661c41f4472cbac08051a5c1 Mon Sep 17 00:00:00 2001
From: yao-zengchun <yao-zengchun@smhc.co.jp>
Date: Tue, 11 Nov 2025 09:53:23 +0000
Subject: [PATCH] Merge branch 'wcd' of http://192.168.1.110:5678/r/pms-upgrade into wcd
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/config/WxCpConfig.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 48 insertions(+), 5 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 f6b2085..e7ebc17 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,9 +1,11 @@
package me.zhengjie.config;
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpProperties;
+import com.binarywang.spring.starter.wxjava.cp.properties.WxCpRedisProperties;
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.WxCpJedisConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpRedisTemplateConfigImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -11,6 +13,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
/**
* @author baoLh
@@ -30,12 +34,27 @@
@Bean
public WxCpService wxCpService() {
-// // 默认缓存配置
-// WxCpDefaultConfigImpl configStorage = new WxCpDefaultConfigImpl();
+ WxCpDefaultConfigImpl configStorage;
+ if (wxCpProperties.getConfigStorage().getType().equals(WxCpProperties.StorageType.redistemplate)) {
+ // redis缓存配置
+ StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
+ configStorage = new WxCpRedisTemplateConfigImpl(redisTemplate, wxCpProperties.getConfigStorage().getKeyPrefix());
+ } else if (wxCpProperties.getConfigStorage().getType().equals(WxCpProperties.StorageType.jedis)) {
+ // jedis配置
+ WxCpRedisProperties wxCpRedisProperties = wxCpProperties.getConfigStorage().getRedis();
+ JedisPool jedisPool;
+ if (wxCpRedisProperties != null && StringUtils.isNotEmpty(wxCpRedisProperties.getHost())) {
+ jedisPool = getJedisPool();
+ } else {
+ jedisPool = applicationContext.getBean(JedisPool.class);
+ }
+ configStorage = new WxCpJedisConfigImpl(jedisPool, wxCpProperties.getConfigStorage().getKeyPrefix());
+ } else {
+ // 默认缓存配置
+ 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());
@@ -71,4 +90,28 @@
return wxCpService;
}
+
+ private JedisPool getJedisPool() {
+ WxCpProperties.ConfigStorage storage = wxCpProperties.getConfigStorage();
+ WxCpRedisProperties redis = storage.getRedis();
+
+ JedisPoolConfig config = new JedisPoolConfig();
+ if (redis.getMaxActive() != null) {
+ config.setMaxTotal(redis.getMaxActive());
+ }
+ if (redis.getMaxIdle() != null) {
+ config.setMaxIdle(redis.getMaxIdle());
+ }
+ if (redis.getMaxWaitMillis() != null) {
+ config.setMaxWaitMillis(redis.getMaxWaitMillis());
+ }
+ if (redis.getMinIdle() != null) {
+ config.setMinIdle(redis.getMinIdle());
+ }
+ config.setTestOnBorrow(true);
+ config.setTestWhileIdle(true);
+
+ return new JedisPool(config, redis.getHost(), redis.getPort(),
+ redis.getTimeout(), redis.getPassword(), redis.getDatabase());
+ }
}
--
Gitblit v1.9.3