当前位置: 首页>>代码示例>>Java>>正文


Java WxMpXmlMessage类代码示例

本文整理汇总了Java中me.chanjar.weixin.mp.bean.WxMpXmlMessage的典型用法代码示例。如果您正苦于以下问题:Java WxMpXmlMessage类的具体用法?Java WxMpXmlMessage怎么用?Java WxMpXmlMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WxMpXmlMessage类属于me.chanjar.weixin.mp.bean包,在下文中一共展示了WxMpXmlMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handle

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
           WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
	String eventKey = wxMessage.getEventKey(); // qrscene_quancheng-ec
	String companyId = eventKey;
	LOGGER.info("company id: " + companyId);

	WxMpUser user = wxMpService.getUserService().userInfo(wxMessage.getFromUserName(), "zh_CN");
	String content = "Hi " + user.getNickname() + ", 还差一步<a href=\"#?user=" + user.getOpenId() + "&company="
               + companyId + "\">完善个人信息</a> 就可以开始申请购票了";

	WxMpXmlOutTextMessage m = WxMpXmlOutTextMessage.TEXT().content(content)
               .fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName()).build();

	LOGGER.error("outMessage" + m.toXml());
	return m;
}
 
开发者ID:jihao,项目名称:weixin-server-demo,代码行数:18,代码来源:SubscribeHandler.java

示例2: handle

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
           WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
	LOGGER.info("wxMpService==null ? " + (wxMpService == null));
	WxMpUser user = wxMpService.getUserService().userInfo(wxMessage.getFromUserName(), "zh_CN");
	// 后台逻辑,获得此用户的公司id,这里是 hard code
	String companyId = "quancheng-ec";

	WxMpQrCodeTicket ticket = wxMpService.getQrcodeService().qrCodeCreateLastTicket(companyId);
	// "gQFF8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL3Ewd2Y5U2JscUMtUlJ2OVFjMlFMAAIEez6pVwMEAAAAAA==";
	String qrCodePictureUrl = wxMpService.getQrcodeService().qrCodePictureUrl(ticket.getTicket());
	LOGGER.info("qrCodePictureUrl: " + qrCodePictureUrl);
	WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
	item.setDescription(user.getNickname() + " 邀请您加入公司:" + companyId);
	item.setPicUrl(qrCodePictureUrl);
	item.setTitle("邀请加入");
	item.setUrl(qrCodePictureUrl);

	WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUserName())
               .toUser(wxMessage.getFromUserName()).addArticle(item).build();

	LOGGER.error("outMessage=" + m.toXml());
	return m;
}
 
开发者ID:jihao,项目名称:weixin-server-demo,代码行数:25,代码来源:InviteHandler.java

示例3: handle

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService,
        WxSessionManager sessionManager) throws WxErrorException {
	LOGGER.info(wxMessage.toString());
	String echoMessage = "voide2text: " + wxMessage.getRecognition();
	LOGGER.info(echoMessage);

	TextUnderstander mTextUnderstander = TextUnderstander.createTextUnderstander(); // 开始语义理解
	mTextUnderstander.setParameter(SpeechConstant.LANGUAGE, "zh_cn");

	TextUnderstanderListener searchListener = new CustomTextUnderstanderListener(wxMessage, context, wxMpService,
	        sessionManager, this.xfyun_appid, this.flight_search_url, this.flight_user_token);
	mTextUnderstander.understandText(wxMessage.getRecognition(), searchListener); // 初始化监听器

	return null;
}
 
开发者ID:jihao,项目名称:weixin-server-demo,代码行数:17,代码来源:VoiceHandler.java

示例4: test

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
/**
 * 将微信自定义的事件修正为不区分大小写,
 * 比如框架定义的事件常量为click,但微信传递过来的却是CLICK
 */
protected boolean test(WxMpXmlMessage wxMessage) {
  return
      (this.fromUser == null || this.fromUser.equals(wxMessage.getFromUser()))
          &&
          (this.msgType == null || this.msgType.toLowerCase().equals((wxMessage.getMsgType()==null?null:wxMessage.getMsgType().toLowerCase())))
          &&
          (this.event == null || this.event.toLowerCase().equals((wxMessage.getEvent()==null?null:wxMessage.getEvent().toLowerCase())))
          &&
          (this.eventKey == null || this.eventKey.toLowerCase().equals((wxMessage.getEventKey()==null?null:wxMessage.getEventKey().toLowerCase())))
          &&
          (this.content == null || this.content
              .equals(wxMessage.getContent() == null ? null : wxMessage.getContent().trim()))
          &&
          (this.rContent == null || Pattern
              .matches(this.rContent, wxMessage.getContent() == null ? "" : wxMessage.getContent().trim()))
          &&
          (this.matcher == null || this.matcher.match(wxMessage))
      ;
}
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:24,代码来源:WxMpMessageRouterRule.java

示例5: isDuplicateMessage

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
protected boolean isDuplicateMessage(WxMpXmlMessage wxMessage) {

    StringBuffer messageId = new StringBuffer();
    if (wxMessage.getMsgId() == null) {
      messageId.append(wxMessage.getCreateTime())
        .append("-").append(wxMessage.getFromUser())
        .append("-").append(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey())
        .append("-").append(wxMessage.getEvent() == null ? "" : wxMessage.getEvent())
      ;
    } else {
      messageId.append(wxMessage.getMsgId());
    }

    return this.messageDuplicateChecker.isDuplicate(messageId.toString());

  }
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:17,代码来源:WxMpMessageRouter.java

示例6: testSessionClean1

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@Test(dataProvider = "standardSessionManager")
public void testSessionClean1(StandardSessionManager ism) throws InterruptedException {

  // 两个同步请求,看是否处理完毕后会被清理掉
  final WxMpMessageRouter router = new WxMpMessageRouter(null);
  router.setSessionManager(ism);
  router
      .rule().async(false).handler(new WxSessionMessageHandler()).next()
      .rule().async(false).handler(new WxSessionMessageHandler()).end();

  WxMpXmlMessage msg = new WxMpXmlMessage();
  msg.setFromUser("abc");
  router.route(msg);

  Thread.sleep(2000l);
  Assert.assertEquals(ism.getActiveSessions(), 0);

}
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:19,代码来源:WxMpMessageRouterTest.java

示例7: testSessionClean3

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@Test(dataProvider = "standardSessionManager")
public void testSessionClean3(StandardSessionManager ism) throws InterruptedException {

  // 2个异步请求,看是否处理完毕后会被清理掉
  final WxMpMessageRouter router = new WxMpMessageRouter(null);
  router.setSessionManager(ism);
  router
      .rule().async(true).handler(new WxSessionMessageHandler()).next()
      .rule().async(true).handler(new WxSessionMessageHandler()).end();

  WxMpXmlMessage msg = new WxMpXmlMessage();
  msg.setFromUser("abc");
  router.route(msg);

  Thread.sleep(2000l);
  Assert.assertEquals(ism.getActiveSessions(), 0);

}
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:19,代码来源:WxMpMessageRouterTest.java

示例8: doPost

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.POST)
public String doPost(@RequestBody String xml) {
    WxMpXmlMessage message = WxMpXmlMessage.fromXml(xml);
    switch (message.getMsgType()) {
        default:
            WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS().fromUser(message.getToUserName()).toUser(message.getFromUserName()).build();

            Page<Article> articles = articleService.get(0, 4);
            for (Article article : articles) {
                WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
                item.setDescription(article.getTitle());
                if (article.getImage() == null) item.setPicUrl("http://www.lixiaocong.com/image/logo.png");
                else item.setPicUrl(article.getImage());
                item.setTitle(article.getTitle());
                item.setUrl("http://www.lixiaocong.com/blog/detail?id=" + article.getId());
                m.addArticle(item);
            }
            return m.toXml();
    }
}
 
开发者ID:lixiaocong,项目名称:lxcCMS,代码行数:21,代码来源:WeixinController.java

示例9: handle

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
        TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
        try {
            Operator op = TableOperator.get(wxMessage.getFromUserName());
            if (op == null) {
                out.content(lang("Not_Operator"));
//			} else if (op.getAccess() >= Access.NO_LOGIN) {
//				out.content(lang("No_Login"));
            } else {
                out.content(format("Operator_Info", op.getId(), op.getName(), op.getAccess(), op.getBlock(), op.getWeek()));
            }
        } catch (Exception e) {
            e.printStackTrace();
            out.content(lang("Login_Error"));
        }
        return out.build();
    }
 
开发者ID:ZSCNetSupportDept,项目名称:WechatTicketSystem,代码行数:19,代码来源:OperatorInfoHandler.java

示例10: handle

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
    TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
    try {
        Operator operator = TableOperator.get(wxMessage.getFromUserName());
        if (operator == null)
            out.content(lang("Not_Operator"));
        else if (operator.getAccess() >= Access.NO_LOGIN) {
            out.content(lang("No_Login"));
        } else {
            WxSession session = WechatSession.create();
            session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
            session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
            session.setAttribute(Attribute.OPERATOR, operator);
            out.content(format("Home_Page_Msg", format("Operator_Home_Page", session.getId())));
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.content(lang("Login_Error"));
    }
    return out.build();
}
 
开发者ID:ZSCNetSupportDept,项目名称:WechatTicketSystem,代码行数:23,代码来源:LoginHandler.java

示例11: handle

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
    User u = TableUser.getByWechat(wxMessage.getFromUserName());
    Ticket t = TableTicket.latest(u);
    if (t == null) {
        return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
                .content(lang("No_Ticket_Available")).build();
    }
    WxSession session = WechatSession.create();
    session.setAttribute(Attribute.AUTHORIZED, Command.QUERY);
    session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
    session.setAttribute(Attribute.USER, u);

    NewsBuilder out = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
    WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
    item.setTitle(lang("Query_Title"));
    item.setDescription(ParseUtil.parseTicket(t) + "\n" + lang("More_Details"));
    item.setUrl(format("User_Query_Link", session.getId()));
    out.addArticle(item);
    return out.build();
}
 
开发者ID:ZSCNetSupportDept,项目名称:WechatTicketSystem,代码行数:22,代码来源:QueryHandler.java

示例12: handle

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
    User u = TableUser.getByWechat(wxMessage.getFromUserName());
    if (TableTicket.hasOpen(u)) {
        return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
                .content(lang("Already_Opening_Ticket")).build();
    }
    WxSession session = WechatSession.create();
    session.setAttribute(Attribute.AUTHORIZED, Command.SUBMIT);
    session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
    session.setAttribute(Attribute.USER, u);

    NewsBuilder out = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
    WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
    item.setTitle(lang("Submit_Title"));
    item.setDescription(lang("Submit_Desc"));
    item.setUrl(format("User_Submit_Link", session.getId(), u.getName(), u.getIsp().id, u.getRoom(), u.getBlock(), u.getPhone()));
    out.addArticle(item);
    return out.build();
}
 
开发者ID:ZSCNetSupportDept,项目名称:WechatTicketSystem,代码行数:21,代码来源:SubmitHandler.java

示例13: handle

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
   // String msg = source.getMessage("message.welcome", null, Locale.getDefault());
    String event = StringUtils.isBlank(wxMessage.getEvent()) ? StringUtils.EMPTY : wxMessage.getEvent();
    WxMpXmlOutTextMessage m = null;
    if (WxConsts.EVT_SUBSCRIBE.equals(event)) {
        m
                = WxMpXmlOutMessage
                .TEXT()
                .content("message.welcome")
                .fromUser(wxMessage.getToUserName())
                .toUser(wxMessage.getFromUserName())
                .build();
    } else if (WxConsts.EVT_UNSUBSCRIBE.equals(event)) {
    }
    log.info("{} ---> {}", event, ToStringBuilder.reflectionToString(wxMessage));
    return m;
}
 
开发者ID:cyzaoj,项目名称:mywx,代码行数:19,代码来源:FocusMeMessage.java

示例14: processRequest

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
/**
 * 微信服务器POST过来的数据
 * 
 * @return
 * @throws IOException
 */
@RequestMapping(value = "/connect", method = { RequestMethod.POST }, produces = { MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public String processRequest(HttpServletRequest request, @RequestParam String nonce, @RequestParam String timestamp,
        @RequestParam(defaultValue = "raw") String encrypt_type) throws IOException {

	WxMpXmlMessage inMessage = null;

	if ("raw".equals(encrypt_type)) {
		// 明文传输的消息
		inMessage = WxMpXmlMessage.fromXml(request.getInputStream());
	} else if ("aes".equals(encrypt_type)) {
		// 是aes加密的消息
		String msgSignature = request.getParameter("msg_signature");
		inMessage = WxMpXmlMessage.fromEncryptedXml(request.getInputStream(), wxMpConfigStorage, timestamp, nonce,
		        msgSignature);
	} else {
		return "<response>不可识别的加密类型</response>";
	}

	WxMpXmlOutMessage outMessage = wxMpMessageRouter.route(inMessage);

	if (outMessage != null) {
		if ("raw".equals(encrypt_type)) {
			return outMessage.toXml();
		} else if ("aes".equals(encrypt_type)) {
			return outMessage.toEncryptedXml(wxMpConfigStorage);
		}
	} else {
		return "";
	}
	return "<response>服务号不可用</response>";
}
 
开发者ID:jihao,项目名称:weixin-server-demo,代码行数:39,代码来源:WeiXinController.java

示例15: CustomTextUnderstanderListener

import me.chanjar.weixin.mp.bean.WxMpXmlMessage; //导入依赖的package包/类
public CustomTextUnderstanderListener(WxMpXmlMessage wxMessage, Map<String, Object> context,
        WxMpService wxMpService, WxSessionManager sessionManager, String xfyun_appid, String flight_search_url, String flight_user_token) {
	super();
	this.wxMessage = wxMessage;
	this.context = context;
	this.wxMpService = wxMpService;
	this.sessionManager = sessionManager;
	
	this.xfyun_appid = xfyun_appid;
	this.flight_search_url = flight_search_url;
	this.flight_user_token = flight_user_token;
	
	SpeechUtility.createUtility(SpeechConstant.APPID + "=" + this.xfyun_appid);
}
 
开发者ID:jihao,项目名称:weixin-server-demo,代码行数:15,代码来源:CustomTextUnderstanderListener.java


注:本文中的me.chanjar.weixin.mp.bean.WxMpXmlMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。