微信被动回复用户消息-文本消息-springmvc环境下自动生成xml
springmvc - 大牛!
private Object subscribeMessage(Scan scan) { Scan reply = new Scan(); reply.setToUserName(scan.getFromUserName()); reply.setFromUserName(scan.getToUserName()); reply.setCreateTime((int) (Calendar.getInstance().getTimeInMillis() / 1000) ); reply.setMsgType("text"); reply.setContent("欢迎订阅。"); return reply; }
object
@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; ......
controller
@RequestMapping(value="message" ) @ResponseBody public Object weixinCreate(@RequestBody Scan scan, HttpServletResponse response){ if("text".equals(scan.getMsgType())){ return textMessage(scan); }