MsgModelParser.java
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Copyright (c) 2011-2014, L.cm 卢春梦 (qq596392912@gmail.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
package com.jfinal.wxaapp.msg;
import com.jfinal.wxaapp.msg.bean.WxaImageMsg;
import com.jfinal.wxaapp.msg.bean.WxaMsg;
import com.jfinal.wxaapp.msg.bean.WxaTextMsg;
import com.jfinal.wxaapp.msg.bean.WxaUserEnterSessionMsg;
/**
* 用户model转为msg对象
* @author L.cm
*
*/
class MsgModelParser {
private static enum MsgType {
text, image, event
}
protected WxaMsg parserMsg(MsgModel msgModel) {
String msgTypeStr = msgModel.getMsgType().toLowerCase();
MsgType msgType = MsgType.valueOf(msgTypeStr);
if (MsgType.text == msgType) {
return new WxaTextMsg(msgModel);
}
if (MsgType.image == msgType) {
return new WxaImageMsg(msgModel);
}
if (MsgType.event == msgType) {
if ("user_enter_tempsession".equalsIgnoreCase(msgModel.getEvent())) {
return new WxaUserEnterSessionMsg(msgModel);
}
}
throw new RuntimeException("JFinal-weixin 暂不支持该类型的小程序消息!");
}
}