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

🔖 2.1.0

上级 1a7ac2b7
...@@ -20,7 +20,7 @@ jfinal weixin 的 spring boot starter,这个starter是为了方便boot用户 ...@@ -20,7 +20,7 @@ jfinal weixin 的 spring boot starter,这个starter是为了方便boot用户
<dependency> <dependency>
<groupId>net.dreamlu</groupId> <groupId>net.dreamlu</groupId>
<artifactId>mica-weixin</artifactId> <artifactId>mica-weixin</artifactId>
<version>2.0.6</version> <version>2.1.0</version>
</dependency> </dependency>
``` ```
...@@ -39,6 +39,9 @@ jfinal weixin 的 spring boot starter,这个starter是为了方便boot用户 ...@@ -39,6 +39,9 @@ jfinal weixin 的 spring boot starter,这个starter是为了方便boot用户
### Api ### Api
- 类添加`@WxApi`,注解value为你的消息地址,使用/weixin/api,已经组合[@RequestMapping和@Controller] - 类添加`@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: ...@@ -71,7 +74,11 @@ dream:
- `access-token-cache`建议配置有效时间7100秒。 - `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。 - 升级 jfinal-weixin 到 3.0。
### 2020-12-16 2.0.5 ### 2020-12-16 2.0.5
......
...@@ -33,13 +33,19 @@ ...@@ -33,13 +33,19 @@
<dependency> <dependency>
<groupId>net.dreamlu</groupId> <groupId>net.dreamlu</groupId>
<artifactId>mica-weixin</artifactId> <artifactId>mica-weixin</artifactId>
<version>2.0.6</version> <version>2.1.0</version>
</dependency> </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>--> <!-- <dependency>-->
<!-- <groupId>net.dreamlu</groupId>--> <!-- <groupId>net.dreamlu</groupId>-->
<!-- <artifactId>mica-redis</artifactId>--> <!-- <artifactId>mica-redis</artifactId>-->
<!-- <version>2.4.3-GA</version>--> <!-- <version>2.4.5-GA</version>-->
<!-- </dependency>--> <!-- </dependency>-->
</dependencies> </dependencies>
......
...@@ -5,10 +5,10 @@ ext { ...@@ -5,10 +5,10 @@ ext {
javaVersion = JavaVersion.VERSION_1_8 javaVersion = JavaVersion.VERSION_1_8
springBootVersion = "2.4.4" springBootVersion = "2.4.4"
jfinalVersion = "4.9.08" jfinalVersion = "4.9.08"
jfinalWeixinVersion = "3.0" jfinalWeixinVersion = "3.1"
okhttpVersion = "3.14.9" okhttpVersion = "3.14.9"
micaAutoVersion = "2.0.4" micaAutoVersion = "2.0.4"
lombokVersion = "1.18.18" lombokVersion = "1.18.20"
} }
allprojects { allprojects {
......
VERSION=2.0.6 VERSION=2.1.0
GROUPID=net.dreamlu GROUPID=net.dreamlu
userName=chunmeng userName=chunmeng
......
...@@ -2,7 +2,11 @@ package net.dreamlu.weixin.cache; ...@@ -2,7 +2,11 @@ package net.dreamlu.weixin.cache;
import com.jfinal.weixin.sdk.cache.IAccessTokenCache; import com.jfinal.weixin.sdk.cache.IAccessTokenCache;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.dreamlu.weixin.properties.DreamWeixinProperties;
import org.springframework.cache.Cache; import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import java.util.Objects;
/** /**
* 基于 spring cache 的 weixin token 缓存 * 基于 spring cache 的 weixin token 缓存
...@@ -12,20 +16,28 @@ import org.springframework.cache.Cache; ...@@ -12,20 +16,28 @@ import org.springframework.cache.Cache;
@RequiredArgsConstructor @RequiredArgsConstructor
public class SpringAccessTokenCache implements IAccessTokenCache { public class SpringAccessTokenCache implements IAccessTokenCache {
private final static String ACCESS_TOKEN_PREFIX = "dream-weixin:token:"; private final static String ACCESS_TOKEN_PREFIX = "dream-weixin:token:";
private final Cache cache; private final CacheManager cacheManager;
private final DreamWeixinProperties properties;
@Override @Override
public String get(String key) { public String get(String key) {
return cache.get(ACCESS_TOKEN_PREFIX + key, String.class); return getCache().get(ACCESS_TOKEN_PREFIX + key, String.class);
} }
@Override @Override
public void set(String key, String jsonValue) { public void set(String key, String jsonValue) {
cache.put(ACCESS_TOKEN_PREFIX + key, jsonValue); getCache().put(ACCESS_TOKEN_PREFIX + key, jsonValue);
} }
@Override @Override
public void remove(String key) { 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; ...@@ -5,7 +5,6 @@ import net.dreamlu.weixin.cache.SpringAccessTokenCache;
import net.dreamlu.weixin.properties.DreamWeixinProperties; import net.dreamlu.weixin.properties.DreamWeixinProperties;
import net.dreamlu.weixin.spring.MsgInterceptor; import net.dreamlu.weixin.spring.MsgInterceptor;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -26,8 +25,7 @@ public class DreamWeixinAutoConfiguration { ...@@ -26,8 +25,7 @@ public class DreamWeixinAutoConfiguration {
@Bean @Bean
public SpringAccessTokenCache springAccessTokenCache(CacheManager cacheManager, public SpringAccessTokenCache springAccessTokenCache(CacheManager cacheManager,
DreamWeixinProperties properties) { DreamWeixinProperties properties) {
Cache cache = cacheManager.getCache(properties.getAccessTokenCache()); return new SpringAccessTokenCache(cacheManager, properties);
return new SpringAccessTokenCache(cache);
} }
@Configuration @Configuration
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册