| @@ -6,16 +6,14 @@ import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mp.service.WxMpManager; | |||
| 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; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.mp.api.WxMpMessageRouter; | |||
| import me.chanjar.weixin.mp.api.WxMpService; | |||
| import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
| import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; | |||
| import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; | |||
| import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | |||
| @@ -37,7 +35,6 @@ import java.io.InputStream; | |||
| import java.nio.charset.Charset; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Controller | |||
| @RequestMapping("/wxOpen") | |||
| @@ -1,7 +1,7 @@ | |||
| package com.iformall.mp.controller; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.mp.service.WxMpManager; | |||
| import com.iformall.mp.manager.WxMpManager; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.mp.api.WxMpService; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||
| @@ -1,6 +1,6 @@ | |||
| package com.iformall.mp.controller; | |||
| import com.iformall.mp.service.WxMpManager; | |||
| import com.iformall.mp.manager.WxMpManager; | |||
| import me.chanjar.weixin.common.api.WxConsts; | |||
| import me.chanjar.weixin.common.bean.menu.WxMenu; | |||
| import me.chanjar.weixin.common.bean.menu.WxMenuButton; | |||
| @@ -1,6 +1,6 @@ | |||
| package com.iformall.mp.controller; | |||
| import com.iformall.mp.service.WxMpManager; | |||
| import com.iformall.mp.manager.WxMpManager; | |||
| import me.chanjar.weixin.mp.api.WxMpService; | |||
| import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; | |||
| import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; | |||
| @@ -1,6 +1,7 @@ | |||
| package com.iformall.mp.controller; | |||
| import com.iformall.mp.service.WxMpManager; | |||
| import com.iformall.mp.manager.WxMpManager; | |||
| import com.iformall.mp.utils.MpUtil; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.mp.api.WxMpService; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||
| @@ -18,7 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam; | |||
| * @author Stormeye | |||
| */ | |||
| @Controller | |||
| @RequestMapping("/wx/redirect/{account}") | |||
| @RequestMapping("/wx/redirect/{appId}") | |||
| public class WxRedirectController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @@ -27,9 +28,9 @@ public class WxRedirectController { | |||
| @RequestMapping("/greet") | |||
| public String greetUser(@PathVariable String account, @RequestParam String code, ModelMap map) { | |||
| public String greetUser(@PathVariable String appId, @RequestParam String code, ModelMap map) { | |||
| WxMpService mpService = wxMpManager.getMpService(account); | |||
| WxMpService mpService = wxMpManager.getMpService(appId); | |||
| try { | |||
| WxMpOAuth2AccessToken accessToken = mpService.oauth2getAccessToken(code); | |||
| @@ -41,6 +41,15 @@ public class WxMpManager { | |||
| @Autowired | |||
| 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) { | |||
| @@ -1,123 +0,0 @@ | |||
| package com.iformall.mp.service; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.mp.handler.*; | |||
| import com.iformall.mp.utils.MpUtil; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import me.chanjar.weixin.mp.api.WxMpMessageRouter; | |||
| import me.chanjar.weixin.mp.api.WxMpService; | |||
| import me.chanjar.weixin.mp.constant.WxMpEventConstants; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import static me.chanjar.weixin.common.api.WxConsts.*; | |||
| /** | |||
| * wechat mp configuration | |||
| * | |||
| * @author Binary Wang(https://github.com/binarywang) | |||
| */ | |||
| @Service | |||
| public class WxMpManager { | |||
| @Autowired | |||
| private WxAppinfoService appinfoService; | |||
| @Autowired | |||
| private LogHandler logHandler; | |||
| @Autowired | |||
| private NullHandler nullHandler; | |||
| @Autowired | |||
| private KfSessionHandler kfSessionHandler; | |||
| @Autowired | |||
| private StoreCheckNotifyHandler storeCheckNotifyHandler; | |||
| @Autowired | |||
| private LocationHandler locationHandler; | |||
| @Autowired | |||
| private MenuHandler menuHandler; | |||
| @Autowired | |||
| private MsgHandler msgHandler; | |||
| @Autowired | |||
| private UnsubscribeHandler unsubscribeHandler; | |||
| @Autowired | |||
| private SubscribeHandler subscribeHandler; | |||
| public WxMpMessageRouter getRouter(String appId) { | |||
| WxMpService mpService = getMpService(appId); | |||
| if(mpService != null) { | |||
| return newRouter(mpService); | |||
| } | |||
| return null; | |||
| } | |||
| public WxMpMessageRouter getRouter(WxMpService mpService) { | |||
| return newRouter(mpService); | |||
| } | |||
| public WxMpService getMpService(String appId) { | |||
| WxAppinfo appinfo = appinfoService.getByAppId(appId); | |||
| if(appinfo == null) | |||
| return null; | |||
| return MpUtil.getMpService(appinfo); | |||
| } | |||
| private WxMpMessageRouter newRouter(WxMpService wxMpService) { | |||
| final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService); | |||
| // 记录所有事件的日志 (异步执行) | |||
| 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.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.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.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.LOCATION) | |||
| .handler(this.locationHandler).end(); | |||
| // 扫码事件 | |||
| newRouter.rule().async(false).msgType(XmlMsgType.EVENT) | |||
| .event(EventType.SCAN).handler(this.nullHandler).end(); | |||
| // 默认 | |||
| newRouter.rule().async(false).handler(this.msgHandler).end(); | |||
| return newRouter; | |||
| } | |||
| } | |||