本文整理汇总了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);
}
示例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))
;
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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))
;
}
示例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());
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}