Java Code Examples for me.chanjar.weixin.mp.bean.message.WxMpXmlMessage#getContent()

The following examples show how to use me.chanjar.weixin.mp.bean.message.WxMpXmlMessage#getContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MsgHandler.java    From yshopmall with Apache License 2.0 5 votes vote down vote up
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                Map<String, Object> context, WxMpService weixinService,
                                WxSessionManager sessionManager) {

    if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
        //TODO 可以选择将消息保存到本地
    }

    //当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
    try {
        if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
            && weixinService.getKefuService().kfOnlineList()
            .getKfOnlineList().size() > 0) {
            return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE()
                .fromUser(wxMessage.getToUser())
                .toUser(wxMessage.getFromUser()).build();
        }
    } catch (WxErrorException e) {
        e.printStackTrace();
    }

    //TODO 组装回复消息
    String content = "yshop收到信息内容:" + wxMessage.getContent();

    return new TextBuilder().build(content, wxMessage, weixinService);

}
 
Example 2
Source File: MsgHandler.java    From black-shop with Apache License 2.0 5 votes vote down vote up
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService weixinService,
								WxSessionManager sessionManager) {

	if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
		// TODO 可以选择将消息保存到本地
	}

	// 当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
	try {
		if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
				&& weixinService.getKefuService().kfOnlineList().getKfOnlineList().size() > 0) {
			return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().fromUser(wxMessage.getToUser())
					.toUser(wxMessage.getFromUser()).build();
		}
	} catch (WxErrorException e) {
		e.printStackTrace();
	}
	// 1. 获取微信客户端发送的消息
	String fromContent = wxMessage.getContent();
	// 2.使用正则表达式验证消息是否为手机号码格式
	if (RegexUtils.checkMobile(fromContent)) {
		// 1.根据手机号码调用会员服务接口查询用户信息是否存在
		ResponseResult<Boolean> result = sysUserServiceClient.existMobileNumber(fromContent);
		if (!result.getResult()) {
			return new TextBuilder().build("该手机号码" + fromContent + "已经存在!", wxMessage, weixinService);
		}
		// 3.如果是手机号码格式的话,随机生产4位数字注册码
		int registCode = registCode();
		String content = registrationCodeMessage.format(registrationCodeMessage, registCode);
		// 将注册码存入在redis中 key为手机号码
		//redisUtil.setString(Constants.WECHET_CODE_KEY + fromContent, registCode + "", Constants.WECHET_CODE_TIMEOUT);
		return new TextBuilder().build(content, wxMessage, weixinService);
	}
	// 否则情况下返回默认消息 调用第三方机器人接口
	return new TextBuilder().build(defaultRegistrationCodeMessage, wxMessage, weixinService);

}