广州市综治平台后端
xusd
2025-06-07 36306491396230522fa20585c2621a7fc899849a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package cn.huge.module.wechat.miniapp.service;
 
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.bean.WxMaMessage;
import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
import cn.binarywang.wx.miniapp.message.WxMaMessageRouter;
import cn.huge.module.oper.dto.SeCustWechatDTO;
import cn.huge.module.wechat.miniapp.handler.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
/**
 * @title: 小程序服务
 * @description: 小程序服务
 * @company: hugeinfo
 * @author: liyj
 * @time: 2021/02/02
 * @version: 1.0.0
 **/
@Service
public class WeixinMaService extends WxMaServiceImpl {
 
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
    private WxMaMessageRouter router;
 
    @Autowired
    private LogMaHandler logHandler;
 
    @Autowired
    private PicMaHandler picHandler;
 
    @Autowired
    private QrcodeMaHandler qrcodeHandler;
 
    @Autowired
    private TemplateMsgMaHandler templateMsgHandler;
 
    @Autowired
    private TextMaHandler textHandler;
 
//    @PostConstruct
//    public void init() {
//        final WxMaInMemoryConfig config = new WxMaInMemoryConfig();
//        config.setAppid(this.wxConfig.getAppid());// 设置微信公众号的appid
//        config.setSecret(this.wxConfig.getSecret());// 设置微信公众号的app corpSecret
//        config.setToken(this.wxConfig.getToken());// 设置微信公众号的token
//        config.setAesKey(this.wxConfig.getAesKey());// 设置消息加解密密钥
//        super.setWxMaConfig(config);
//
//        this.refreshRouter();
//    }
 
//    public void createConfig(SeCustWechatDTO seCustWechatDTO) {
//        final WxMaInMemoryConfig config = new WxMaInMemoryConfig();
//        config.setAppid(seCustWechatDTO.getAppid());// 设置微信公众号的appid
//        config.setSecret(seCustWechatDTO.getSecret());// 设置微信公众号的app corpSecret
//        config.setToken(seCustWechatDTO.getToken());// 设置微信公众号的token
//        config.setAesKey(seCustWechatDTO.getAeskey());// 设置消息加解密密钥
//        super.setWxMaConfig(config);
//
//        this.refreshRouter();
//    }
 
    public void createConfig(SeCustWechatDTO seCustWechatDTO) {
        final WxMaInMemoryConfig config = new WxMaInMemoryConfig();
        config.setAppid(seCustWechatDTO.getAppid());// 设置微信公众号的appid
        config.setSecret(seCustWechatDTO.getSecret());// 设置微信公众号的app corpSecret
        config.setToken(seCustWechatDTO.getToken());// 设置微信公众号的token
        config.setAesKey(seCustWechatDTO.getAeskey());// 设置消息加解密密钥
        super.setWxMaConfig(config);
 
        this.refreshRouter();
    }
 
    private void refreshRouter() {
        final WxMaMessageRouter newRouter = new WxMaMessageRouter(this);
 
        newRouter
                .rule().handler(logHandler).next()
                .rule().async(false).content("模板").handler(templateMsgHandler).end()
                .rule().async(false).content("文本").handler(textHandler).end()
                .rule().async(false).content("图片").handler(picHandler).end()
                .rule().async(false).content("二维码").handler(qrcodeHandler).end();
 
        this.router = newRouter;
    }
 
    public void route(WxMaMessage message) {
        try {
            this.router.route(message);
        } catch (Exception e) {
            this.logger.error(e.getMessage(), e);
        }
    }
 
    protected LogMaHandler getLogHandler(){
        return this.logHandler;
    }
 
    protected PicMaHandler getPicHandler(){
        return this.picHandler;
    }
 
    protected QrcodeMaHandler getQrcodeHandler(){
        return this.qrcodeHandler;
    }
 
    protected TemplateMsgMaHandler getTemplateMsgHandler(){
        return this.templateMsgHandler;
    }
 
    protected TextMaHandler getTextHandler(){
        return this.textHandler;
    }
}
/**
 * -------------------_ooOoo_-------------------
 * ------------------o8888888o------------------
 * ------------------88" . "88------------------
 * ------------------(| -_- |)------------------
 * ------------------O\  =  /O------------------
 * ---------------____/`---'\____---------------
 * -------------.'  \\|     |//  `.-------------
 * ------------/  \\|||  :  |||//  \------------
 * -----------/  _||||| -:- |||||-  \-----------
 * -----------|   | \\\  -  /// |   |-----------
 * -----------| \_|  ''\---/''  |   |-----------
 * -----------\  .-\__  `-`  ___/-. /-----------
 * ---------___`. .'  /--.--\  `. . __----------
 * ------."" '<  `.___\_<|>_/___.'  >'"".-------
 * -----| | :  `- \`.;`\ _ /`;.`/ - ` : | |-----
 * -----\  \ `-.   \_ __\ /__ _/   .-` /  /-----
 * ======`-.____`-.___\_____/___.-`____.-'======
 * -------------------`=---='
 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 * ---------佛祖保佑---hugeinfo---永无BUG----------
 */