package com.wanhua.weixin.model;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
* 接收的普通消息
*
* @author w_xfpenga
*
* 2014-12-28
*
*/
@XStreamAlias("xml")
public class ReceMsg {
// 开发者微信号
@XStreamAlias("ToUserName")
public String ToUserName;
// 发送方帐号(一个OpenID)
@XStreamAlias("FromUserName")
public String FromUserName;
// 消息创建时间 (整型)
@XStreamAlias("CreateTime")
public String CreateTime;
// 消息类型:text,image,voice,video,location,link
@XStreamAlias("MsgType")
public String MsgType;
// 文本消息内容
@XStreamAlias("Content")
public String Content;
// 消息id,64位整型
@XStreamAlias("MsgId")
public String MsgId;
/**
* 将ReceMsg实体类转化成xml格式
*
* @author w_xfpenga
* @param xml
* @return
*
* 2014-12-28
*/
public static ReceMsg parseReceMsgText(String xml) {
XStream xstream = new XStream(new DomDriver());
xstream.alias("xml", ReceMsg.class);
// 开发者微信号
xstream.aliasField("ToUserName", ReceMsg.class, "ToUserName");
// 发送方帐号(一个OpenID)
xstream.aliasField("FromUserName", ReceMsg.class, "FromUserName");
// 消息创建时间 (整型)
xstream.aliasField("CreateTime", ReceMsg.class, "CreateTime");
// 消息类型:text,image,voice,video,location,link
xstream.aliasField("MsgType", ReceMsg.class, "MsgType");
// 文本消息内容
xstream.aliasField("Content", ReceMsg.class, "Content");
// 消息id,64位整型
xstream.aliasField("MsgId", ReceMsg.class, "MsgId");
ReceMsg receMsgText = (ReceMsg) xstream.fromXML(xml);
return receMsgText;
}
}