提交 afb5f427 编写于 作者: 如梦技术's avatar 如梦技术 🐛

🔖 2.1.0

上级 1a7ac2b7
......@@ -20,7 +20,7 @@ jfinal weixin 的 spring boot starter,这个starter是为了方便boot用户
<dependency>
<groupId>net.dreamlu</groupId>
<artifactId>mica-weixin</artifactId>
<version>2.0.6</version>
<version>2.1.0</version>
</dependency>
```
......@@ -39,6 +39,9 @@ jfinal weixin 的 spring boot starter,这个starter是为了方便boot用户
### Api
- 类添加`@WxApi`,注解value为你的消息地址,使用/weixin/api,已经组合[@RequestMapping和@Controller]
### access token cache
您可以配置 [mica-caffeine](https://gitee.com/596392912/mica/tree/master/mica-caffeine)[mica-redis](https://gitee.com/596392912/mica/tree/master/mica-redis) 实现 access token 的缓存。
### 配置
| 配置项 | 默认值 | 说明 |
| ----- | ------ | ------ |
......@@ -71,7 +74,11 @@ dream:
- `access-token-cache`建议配置有效时间7100秒。
## 更新说明
### 2020-12-16 2.0.6
### 2021-04-27 2.1.0
- Spring cache 对象改为每次读取, caffeine 会刷新,照成引用为 null。
- 升级 jfinal-weixin 到 3.1。
### 2020-03-20 2.0.6
- 升级 jfinal-weixin 到 3.0。
### 2020-12-16 2.0.5
......
......@@ -33,13 +33,19 @@
<dependency>
<groupId>net.dreamlu</groupId>
<artifactId>mica-weixin</artifactId>
<version>2.0.6</version>
<version>2.1.0</version>
</dependency>
<!-- redis 存储 weixin,可选依赖,对 Spring boot 有版本兼容,需要自行选择合适的版本 -->
<!-- caffeine 存储 weixin token,可选依赖,对 Spring boot 有版本兼容,需要自行选择合适的版本 -->
<!-- <dependency>-->
<!-- <groupId>net.dreamlu</groupId>-->
<!-- <artifactId>mica-caffeine</artifactId>-->
<!-- <version>2.4.5-GA</version>-->
<!-- </dependency>-->
<!-- redis 存储 weixin token,可选依赖,对 Spring boot 有版本兼容,需要自行选择合适的版本 -->
<!-- <dependency>-->
<!-- <groupId>net.dreamlu</groupId>-->
<!-- <artifactId>mica-redis</artifactId>-->
<!-- <version>2.4.3-GA</version>-->
<!-- <version>2.4.5-GA</version>-->
<!-- </dependency>-->
</dependencies>
......
......@@ -5,10 +5,10 @@ ext {
javaVersion = JavaVersion.VERSION_1_8
springBootVersion = "2.4.4"
jfinalVersion = "4.9.08"
jfinalWeixinVersion = "3.0"
jfinalWeixinVersion = "3.1"
okhttpVersion = "3.14.9"
micaAutoVersion = "2.0.4"
lombokVersion = "1.18.18"
lombokVersion = "1.18.20"
}
allprojects {
......
VERSION=2.0.6
VERSION=2.1.0
GROUPID=net.dreamlu
userName=chunmeng
......
......@@ -2,7 +2,11 @@ package net.dreamlu.weixin.cache;
import com.jfinal.weixin.sdk.cache.IAccessTokenCache;
import lombok.RequiredArgsConstructor;
import net.dreamlu.weixin.properties.DreamWeixinProperties;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import java.util.Objects;
/**
* 基于 spring cache 的 weixin token 缓存
......@@ -12,20 +16,28 @@ import org.springframework.cache.Cache;
@RequiredArgsConstructor
public class SpringAccessTokenCache implements IAccessTokenCache {
private final static String ACCESS_TOKEN_PREFIX = "dream-weixin:token:";
private final Cache cache;
private final CacheManager cacheManager;
private final DreamWeixinProperties properties;
@Override
public String get(String key) {
return cache.get(ACCESS_TOKEN_PREFIX + key, String.class);
return getCache().get(ACCESS_TOKEN_PREFIX + key, String.class);
}
@Override
public void set(String key, String jsonValue) {
cache.put(ACCESS_TOKEN_PREFIX + key, jsonValue);
getCache().put(ACCESS_TOKEN_PREFIX + key, jsonValue);
}
@Override
public void remove(String key) {
cache.evict(ACCESS_TOKEN_PREFIX + key);
getCache().evict(ACCESS_TOKEN_PREFIX + key);
}
private Cache getCache() {
String accessTokenCacheName = properties.getAccessTokenCache();
Cache cache = cacheManager.getCache(accessTokenCacheName);
return Objects.requireNonNull(cache, "AccessToken cache is null.");
}
}
......@@ -5,7 +5,6 @@ import net.dreamlu.weixin.cache.SpringAccessTokenCache;
import net.dreamlu.weixin.properties.DreamWeixinProperties;
import net.dreamlu.weixin.spring.MsgInterceptor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
......@@ -26,8 +25,7 @@ public class DreamWeixinAutoConfiguration {
@Bean
public SpringAccessTokenCache springAccessTokenCache(CacheManager cacheManager,
DreamWeixinProperties properties) {
Cache cache = cacheManager.getCache(properties.getAccessTokenCache());
return new SpringAccessTokenCache(cache);
return new SpringAccessTokenCache(cacheManager, properties);
}
@Configuration
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册