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----------
|
*/
|