Просмотр исходного кода

[公众号消息][修改]:第三方平台api处理公众号消息

release
Stormeye Wu 7 лет назад
Родитель
Сommit
1c10d307b7
2 измененных файлов: 51 добавлений и 62 удалений
  1. +1
    -15
      mlWechatOpen/src/main/java/com/iformall/controller/WechatCalllbackController.java
  2. +50
    -47
      mlWechatOpen/src/main/java/com/iformall/mp/manager/WxMpManager.java

+ 1
- 15
mlWechatOpen/src/main/java/com/iformall/controller/WechatCalllbackController.java Просмотреть файл

@@ -7,7 +7,6 @@ import com.iformall.common.ResultData;
import com.iformall.domain.po.*;
import com.iformall.enums.*;
import com.iformall.mp.manager.WxMpManager;
import com.iformall.mp.utils.MpUtil;
import com.iformall.service.*;
import com.iformall.service.wechat.WxOpenService;
import io.swagger.annotations.Api;
@@ -86,19 +85,6 @@ public class WechatCalllbackController extends BaseController {
String encType = request.getParameter("encrypt_type");
String msgSignature = request.getParameter("msg_signature");

/*
// 测试数据
String timestamp = "1545708083";
String nonce = "1052028699";
String signature = "b5fa8296b46c726cbed35f744944f20f682776a6";
String encType = "aes";
String msgSignature= "54bec4c513f447cb312fd091bea48326f87aedde";

String resultxml = "<xml>\n" +
" <AppId><![CDATA[wx897e4673286c915d]]></AppId>\n" +
" <Encrypt><![CDATA[92gl+PCgxooLh85YZ74VX8gNPV3tq2w8br4tuBl2UIc9uJuJiSNBgohFxgS7tRXSMUtr5t+75MiLKlaMKvv4FH5iF3WdYbxjF6ojnA1+MBzD7mf9fo6KkWUdDq+1V0OtrooP4s8iuAC0Lx3elCtWUZXYGnCeP5Y/2A8ZZBwpvcBz73d7n2Kv8QVvLsw2dmrej1b8KGdmRAEbm/oYoVthlAkmoTTAAx+Gj10XTMem1wp1vT/a0mGxN88oJxNZoHdFvAbmc24A7VD4i5VDOt9FqwerqlGXnBX5pBAmOx8ZUsndM8yuf3I54GE9hEPRvdWBiyLb96Lb8ZnjEBlvc9kvs7PpFOSQhkbGMNQKWGW1os8UImr7O3+IiKLuBv2G1pJBb2/kIeZn5v9NuxYLOsXQmb2XijHYMXwCNHCI3Eji22k9XDiiuK1miHlUuL8Gz8X7lN9JuVcE24jd7Ty4H0pThQ==]]></Encrypt>\n" +
"</xml>";
*/
logger.info("\n接收微信回调:[signature=[{}], encType=[{}], msgSignature=[{}],"
+ " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ",
signature, encType, msgSignature, timestamp, nonce, resultxml);
@@ -267,7 +253,7 @@ public class WechatCalllbackController extends BaseController {
}
} else {
// 公众号
WxMpService mpService = MpUtil.getMpService(appinfo);
WxMpService mpService = openService.getWxOpenComponentService().getWxMpServiceByAppid(appId);
try {
WxMpXmlOutMessage outMessage = mpManager.getRouter(mpService).route(inMessage);
if (outMessage == null) {


+ 50
- 47
mlWechatOpen/src/main/java/com/iformall/mp/manager/WxMpManager.java Просмотреть файл

@@ -1,9 +1,8 @@
package com.iformall.mp.manager;

import com.iformall.domain.po.WxAppinfo;
import com.iformall.mp.handler.*;
import com.iformall.mp.utils.MpUtil;
import com.iformall.service.WxAppinfoService;
import com.iformall.service.wechat.WxOpenService;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.constant.WxMpEventConstants;
@@ -15,11 +14,15 @@ import static me.chanjar.weixin.common.api.WxConsts.*;
/**
* wechat mp configuration
*
* @author Binary Wang(https://github.com/binarywang)
* @author Stormeye
*/
@Service
public class WxMpManager {


@Autowired
protected WxOpenService openService;

@Autowired
private WxAppinfoService appinfoService;
@Autowired
@@ -42,20 +45,7 @@ public class WxMpManager {
private SubscribeHandler subscribeHandler;

public WxMpService getMpService(String appId) {
WxAppinfo appinfo = appinfoService.getByAppId(appId);
if(appinfo == null) {
return null;
}
WxMpService mpService = MpUtil.getMpService(appinfo);
return mpService;
}

public WxMpMessageRouter getRouter(WxAppinfo appinfo) {
WxMpService mpService = MpUtil.getMpService(appinfo);
if(mpService != null) {
return newRouter(mpService);
}
return null;
return openService.getWxOpenComponentService().getWxMpServiceByAppid(appId);
}

public WxMpMessageRouter getRouter(WxMpService mpService) {
@@ -69,52 +59,65 @@ public class WxMpManager {
newRouter.rule().handler(this.logHandler).next();

// 接收客服会话管理事件
newRouter.rule().async(false).msgType(XmlMsgType.EVENT)
.event(WxMpEventConstants.CustomerService.KF_CREATE_SESSION)
.handler(this.kfSessionHandler).end();
newRouter.rule().async(false).msgType(XmlMsgType.EVENT)
.event(WxMpEventConstants.CustomerService.KF_CLOSE_SESSION)
.handler(this.kfSessionHandler)
.end();
newRouter.rule().async(false).msgType(XmlMsgType.EVENT)
.event(WxMpEventConstants.CustomerService.KF_SWITCH_SESSION)
.handler(this.kfSessionHandler).end();
newRouter.rule().async(false)
.msgType(XmlMsgType.EVENT)
.event(WxMpEventConstants.CustomerService.KF_CREATE_SESSION)
.handler(this.kfSessionHandler).end();
newRouter.rule().async(false)
.msgType(XmlMsgType.EVENT)
.event(WxMpEventConstants.CustomerService.KF_CLOSE_SESSION)
.handler(this.kfSessionHandler).end();
newRouter.rule().async(false)
.msgType(XmlMsgType.EVENT)
.event(WxMpEventConstants.CustomerService.KF_SWITCH_SESSION)
.handler(this.kfSessionHandler).end();

// 门店审核事件
newRouter.rule().async(false).msgType(XmlMsgType.EVENT)
.event(WxMpEventConstants.POI_CHECK_NOTIFY)
.handler(this.storeCheckNotifyHandler).end();
newRouter.rule().async(false)
.msgType(XmlMsgType.EVENT)
.event(WxMpEventConstants.POI_CHECK_NOTIFY)
.handler(this.storeCheckNotifyHandler).end();

// 自定义菜单事件
newRouter.rule().async(false).msgType(XmlMsgType.EVENT)
.event(MenuButtonType.CLICK).handler(this.menuHandler).end();
newRouter.rule().async(false)
.msgType(XmlMsgType.EVENT)
.event(MenuButtonType.CLICK)
.handler(this.menuHandler).end();

// 点击菜单连接事件
newRouter.rule().async(false).msgType(XmlMsgType.EVENT)
.event(MenuButtonType.VIEW).handler(this.nullHandler).end();
newRouter.rule().async(false)
.msgType(XmlMsgType.EVENT)
.event(MenuButtonType.VIEW)
.handler(this.nullHandler).end();

// 关注事件
newRouter.rule().async(false).msgType(XmlMsgType.EVENT)
.event(EventType.SUBSCRIBE).handler(this.subscribeHandler)
.end();
newRouter.rule().async(false)
.msgType(XmlMsgType.EVENT)
.event(EventType.SUBSCRIBE)
.handler(this.subscribeHandler).end();

// 取消关注事件
newRouter.rule().async(false).msgType(XmlMsgType.EVENT)
.event(EventType.UNSUBSCRIBE)
.handler(this.unsubscribeHandler).end();
newRouter.rule().async(false)
.msgType(XmlMsgType.EVENT)
.event(EventType.UNSUBSCRIBE)
.handler(this.unsubscribeHandler).end();

// 上报地理位置事件
newRouter.rule().async(false).msgType(XmlMsgType.EVENT)
.event(EventType.LOCATION).handler(this.locationHandler)
.end();
newRouter.rule().async(false)
.msgType(XmlMsgType.EVENT)
.event(EventType.LOCATION)
.handler(this.locationHandler).end();

// 接收地理位置消息
newRouter.rule().async(false).msgType(XmlMsgType.LOCATION)
.handler(this.locationHandler).end();
newRouter.rule().async(false)
.msgType(XmlMsgType.LOCATION)
.handler(this.locationHandler).end();

// 扫码事件
newRouter.rule().async(false).msgType(XmlMsgType.EVENT)
.event(EventType.SCAN).handler(this.nullHandler).end();
newRouter.rule().async(false)
.msgType(XmlMsgType.EVENT)
.event(EventType.SCAN)
.handler(this.nullHandler).end();

// 默认
newRouter.rule().async(false).handler(this.msgHandler).end();


Загрузка…
Отмена
Сохранить