• 微信推送给服务器的XML消息解析-springmvc 解析xml数据流


    微信推送给服务器的XML消息解析;

    可以使用request.getInputStream(); 获取输入的消息流;但是需要自己解析流;

    spring mvc自带解析功能;

    controller中:

        @RequestMapping(value="weixin_create" )
        @ResponseBody
        public String weixinCreate(@RequestBody Scan  scan ){
            scanMapper.insertSelective(scan );
            return "weixinCreate...";
        }

    而且,还可以获取get串中的参数;

        @RequestMapping(value="weixin_create" )
        @ResponseBody
        public String weixinCreate(@RequestBody Scan scan, String signature){
            scan.setToUserName(signature); // 测试是否可以获得值
            scanMapper.insertSelective(scan);
            return "weixinCreate...";
        }

    model对象,这个也是mybatis的使用对象;

    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;
        }
    }
  • 相关阅读:
    笔记:C/C++字符函数的使用
    学习游戏基础编程3:地图编辑器
    学习游戏基础编程2:Win32分割窗口
    学习游戏基础编程1:Win32自定义控件
    [WebServer] Tomcat 配置访问限制:访问白名单和访问黑名单
    [WebServer] Windows操作系统下 Tomcat 服务器运行 PHP 的环境配置
    XSLT函数集合:数值函数、字符串函、节点集函数和布尔函数
    腾讯的一道JavaScript面试题
    【转】AES 进一步的研究
    MQTT-Client-FrameWork使用整理
  • 原文地址:https://www.cnblogs.com/stono/p/6561261.html
Copyright © 2020-2023  润新知