|
@@ -0,0 +1,36 @@
|
|
1
|
+package com.yunzhi.liyuanhui.common;
|
|
2
|
+
|
|
3
|
+import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
4
|
+import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
|
5
|
+import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
|
6
|
+import com.yunzhi.liyuanhui.config.WeixinConfig;
|
|
7
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
8
|
+import org.springframework.stereotype.Component;
|
|
9
|
+
|
|
10
|
+@Component
|
|
11
|
+public class WxUtils {
|
|
12
|
+ @Autowired
|
|
13
|
+ private WeixinConfig config;
|
|
14
|
+
|
|
15
|
+ private static WxMaService service;
|
|
16
|
+
|
|
17
|
+ public WxUtils() {
|
|
18
|
+ setService(config);
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ private void setService(WeixinConfig config) {
|
|
22
|
+ WxMaDefaultConfigImpl conf = new WxMaDefaultConfigImpl();
|
|
23
|
+ conf.setAppid(config.getMiniapp().getAppid());
|
|
24
|
+ conf.setSecret(config.getMiniapp().getSecret());
|
|
25
|
+ conf.setToken(config.getMiniapp().getToken());
|
|
26
|
+ conf.setAesKey(config.getMiniapp().getAesKey());
|
|
27
|
+ conf.setMsgDataFormat(config.getMiniapp().getMsgDataFormat());
|
|
28
|
+
|
|
29
|
+ WxMaService service = new WxMaServiceImpl();
|
|
30
|
+ service.setWxMaConfig(conf);
|
|
31
|
+ }
|
|
32
|
+
|
|
33
|
+ public WxMaService getService() {
|
|
34
|
+ return service;
|
|
35
|
+ }
|
|
36
|
+}
|