View Javadoc
1   package com.zone.weixin4j.qy.chat;
2   
3   import com.zone.weixin4j.type.MessageType;
4   
5   import javax.xml.bind.annotation.XmlElement;
6   import javax.xml.bind.annotation.XmlTransient;
7   import java.io.Serializable;
8   import java.util.Arrays;
9   import java.util.Date;
10  import java.util.List;
11  
12  /**
13   * 会话事件或消息
14   * 
15   * @className ChatItem
16   * @author jinyu(foxinmy@gmail.com)
17   * @date 2015年8月1日
18   * @since JDK 1.6
19   * @see
20   */
21  public class ChatItem implements Serializable {
22  
23  	private static final long serialVersionUID = -5921235260175596270L;
24  
25  	private final String LIST_SEPARATOR = "\\|";
26  
27  	/**
28  	 * 操作成员UserID
29  	 */
30  	@XmlElement(name = "FromUserName")
31  	private String operatorId;
32  	/**
33  	 * 消息创建时间(整型)
34  	 */
35  	@XmlElement(name = "CreateTime")
36  	private long createTime;
37  	/**
38  	 * 消息类型
39  	 * 
40  	 */
41  	@XmlElement(name = "MsgType")
42  	private String msgType;
43  	/**
44  	 * 事件类型
45  	 */
46  	@XmlElement(name = "Event")
47  	private String eventType;
48  	/**
49  	 * 会话id
50  	 */
51  	@XmlElement(name = "ChatId")
52  	private String chatId;
53  	/**
54  	 * 会话标题
55  	 */
56  	@XmlElement(name = "Name")
57  	private String chatName;
58  	/**
59  	 * 管理员userid
60  	 */
61  	@XmlElement(name = "Owner")
62  	private String ownerId;
63  	/**
64  	 * 会话成员列表
65  	 */
66  	@XmlElement(name = "UserList")
67  	private String members;
68  	/**
69  	 * 会话新增成员列表
70  	 */
71  	@XmlElement(name = "AddUserList")
72  	private String addMembers;
73  	/**
74  	 * 会话删除成员列表
75  	 */
76  	@XmlElement(name = "DelUserList")
77  	private String deleteMembers;
78  	/**
79  	 * 消息ID 64位整型
80  	 */
81  	@XmlElement(name = "MsgId")
82  	private long msgId;
83  	/**
84  	 * 接收人
85  	 */
86  	@XmlElement(name = "Receiver")
87  	private ChatReceiver receiver;
88  	/**
89  	 * 文本消息内容
90  	 */
91  	@XmlElement(name = "Content")
92  	private String content;
93  	/**
94  	 * 图片消息链接
95  	 */
96  	@XmlElement(name = "PicUrl")
97  	private String picUrl;
98  	/**
99  	 * 链接消息标题
100 	 */
101 	@XmlElement(name = "Title")
102 	private String title;
103 	/**
104 	 * 链接消息描述
105 	 */
106 	@XmlElement(name = "Description")
107 	private String description;
108 	/**
109 	 * 链接消息链接
110 	 */
111 	@XmlElement(name = "Url")
112 	private String url;
113 	/**
114 	 * 图片、语音、文件消息的媒体id,可以调用获取媒体文件接口拉取数据
115 	 */
116 	@XmlElement(name = "MediaId")
117 	private String mediaId;
118 
119 	public String getOperatorId() {
120 		return operatorId;
121 	}
122 
123 	public long getCreateTime() {
124 		return createTime;
125 	}
126 
127 	@XmlTransient
128 	public Date getFormatCreateTime() {
129 		return createTime > 0l ? new Date(createTime * 1000l) : null;
130 	}
131 
132 	public String getMsgType() {
133 		return msgType;
134 	}
135 
136 	@XmlTransient
137 	public MessageType getFormatMsgType() {
138 		return msgType != null ? MessageType.valueOf(msgType) : null;
139 	}
140 
141 	public String getEventType() {
142 		return eventType;
143 	}
144 
145 	@XmlTransient
146 	public ChatEventType getFormatEventType() {
147 		return eventType != null ? ChatEventType.valueOf(eventType) : null;
148 	}
149 
150 	public String getChatId() {
151 		return chatId;
152 	}
153 
154 	public String getChatName() {
155 		return chatName;
156 	}
157 
158 	public String getOwnerId() {
159 		return ownerId;
160 	}
161 
162 	public String getMembers() {
163 		return members;
164 	}
165 
166 	@XmlTransient
167 	public List<String> getFormatMembers() {
168 		return members != null ? Arrays.asList(members.split(LIST_SEPARATOR))
169 				: null;
170 	}
171 
172 	public String getAddMembers() {
173 		return addMembers;
174 	}
175 
176 	@XmlTransient
177 	public List<String> getFormatAddMembers() {
178 		return addMembers != null ? Arrays.asList(addMembers
179 				.split(LIST_SEPARATOR)) : null;
180 	}
181 
182 	public String getDeleteMembers() {
183 		return deleteMembers;
184 	}
185 
186 	@XmlTransient
187 	public List<String> getFormatDeleteMembers() {
188 		return deleteMembers != null ? Arrays.asList(deleteMembers
189 				.split(LIST_SEPARATOR)) : null;
190 	}
191 
192 	public long getMsgId() {
193 		return msgId;
194 	}
195 
196 	public ChatReceiver getReceiver() {
197 		return receiver;
198 	}
199 
200 	public String getContent() {
201 		return content;
202 	}
203 
204 	public String getPicUrl() {
205 		return picUrl;
206 	}
207 
208 	public String getMediaId() {
209 		return mediaId;
210 	}
211 
212 	public static long getSerialversionuid() {
213 		return serialVersionUID;
214 	}
215 
216 	public String getTitle() {
217 		return title;
218 	}
219 
220 	public String getDescription() {
221 		return description;
222 	}
223 
224 	public String getUrl() {
225 		return url;
226 	}
227 
228 	@Override
229 	public String toString() {
230 		return "ChatItem [operatorId=" + operatorId + ", createTime="
231 				+ createTime + ", msgType=" + msgType + ", eventType="
232 				+ eventType + ", chatId=" + chatId + ", chatName=" + chatName
233 				+ ", ownerId=" + ownerId + ", members=" + members
234 				+ ", addMembers=" + addMembers + ", deleteMembers="
235 				+ deleteMembers + ", msgId=" + msgId + ", receiver=" + receiver
236 				+ ", content=" + content + ", picUrl=" + picUrl + ", title="
237 				+ title + ", description=" + description + ", url=" + url
238 				+ ", mediaId=" + mediaId + "]";
239 	}
240 }