微信推送給服務器的XML消息解析;java
可使用request.getInputStream(); 獲取輸入的消息流;可是須要本身解析流;spring
spring mvc自帶解析功能;服務器
controller中:微信
@RequestMapping(value="weixin_create" ) @ResponseBody public String weixinCreate(@RequestBody Scan scan ){ scanMapper.insertSelective(scan ); return "weixinCreate..."; }
並且,還能夠獲取get串中的參數;mybatis
@RequestMapping(value="weixin_create" ) @ResponseBody public String weixinCreate(@RequestBody Scan scan, String signature){ scan.setToUserName(signature); // 測試是否能夠得到值 scanMapper.insertSelective(scan); return "weixinCreate..."; }
model對象,這個也是mybatis的使用對象;mvc
package com.xxx.model; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name="xml") @XmlAccessorType(XmlAccessType.FIELD) public class Scan { private Integer id; @XmlElement(name="ToUserName") private String toUserName; @XmlElement(name="FromUserName") private String fromUserName; @XmlElement(name="CreateTime") private Integer createTime; @XmlElement(name="MsgType") private String msgType; @XmlElement(name="Event") private String event; @XmlElement(name="EventKey") private String eventKey; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getToUserName() { return toUserName; } public void setToUserName(String toUserName) { this.toUserName = toUserName; } public String getFromUserName() { return fromUserName; } public void setFromUserName(String fromUserName) { this.fromUserName = fromUserName; } public Integer getCreateTime() { return createTime; } public void setCreateTime(Integer createTime) { this.createTime = createTime; } public String getMsgType() { return msgType; } public void setMsgType(String msgType) { this.msgType = msgType; } public String getEvent() { return event; } public void setEvent(String event) { this.event = event; } public String getEventKey() { return eventKey; } public void setEventKey(String eventKey) { this.eventKey = eventKey; } }