java编写微信源代码 java( 四 )


}
/** 此时,如果用户输入的是“java编写微信源代码你好”,在经过上面的过程之后 , result为“你也好”类似的内容
*因为最终回复给微信的也是xml格式的数据,所有需要将其封装为文本类型返回消息
* */
result = new FormatXmlProcess().formatXmlAnswer(xmlEntity.getFromUserName(), xmlEntity.getToUserName(), result);
return result;
}
}
2.2 解析接收到的xml数据,此处有两个类,ReceiveXmlEntity.java和ReceiveXmlProcess.java , 通过反射的机制动态调用实体类中的set方法,可以避免很多重复的判断,提高代码效率,代码如下:
[java] view plain copy
package demo.entity;
/**
* 接收到的微信xml实体类
* @author pamchen-1
*
*/
public class ReceiveXmlEntity {
private String ToUserName="";
private String FromUserName="";
private String CreateTime="";
private String MsgType="";
private String MsgId="";
private String Event="";
private String EventKey="";
private String Ticket="";
private String Latitude="";
private String Longitude="";
private String Precision="";
private String PicUrl="";
private String MediaId="";
private String Title="";
private String Description="";
private String Url="";
private String Location_X="";
private String Location_Y="";
private String Scale="";
private String Label="";
private String Content="";
private String Format="";
private String Recognition="";
public String getRecognition() {
return Recognition;
}
public void setRecognition(String recognition) {
Recognition = recognition;
}
public String getFormat() {
return Format;
}
public void setFormat(String format) {
Format = format;
}
public String getContent() {
return Content;
}
public void setContent(String content) {
Content = content;
}
public String getLocation_X() {
return Location_X;
}
public void setLocation_X(String locationX) {
Location_X = locationX;
}
public String getLocation_Y() {
return Location_Y;
}
public void setLocation_Y(String locationY) {
Location_Y = locationY;
}
public String getScale() {
return Scale;
}
public void setScale(String scale) {
Scale = scale;
}
public String getLabel() {
return Label;
}
public void setLabel(String label) {
Label = label;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public String getUrl() {
return Url;
}
public void setUrl(String url) {
Url = url;
}
public String getPicUrl() {
return PicUrl;
}
public void setPicUrl(String picUrl) {
PicUrl = picUrl;
}
public String getMediaId() {
return MediaId;
}
public void setMediaId(String mediaId) {
MediaId = mediaId;
}
public String getEventKey() {
return EventKey;
}
public void setEventKey(String eventKey) {
EventKey = eventKey;
}
public String getTicket() {
return Ticket;
}
public void setTicket(String ticket) {
Ticket = ticket;
}
public String getLatitude() {
return Latitude;
}
public void setLatitude(String latitude) {
Latitude = latitude;
}
public String getLongitude() {
return Longitude;
}
public void setLongitude(String longitude) {

推荐阅读