File tree Expand file tree Collapse file tree 4 files changed +49
-8
lines changed
java/com/github/binarywang/demo/wx/mp/config Expand file tree Collapse file tree 4 files changed +49
-8
lines changed Original file line number Diff line number Diff line change 43
43
```
44
44
wx:
45
45
mp:
46
+ useRedis: false
47
+ redisConfig:
48
+ host: 127.0.0.1
49
+ port: 6379
46
50
configs:
47
- - appId: 1111 (一个公众号的appid)
48
- secret: 1111( 公众号的appsecret)
49
- token: 111 ( 接口配置里的Token值)
50
- aesKey: 111 ( 接口配置里的EncodingAESKey值)
51
- - appId: 2222 (另一个公众号的appid ,以下同上)
51
+ - appId: 1111 # 第一个公众号的appid
52
+ secret: 1111 # 公众号的appsecret
53
+ token: 111 # 接口配置里的Token值
54
+ aesKey: 111 # 接口配置里的EncodingAESKey值
55
+ - appId: 2222 # 第二个公众号的appid ,以下同上
52
56
secret: 1111
53
57
token: 111
54
58
aesKey: 111
59
+
55
60
```
56
61
3 . 运行Java程序:` WxMpDemoApplication ` ;
57
62
4 . 配置微信公众号中的接口地址:http://公网可访问域名/wx/portal/xxxxx (注意,xxxxx为对应公众号的appid值);
Original file line number Diff line number Diff line change @@ -56,9 +56,15 @@ public WxMpService wxMpService() {
56
56
WxMpService service = new WxMpServiceImpl ();
57
57
service .setMultiConfigStorages (configs
58
58
.stream ().map (a -> {
59
- // WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
60
- WxMpDefaultConfigImpl configStorage = new WxMpRedisConfigImpl (new JedisWxRedisOps (new JedisPool ("redisServer" )),
61
- a .getAppId ());
59
+ WxMpDefaultConfigImpl configStorage ;
60
+ if (this .properties .isUseRedis ()) {
61
+ final WxMpProperties .RedisConfig redisConfig = this .properties .getRedisConfig ();
62
+ JedisPool jedisPool = new JedisPool (redisConfig .getHost (), redisConfig .getPort ());
63
+ configStorage = new WxMpRedisConfigImpl (new JedisWxRedisOps (jedisPool ), a .getAppId ());
64
+ } else {
65
+ configStorage = new WxMpDefaultConfigImpl ();
66
+ }
67
+
62
68
configStorage .setAppId (a .getAppId ());
63
69
configStorage .setSecret (a .getSecret ());
64
70
configStorage .setToken (a .getToken ());
Original file line number Diff line number Diff line change 14
14
@ Data
15
15
@ ConfigurationProperties (prefix = "wx.mp" )
16
16
public class WxMpProperties {
17
+ /**
18
+ * 是否使用redis存储access token
19
+ */
20
+ private boolean useRedis ;
21
+
22
+ /**
23
+ * redis 配置
24
+ */
25
+ private RedisConfig redisConfig ;
26
+
27
+ @ Data
28
+ public static class RedisConfig {
29
+ /**
30
+ * redis服务器 主机地址
31
+ */
32
+ private String host ;
33
+
34
+ /**
35
+ * redis服务器 端口号
36
+ */
37
+ private Integer port ;
38
+ }
39
+
40
+ /**
41
+ * 多个公众号配置信息
42
+ */
17
43
private List <MpConfig > configs ;
18
44
19
45
@ Data
Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ logging:
5
5
me.chanjar.weixin: DEBUG
6
6
wx:
7
7
mp:
8
+ useRedis: false
9
+ redisConfig:
10
+ host: 127.0.0.1
11
+ port: 6379
8
12
configs:
9
13
- appId: 1111 # 第一个公众号的appid
10
14
secret: 1111 # 公众号的appsecret
You can’t perform that action at this time.
0 commit comments