Search in sources :

Example 1 with TextBuilder

use of com.github.binarywang.demo.wechat.builder.TextBuilder in project weixin-java-mp-demo-springboot 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;
}
Also used : TextBuilder(com.github.binarywang.demo.wechat.builder.TextBuilder)

Example 2 with TextBuilder

use of com.github.binarywang.demo.wechat.builder.TextBuilder in project weixin-java-mp-demo-springboot by binarywang.

the class SubscribeHandler method handle.

@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService weixinService, WxSessionManager sessionManager) throws WxErrorException {
    this.logger.info("新关注用户 OPENID: " + wxMessage.getFromUser());
    // 获取微信用户基本信息
    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;
}
Also used : TextBuilder(com.github.binarywang.demo.wechat.builder.TextBuilder) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) WxMpXmlOutMessage(me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException)

Aggregations

TextBuilder (com.github.binarywang.demo.wechat.builder.TextBuilder)2 WxErrorException (me.chanjar.weixin.common.exception.WxErrorException)1 WxMpXmlOutMessage (me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage)1 WxMpUser (me.chanjar.weixin.mp.bean.result.WxMpUser)1