use of com.github.binarywang.demo.spring.builder.TextBuilder in project weixin-java-mp-multi-demo by binarywang.
the class LocationHandler method handle.
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) {
if (wxMessage.getMsgType().equals(XmlMsgType.LOCATION)) {
// TODO 接收处理用户发送的地理位置消息
try {
String content = "感谢反馈,您的的地理位置已收到!";
return new TextBuilder().build(content, wxMessage, null);
} catch (Exception e) {
this.logger.error("位置消息接收处理失败", e);
return null;
}
}
// 上报地理位置事件
this.logger.info("\n上报地理位置 。。。 ");
this.logger.info("\n纬度 : " + wxMessage.getLatitude());
this.logger.info("\n经度 : " + wxMessage.getLongitude());
this.logger.info("\n精度 : " + String.valueOf(wxMessage.getPrecision()));
return null;
}
use of com.github.binarywang.demo.spring.builder.TextBuilder in project weixin-java-mp-multi-demo by binarywang.
the class MsgHandler method handle.
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) {
BaseWxService weixinService = (BaseWxService) wxMpService;
if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
// TODO 可以选择将消息保存到本地
}
// 当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服") && weixinService.hasKefuOnline()) {
return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).build();
}
// TODO 组装回复消息
String content = "回复信息内容";
return new TextBuilder().build(content, wxMessage, weixinService);
}
use of com.github.binarywang.demo.spring.builder.TextBuilder in project weixin-java-mp-multi-demo by binarywang.
the class MenuHandler method handle.
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) {
BaseWxService weixinService = (BaseWxService) wxMpService;
String key = wxMessage.getEventKey();
WxMenuKey menuKey = null;
try {
menuKey = JSON.parseObject(key, WxMenuKey.class);
} catch (Exception e) {
return WxMpXmlOutMessage.TEXT().content(key).fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).build();
}
AbstractBuilder builder = null;
switch(menuKey.getType()) {
case XmlMsgType.TEXT:
builder = new TextBuilder();
break;
case XmlMsgType.IMAGE:
builder = new ImageBuilder();
break;
case XmlMsgType.VOICE:
break;
case XmlMsgType.VIDEO:
break;
case XmlMsgType.NEWS:
break;
default:
break;
}
if (builder != null) {
try {
return builder.build(menuKey.getContent(), wxMessage, weixinService);
} catch (Exception e) {
this.logger.error(e.getMessage(), e);
}
}
return null;
}
use of com.github.binarywang.demo.spring.builder.TextBuilder in project weixin-java-mp-multi-demo by binarywang.
the class SubscribeHandler method handle.
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
this.logger.info("新关注用户 OPENID: " + wxMessage.getFromUser());
BaseWxService weixinService = (BaseWxService) wxMpService;
// 获取微信用户基本信息
WxMpUser userWxInfo = weixinService.getUserService().userInfo(wxMessage.getFromUser(), null);
if (userWxInfo != null) {
// TODO 可以添加关注用户到本地
}
WxMpXmlOutMessage responseResult = null;
try {
responseResult = handleSpecial(wxMessage);
} catch (Exception e) {
this.logger.error(e.getMessage(), e);
}
if (responseResult != null) {
return responseResult;
}
try {
return new TextBuilder().build("感谢关注", wxMessage, weixinService);
} catch (Exception e) {
this.logger.error(e.getMessage(), e);
}
return null;
}
Aggregations