當前位置: 首頁>>代碼示例>>Java>>正文


Java WxMpXmlMessage類代碼示例

本文整理匯總了Java中me.chanjar.weixin.mp.bean.message.WxMpXmlMessage的典型用法代碼示例。如果您正苦於以下問題:Java WxMpXmlMessage類的具體用法?Java WxMpXmlMessage怎麽用?Java WxMpXmlMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WxMpXmlMessage類屬於me.chanjar.weixin.mp.bean.message包,在下文中一共展示了WxMpXmlMessage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSessionClean1

import me.chanjar.weixin.mp.bean.message.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:11590692,項目名稱:Wechat-Group,代碼行數:19,代碼來源:WxMpMessageRouterTest.java

示例2: test

import me.chanjar.weixin.mp.bean.message.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:11590692,項目名稱:Wechat-Group,代碼行數:24,代碼來源:WxMpMessageRouterRule.java

示例3: isDuplicateMessage

import me.chanjar.weixin.mp.bean.message.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:11590692,項目名稱:Wechat-Group,代碼行數:17,代碼來源:WxMpMessageRouter.java

示例4: handle

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
                                WxMpService wxMpService, WxSessionManager sessionManager) {
  try {
    WxMediaUploadResult wxMediaUploadResult = wxMpService.getMaterialService()
      .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, ClassLoader.getSystemResourceAsStream("mm.jpeg"));
    WxMpXmlOutImageMessage m
      = WxMpXmlOutMessage
      .IMAGE()
      .mediaId(wxMediaUploadResult.getMediaId())
      .fromUser(wxMessage.getToUser())
      .toUser(wxMessage.getFromUser())
      .build();
    return m;
  } catch (WxErrorException e) {
    e.printStackTrace();
  }

  return null;
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:21,代碼來源:DemoImageHandler.java

示例5: testSessionClean3

import me.chanjar.weixin.mp.bean.message.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:11590692,項目名稱:Wechat-Group,代碼行數:19,代碼來源:WxMpMessageRouterTest.java

示例6: handle

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                Map<String, Object> context, WxMpService weixinService,
                                WxSessionManager sessionManager) {

    if (!wxMessage.getMsgType().equals(WxConsts.XML_MSG_EVENT)) {
        //TODO 可以選擇將消息保存到本地
    }
    String input = null;
    if (wxMessage.getMsgType().equals(WxConsts.XML_MSG_VOICE)) {
        input = wxMessage.getRecognition();
    } else if (wxMessage.getMsgType().equals(WxConsts.XML_MSG_TEXT)) {
        input = wxMessage.getContent();
    }
    // 使用用戶id作為sessionId
    String sessionId = wxMessage.getFromUser();

    //TODO 組裝回複消息
    String content = kfConfiguration.router(input, sessionId, sessionManager);

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

}
 
開發者ID:xjtushilei,項目名稱:knowledge-forest-dialogue-recommendation,代碼行數:24,代碼來源:MsgHandler.java

示例7: handle

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                Map<String, Object> context, WxMpService wxMpService,
                                WxSessionManager sessionManager) {
    if (wxMessage.getMsgType().equals(WxConsts.XML_MSG_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()));

    //TODO  可以將用戶地理位置信息保存到本地數據庫,以便以後使用

    return null;
}
 
開發者ID:xjtushilei,項目名稱:knowledge-forest-dialogue-recommendation,代碼行數:26,代碼來源:LocationHandler.java

示例8: handle

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                Map<String, Object> context, WxMpService weixinService,
                                WxSessionManager sessionManager) {

    String msg = String.format("type:%s, event:%s, key:%s",
            wxMessage.getMsgType(), wxMessage.getEvent(),
            wxMessage.getEventKey());
    //type是view的是鏈接,直接打開就行。如果想執行什麽也行
    if (WxConsts.BUTTON_VIEW.equals(wxMessage.getEvent())) {
        return null;
    }
    if (wxMessage.getEventKey().equals("V1001_KF")) {
        return WxMpXmlOutMessage.TEXT().content("將多源、片麵、無序的碎片化知識聚合成符合人類認知學習特點的“知識森林”,緩解碎片化知識引發的學習迷航問題!\n <a href='http://yotta.xjtushilei.com:888/Yotta_frontend/index.html'>點擊查看</a> /:8-) ")
                .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
                .build();
    }
    if (wxMessage.getEventKey().equals("V1001_GOOD")) {
        return WxMpXmlOutMessage.TEXT().content("謝謝你的點讚! /調皮")
                .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
                .build();
    }
    return null;
}
 
開發者ID:xjtushilei,項目名稱:knowledge-forest-dialogue-recommendation,代碼行數:25,代碼來源:MenuHandler.java

示例9: test

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
/**
 * 將微信自定義的事件修正為不區分大小寫,
 * 比如框架定義的事件常量為click,但微信傳遞過來的卻是CLICK
 */
protected boolean test(WxMpXmlMessage wxMessage) {
  return
    (this.fromUser == null || this.fromUser.equals(wxMessage.getFromUser()))
      &&
      (this.msgType == null || this.msgType.equalsIgnoreCase(wxMessage.getMsgType()))
      &&
      (this.event == null || this.event.equalsIgnoreCase(wxMessage.getEvent()))
      &&
      (this.eventKey == null || this.eventKey.equalsIgnoreCase(wxMessage.getEventKey()))
      &&
      (this.eventKeyRegex == null || Pattern.matches(this.eventKeyRegex, StringUtils.trimToEmpty(wxMessage.getEventKey())))
      &&
      (this.content == null || this.content.equals(StringUtils.trimToNull(wxMessage.getContent())))
      &&
      (this.rContent == null || Pattern.matches(this.rContent, StringUtils.trimToEmpty(wxMessage.getContent())))
      &&
      (this.matcher == null || this.matcher.match(wxMessage))
    ;
}
 
開發者ID:binarywang,項目名稱:weixin-java-tools,代碼行數:24,代碼來源:WxMpMessageRouterRule.java

示例10: isMsgDuplicated

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
protected boolean isMsgDuplicated(WxMpXmlMessage wxMessage) {
  StringBuilder messageId = new StringBuilder();
  if (wxMessage.getMsgId() == null) {
    messageId.append(wxMessage.getCreateTime())
      .append("-").append(wxMessage.getFromUser())
      .append("-").append(StringUtils.trimToEmpty(wxMessage.getEventKey()))
      .append("-").append(StringUtils.trimToEmpty(wxMessage.getEvent()))
    ;
  } else {
    messageId.append(wxMessage.getMsgId())
      .append("-").append(wxMessage.getCreateTime())
      .append("-").append(wxMessage.getFromUser());
  }

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

}
 
開發者ID:binarywang,項目名稱:weixin-java-tools,代碼行數:18,代碼來源:WxMpMessageRouter.java

示例11: handle

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
                                WxMpService wxMpService, WxSessionManager sessionManager) {
  try {
    WxMediaUploadResult wxMediaUploadResult = wxMpService.getMaterialService()
      .mediaUpload(WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, ClassLoader.getSystemResourceAsStream("mm.jpeg"));
    WxMpXmlOutImageMessage m
      = WxMpXmlOutMessage
      .IMAGE()
      .mediaId(wxMediaUploadResult.getMediaId())
      .fromUser(wxMessage.getToUser())
      .toUser(wxMessage.getFromUser())
      .build();
    return m;
  } catch (WxErrorException e) {
    e.printStackTrace();
  }

  return null;
}
 
開發者ID:binarywang,項目名稱:weixin-java-tools,代碼行數:21,代碼來源:DemoImageHandler.java

示例12: service

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
/**
 * 處理微信推送過來的消息
 *
 * @param wxMessage
 * @return true 代表繼續執行別的router,false 代表停止執行別的router
 */
protected WxMpXmlOutMessage service(WxMpXmlMessage wxMessage,
    WxMpService wxMpService,
    WxSessionManager sessionManager,
    WxErrorExceptionHandler exceptionHandler) {

  try {

    Map<String, Object> context = new HashMap<>();
    // 如果攔截器不通過
    for (WxMpMessageInterceptor interceptor : this.interceptors) {
      if (!interceptor.intercept(wxMessage, context, wxMpService, sessionManager)) {
        return null;
      }
    }

    // 交給handler處理
    WxMpXmlOutMessage res = null;
    for (WxMpMessageHandler handler : this.handlers) {
      // 返回最後handler的結果
      if(handler == null){
        continue;
      }
      res = handler.handle(wxMessage, context, wxMpService, sessionManager);
    }
    return res;
  } catch (WxErrorException e) {
    exceptionHandler.handle(e);
  }
  return null;

}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:38,代碼來源:WxMpMessageRouterRule.java

示例13: sessionEndAccess

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
/**
 * 對session的訪問結束
 * @param wxMessage
 */
protected void sessionEndAccess(WxMpXmlMessage wxMessage) {

  InternalSession session = ((InternalSessionManager)this.sessionManager).findSession(wxMessage.getFromUser());
  if (session != null) {
    session.endAccess();
  }

}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:13,代碼來源:WxMpMessageRouter.java

示例14: handle

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService,
                                WxSessionManager sessionManager) throws WxErrorException {

  if (isUserWantGuess(wxMessage)) {
    letsGo(wxMessage, wxMpService, sessionManager);
  }

  if (isUserAnswering(wxMessage)) {
    giveHint(wxMessage, wxMpService, sessionManager);
  }

  return null;

}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:16,代碼來源:DemoGuessNumberHandler.java

示例15: handle

import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; //導入依賴的package包/類
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
                                WxMpService wxMpService, WxSessionManager sessionManager) {
  WxMpXmlOutTextMessage m
    = WxMpXmlOutMessage.TEXT().content("測試加密消息").fromUser(wxMessage.getToUser())
    .toUser(wxMessage.getFromUser()).build();
  return m;
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:9,代碼來源:DemoTextHandler.java


注:本文中的me.chanjar.weixin.mp.bean.message.WxMpXmlMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。