微信消息封装服务

This commit is contained in:
x ronger 2020-09-14 20:12:42 +08:00
parent af1ba638f4
commit a32d020b7c

View File

@ -1,8 +1,6 @@
package com.rymcu.vertical.wx.mp.handler;
import com.rymcu.vertical.wx.mp.builder.TextBuilder;
import com.rymcu.vertical.wx.mp.utils.JsonUtils;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
@ -29,21 +27,13 @@ public class MsgHandler extends AbstractHandler {
//TODO 可以选择将消息保存到本地
}
//当用户输入关键词如你好客服并且有客服在线时把消息转发给在线客服
try {
if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
&& weixinService.getKefuService().kfOnlineList()
.getKfOnlineList().size() > 0) {
return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE()
if (wxMessage == null || StringUtils.isBlank(wxMessage.getContent())) {
return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE()
.fromUser(wxMessage.getToUser())
.toUser(wxMessage.getFromUser()).build();
}
} catch (WxErrorException e) {
e.printStackTrace();
}
//TODO 组装回复消息
String content = "收到信息内容:" + JsonUtils.toJson(wxMessage);
String content = "我们已经收到您的留言,稍后客服将会联系您!";
return new TextBuilder().build(content, wxMessage, weixinService);