public String processRequest(HttpServletRequest request) {
        Map<String, Object> reqMap = MessageUtil.parseXml(request, getToken(), getAppId(), getAESKey());
        String fromUserName = (String) reqMap.get("FromUserName");
        String toUserName = (String) reqMap.get("ToUserName");
        String msgType = (String) reqMap.get("MsgType");

        LOG.debug("收到消息,消息类型:{}", msgType);

        BaseMsg msg = null;

        if (msgType.equals(ReqType.EVENT)) {
            String eventType = (String) reqMap.get("Event");
            String ticket = (String) reqMap.get("Ticket");
            QrCodeEvent qrCodeEvent = null;
            if (isNotBlank(ticket)) {
                String eventKey = (String) reqMap.get("EventKey");
                LOG.debug("eventKey:{}", eventKey);
                LOG.debug("ticket:{}", ticket);
                qrCodeEvent = new QrCodeEvent(eventKey, ticket);
                buildBasicEvent(reqMap, qrCodeEvent);
                if (eventType.equals(EventType.SCAN)) {
                    msg = handleQrCodeEvent(qrCodeEvent);
                    if (isNull(msg)) {
                        msg = processEventHandle(qrCodeEvent);
                    }
                }
            }
            if (eventType.equals(EventType.SUBSCRIBE)) {
                BaseEvent event = new BaseEvent();
                if (qrCodeEvent != null) {
                    event = qrCodeEvent;
                } else {
                    buildBasicEvent(reqMap, event);
                }
                msg = handleSubscribe(event);
                if (isNull(msg)) {
                    msg = processEventHandle(event);
                }
            } else if (eventType.equals(EventType.UNSUBSCRIBE)) {
                BaseEvent event = new BaseEvent();
                buildBasicEvent(reqMap, event);
                msg = handleUnsubscribe(event);
                if (isNull(msg)) {
                    msg = processEventHandle(event);
                }
            } else if (eventType.equals(EventType.CLICK)) {
                String eventKey = (String) reqMap.get("EventKey");
                LOG.debug("eventKey:{}", eventKey);
                MenuEvent event = new MenuEvent(eventKey);
                buildBasicEvent(reqMap, event);
                msg = handleMenuClickEvent(event);
                if (isNull(msg)) {
                    msg = processEventHandle(event);
                }
            } else if (eventType.equals(EventType.VIEW)) {
                String eventKey = (String) reqMap.get("EventKey");
                LOG.debug("eventKey:{}", eventKey);
                MenuEvent event = new MenuEvent(eventKey);
                buildBasicEvent(reqMap, event);
                msg = handleMenuViewEvent(event);
                if (isNull(msg)) {
                    msg = processEventHandle(event);
                }
            } else if (eventType.equals(EventType.LOCATION)) {
                double latitude = Double.parseDouble((String) reqMap.get("Latitude"));
                double longitude = Double.parseDouble((String) reqMap.get("Longitude"));
                double precision = Double.parseDouble((String) reqMap.get("Precision"));
                LocationEvent event = new LocationEvent(latitude, longitude,
                        precision);
                buildBasicEvent(reqMap, event);
                msg = handleLocationEvent(event);
                if (isNull(msg)) {
                    msg = processEventHandle(event);
                }
            } else if (EventType.SCANCODEPUSH.equals(eventType) || EventType.SCANCODEWAITMSG.equals(eventType)) {
                String eventKey = (String) reqMap.get("EventKey");
                Map<String, Object> scanCodeInfo = (Map<String, Object>)reqMap.get("ScanCodeInfo");
                String scanType = (String) scanCodeInfo.get("ScanType");
                String scanResult = (String) scanCodeInfo.get("ScanResult");
                ScanCodeEvent event = new ScanCodeEvent(eventKey, scanType, scanResult);
                buildBasicEvent(reqMap, event);
                msg = handleScanCodeEvent(event);
                if (isNull(msg)) {
                    msg = processEventHandle(event);
                }
            } else if (EventType.PICPHOTOORALBUM.equals(eventType) || EventType.PICSYSPHOTO.equals(eventType) || EventType.PICWEIXIN.equals(eventType)) {
                String eventKey = (String) reqMap.get("EventKey");
                Map<String, Object> sendPicsInfo = (Map<String, Object>)reqMap.get("SendPicsInfo");
                int count = Integer.parseInt((String) sendPicsInfo.get("Count"));
                List<Map> picList = (List) sendPicsInfo.get("PicList");
                SendPicsInfoEvent event = new SendPicsInfoEvent(eventKey, count, picList);
                buildBasicEvent(reqMap, event);
                msg = handlePSendPicsInfoEvent(event);
                if (isNull(msg)) {
                    msg = processEventHandle(event);
                }
            } else if (EventType.TEMPLATESENDJOBFINISH.equals(eventType)) {
                String msgId = (String) reqMap.get("MsgID");
                String status = (String) reqMap.get("Status");
                TemplateMsgEvent event = new TemplateMsgEvent(msgId,status);
                buildBasicEvent(reqMap, event);
                msg = handleTemplateMsgEvent(event);
                if (isNull(msg)) {
                    msg = processEventHandle(event);
                }
            }else if(EventType.MASSSENDJOBFINISH.equals(eventType)){
                String msgId=(String)reqMap.get("MsgID");
                String status=(String)reqMap.get("Status");
                Integer TotalCount=Integer.valueOf(String.valueOf(reqMap.get("TotalCount")));
                Integer filterCount=Integer.valueOf(String.valueOf(reqMap.get("FilterCount")));
                Integer sentCount=Integer.valueOf(String.valueOf(reqMap.get("SentCount")));
                Integer errorCount=Integer.valueOf(String.valueOf(reqMap.get("ErrorCount")));
                SendMessageEvent event=new SendMessageEvent(msgId,status,TotalCount,filterCount,sentCount,errorCount);
                buildBasicEvent(reqMap, event);
                msg=callBackAllMessage(event);
                if (isNull(msg)) {
                    msg = processEventHandle(event);
                }
            }
        } else {
            if (msgType.equals(ReqType.TEXT)) {
                String content = (String) reqMap.get("Content");
                LOG.debug("文本消息内容:{}", content);
                TextReqMsg textReqMsg = new TextReqMsg(content);
                buildBasicReqMsg(reqMap, textReqMsg);
                msg = handleTextMsg(textReqMsg);
                if (isNull(msg)) {
                    msg = processMessageHandle(textReqMsg);
                }
            } else if (msgType.equals(ReqType.IMAGE)) {
                String picUrl = (String) reqMap.get("PicUrl");
                String mediaId = (String) reqMap.get("MediaId");
                ImageReqMsg imageReqMsg = new ImageReqMsg(picUrl, mediaId);
                buildBasicReqMsg(reqMap, imageReqMsg);
                msg = handleImageMsg(imageReqMsg);
                if (isNull(msg)) {
                    msg = processMessageHandle(imageReqMsg);
                }
            } else if (msgType.equals(ReqType.VOICE)) {
                String format = (String) reqMap.get("Format");
                String mediaId = (String) reqMap.get("MediaId");
                String recognition = (String) reqMap.get("Recognition");
                VoiceReqMsg voiceReqMsg = new VoiceReqMsg(mediaId, format,
                        recognition);
                buildBasicReqMsg(reqMap, voiceReqMsg);
                msg = handleVoiceMsg(voiceReqMsg);
                if (isNull(msg)) {
                    msg = processMessageHandle(voiceReqMsg);
                }
            } else if (msgType.equals(ReqType.VIDEO)) {
                String thumbMediaId = (String) reqMap.get("ThumbMediaId");
                String mediaId = (String) reqMap.get("MediaId");
                VideoReqMsg videoReqMsg = new VideoReqMsg(mediaId, thumbMediaId);
                buildBasicReqMsg(reqMap, videoReqMsg);
                msg = handleVideoMsg(videoReqMsg);
                if (isNull(msg)) {
                    msg = processMessageHandle(videoReqMsg);
                }
            } else if (msgType.equals(ReqType.SHORT_VIDEO)) {
                String thumbMediaId = (String) reqMap.get("ThumbMediaId");
                String mediaId = (String) reqMap.get("MediaId");
                VideoReqMsg videoReqMsg = new VideoReqMsg(mediaId, thumbMediaId);
                buildBasicReqMsg(reqMap, videoReqMsg);
                msg = hadnleShortVideoMsg(videoReqMsg);
                if (isNull(msg)) {
                    msg = processMessageHandle(videoReqMsg);
                }
            } else if (msgType.equals(ReqType.LOCATION)) {
                double locationX = Double.parseDouble((String) reqMap.get("Location_X"));
                double locationY = Double.parseDouble((String) reqMap.get("Location_Y"));
                int scale = Integer.parseInt((String) reqMap.get("Scale"));
                String label = (String) reqMap.get("Label");
                LocationReqMsg locationReqMsg = new LocationReqMsg(locationX,
                        locationY, scale, label);
                buildBasicReqMsg(reqMap, locationReqMsg);
                msg = handleLocationMsg(locationReqMsg);
                if (isNull(msg)) {
                    msg = processMessageHandle(locationReqMsg);
                }
            } else if (msgType.equals(ReqType.LINK)) {
                String title = (String) reqMap.get("Title");
                String description = (String) reqMap.get("Description");
                String url = (String) reqMap.get("Url");
                LOG.debug("链接消息地址:{}", url);
                LinkReqMsg linkReqMsg = new LinkReqMsg(title, description, url);
                buildBasicReqMsg(reqMap, linkReqMsg);
                msg = handleLinkMsg(linkReqMsg);
                if (isNull(msg)) {
                    msg = processMessageHandle(linkReqMsg);
                }
            }
        }
        String result = "";
        if (nonNull(msg)) {
            msg.setFromUserName(toUserName);
            msg.setToUserName(fromUserName);
            result = msg.toXml();
            if (StrUtil.isNotBlank(getAESKey())) {
                try {
                    WXBizMsgCrypt pc = new WXBizMsgCrypt(getToken(), getAESKey(), getAppId());
                    result = pc.encryptMsg(result, request.getParameter("timestamp"), request.getParameter("nonce"));
                    LOG.debug("加密后密文:{}", result);
                } catch (AesException e) {
                    LOG.error("加密异常", e);
                }
            }
        }
        return result;
    }
public String processRequest ( HttpServletRequest request ) { Map < String , Object > reqMap = MessageUtil . parseXml ( request , getToken ( ) , getAppId ( ) , getAESKey ( ) ) ; String fromUserName = ( String ) reqMap . get ( "FromUserName" ) ; String toUserName = ( String ) reqMap . get ( "ToUserName" ) ; String msgType = ( String ) reqMap . get ( "MsgType" ) ; LOG . debug ( "收到消息,消息类型:{}" , msgType ) ; BaseMsg msg = null ; if ( msgType . equals ( ReqType . EVENT ) ) { String eventType = ( String ) reqMap . get ( "Event" ) ; String ticket = ( String ) reqMap . get ( "Ticket" ) ; QrCodeEvent qrCodeEvent = null ; if ( isNotBlank ( ticket ) ) { String eventKey = ( String ) reqMap . get ( "EventKey" ) ; LOG . debug ( "eventKey:{}" , eventKey ) ; LOG . debug ( "ticket:{}" , ticket ) ; qrCodeEvent = new QrCodeEvent ( eventKey , ticket ) ; buildBasicEvent ( reqMap , qrCodeEvent ) ; if ( eventType . equals ( EventType . SCAN ) ) { msg = handleQrCodeEvent ( qrCodeEvent ) ; if ( isNull ( msg ) ) { msg = processEventHandle ( qrCodeEvent ) ; } } } if ( eventType . equals ( EventType . SUBSCRIBE ) ) { BaseEvent event = new BaseEvent ( ) ; if ( qrCodeEvent != null ) { event = qrCodeEvent ; } else { buildBasicEvent ( reqMap , event ) ; } msg = handleSubscribe ( event ) ; if ( isNull ( msg ) ) { msg = processEventHandle ( event ) ; } } else if ( eventType . equals ( EventType . UNSUBSCRIBE ) ) { BaseEvent event = new BaseEvent ( ) ; buildBasicEvent ( reqMap , event ) ; msg = handleUnsubscribe ( event ) ; if ( isNull ( msg ) ) { msg = processEventHandle ( event ) ; } } else if ( eventType . equals ( EventType . CLICK ) ) { String eventKey = ( String ) reqMap . get ( "EventKey" ) ; LOG . debug ( "eventKey:{}" , eventKey ) ; MenuEvent event = new MenuEvent ( eventKey ) ; buildBasicEvent ( reqMap , event ) ; msg = handleMenuClickEvent ( event ) ; if ( isNull ( msg ) ) { msg = processEventHandle ( event ) ; } } else if ( eventType . equals ( EventType . VIEW ) ) { String eventKey = ( String ) reqMap . get ( "EventKey" ) ; LOG . debug ( "eventKey:{}" , eventKey ) ; MenuEvent event = new MenuEvent ( eventKey ) ; buildBasicEvent ( reqMap , event ) ; msg = handleMenuViewEvent ( event ) ; if ( isNull ( msg ) ) { msg = processEventHandle ( event ) ; } } else if ( eventType . equals ( EventType . LOCATION ) ) { double latitude = Double . parseDouble ( ( String ) reqMap . get ( "Latitude" ) ) ; double longitude = Double . parseDouble ( ( String ) reqMap . get ( "Longitude" ) ) ; double precision = Double . parseDouble ( ( String ) reqMap . get ( "Precision" ) ) ; LocationEvent event = new LocationEvent ( latitude , longitude , precision ) ; buildBasicEvent ( reqMap , event ) ; msg = handleLocationEvent ( event ) ; if ( isNull ( msg ) ) { msg = processEventHandle ( event ) ; } } else if ( EventType . SCANCODEPUSH . equals ( eventType ) || EventType . SCANCODEWAITMSG . equals ( eventType ) ) { String eventKey = ( String ) reqMap . get ( "EventKey" ) ; Map < String , Object > scanCodeInfo = ( Map < String , Object > ) reqMap . get ( "ScanCodeInfo" ) ; String scanType = ( String ) scanCodeInfo . get ( "ScanType" ) ; String scanResult = ( String ) scanCodeInfo . get ( "ScanResult" ) ; ScanCodeEvent event = new ScanCodeEvent ( eventKey , scanType , scanResult ) ; buildBasicEvent ( reqMap , event ) ; msg = handleScanCodeEvent ( event ) ; if ( isNull ( msg ) ) { msg = processEventHandle ( event ) ; } } else if ( EventType . PICPHOTOORALBUM . equals ( eventType ) || EventType . PICSYSPHOTO . equals ( eventType ) || EventType . PICWEIXIN . equals ( eventType ) ) { String eventKey = ( String ) reqMap . get ( "EventKey" ) ; Map < String , Object > sendPicsInfo = ( Map < String , Object > ) reqMap . get ( "SendPicsInfo" ) ; int count = Integer . parseInt ( ( String ) sendPicsInfo . get ( "Count" ) ) ; List < Map > picList = ( List ) sendPicsInfo . get ( "PicList" ) ; SendPicsInfoEvent event = new SendPicsInfoEvent ( eventKey , count , picList ) ; buildBasicEvent ( reqMap , event ) ; msg = handlePSendPicsInfoEvent ( event ) ; if ( isNull ( msg ) ) { msg = processEventHandle ( event ) ; } } else if ( EventType . TEMPLATESENDJOBFINISH . equals ( eventType ) ) { String msgId = ( String ) reqMap . get ( "MsgID" ) ; String status = ( String ) reqMap . get ( "Status" ) ; TemplateMsgEvent event = new TemplateMsgEvent ( msgId , status ) ; buildBasicEvent ( reqMap , event ) ; msg = handleTemplateMsgEvent ( event ) ; if ( isNull ( msg ) ) { msg = processEventHandle ( event ) ; } } else if ( EventType . MASSSENDJOBFINISH . equals ( eventType ) ) { String msgId = ( String ) reqMap . get ( "MsgID" ) ; String status = ( String ) reqMap . get ( "Status" ) ; Integer TotalCount = Integer . valueOf ( String . valueOf ( reqMap . get ( "TotalCount" ) ) ) ; Integer filterCount = Integer . valueOf ( String . valueOf ( reqMap . get ( "FilterCount" ) ) ) ; Integer sentCount = Integer . valueOf ( String . valueOf ( reqMap . get ( "SentCount" ) ) ) ; Integer errorCount = Integer . valueOf ( String . valueOf ( reqMap . get ( "ErrorCount" ) ) ) ; SendMessageEvent event = new SendMessageEvent ( msgId , status , TotalCount , filterCount , sentCount , errorCount ) ; buildBasicEvent ( reqMap , event ) ; msg = callBackAllMessage ( event ) ; if ( isNull ( msg ) ) { msg = processEventHandle ( event ) ; } } } else { if ( msgType . equals ( ReqType . TEXT ) ) { String content = ( String ) reqMap . get ( "Content" ) ; LOG . debug ( "文本消息内容:{}" , content ) ; TextReqMsg textReqMsg = new TextReqMsg ( content ) ; buildBasicReqMsg ( reqMap , textReqMsg ) ; msg = handleTextMsg ( textReqMsg ) ; if ( isNull ( msg ) ) { msg = processMessageHandle ( textReqMsg ) ; } } else if ( msgType . equals ( ReqType . IMAGE ) ) { String picUrl = ( String ) reqMap . get ( "PicUrl" ) ; String mediaId = ( String ) reqMap . get ( "MediaId" ) ; ImageReqMsg imageReqMsg = new ImageReqMsg ( picUrl , mediaId ) ; buildBasicReqMsg ( reqMap , imageReqMsg ) ; msg = handleImageMsg ( imageReqMsg ) ; if ( isNull ( msg ) ) { msg = processMessageHandle ( imageReqMsg ) ; } } else if ( msgType . equals ( ReqType . VOICE ) ) { String format = ( String ) reqMap . get ( "Format" ) ; String mediaId = ( String ) reqMap . get ( "MediaId" ) ; String recognition = ( String ) reqMap . get ( "Recognition" ) ; VoiceReqMsg voiceReqMsg = new VoiceReqMsg ( mediaId , format , recognition ) ; buildBasicReqMsg ( reqMap , voiceReqMsg ) ; msg = handleVoiceMsg ( voiceReqMsg ) ; if ( isNull ( msg ) ) { msg = processMessageHandle ( voiceReqMsg ) ; } } else if ( msgType . equals ( ReqType . VIDEO ) ) { String thumbMediaId = ( String ) reqMap . get ( "ThumbMediaId" ) ; String mediaId = ( String ) reqMap . get ( "MediaId" ) ; VideoReqMsg videoReqMsg = new VideoReqMsg ( mediaId , thumbMediaId ) ; buildBasicReqMsg ( reqMap , videoReqMsg ) ; msg = handleVideoMsg ( videoReqMsg ) ; if ( isNull ( msg ) ) { msg = processMessageHandle ( videoReqMsg ) ; } } else if ( msgType . equals ( ReqType . SHORT_VIDEO ) ) { String thumbMediaId = ( String ) reqMap . get ( "ThumbMediaId" ) ; String mediaId = ( String ) reqMap . get ( "MediaId" ) ; VideoReqMsg videoReqMsg = new VideoReqMsg ( mediaId , thumbMediaId ) ; buildBasicReqMsg ( reqMap , videoReqMsg ) ; msg = hadnleShortVideoMsg ( videoReqMsg ) ; if ( isNull ( msg ) ) { msg = processMessageHandle ( videoReqMsg ) ; } } else if ( msgType . equals ( ReqType . LOCATION ) ) { double locationX = Double . parseDouble ( ( String ) reqMap . get ( "Location_X" ) ) ; double locationY = Double . parseDouble ( ( String ) reqMap . get ( "Location_Y" ) ) ; int scale = Integer . parseInt ( ( String ) reqMap . get ( "Scale" ) ) ; String label = ( String ) reqMap . get ( "Label" ) ; LocationReqMsg locationReqMsg = new LocationReqMsg ( locationX , locationY , scale , label ) ; buildBasicReqMsg ( reqMap , locationReqMsg ) ; msg = handleLocationMsg ( locationReqMsg ) ; if ( isNull ( msg ) ) { msg = processMessageHandle ( locationReqMsg ) ; } } else if ( msgType . equals ( ReqType . LINK ) ) { String title = ( String ) reqMap . get ( "Title" ) ; String description = ( String ) reqMap . get ( "Description" ) ; String url = ( String ) reqMap . get ( "Url" ) ; LOG . debug ( "链接消息地址:{}" , url ) ; LinkReqMsg linkReqMsg = new LinkReqMsg ( title , description , url ) ; buildBasicReqMsg ( reqMap , linkReqMsg ) ; msg = handleLinkMsg ( linkReqMsg ) ; if ( isNull ( msg ) ) { msg = processMessageHandle ( linkReqMsg ) ; } } } String result = "" ; if ( nonNull ( msg ) ) { msg . setFromUserName ( toUserName ) ; msg . setToUserName ( fromUserName ) ; result = msg . toXml ( ) ; if ( StrUtil . isNotBlank ( getAESKey ( ) ) ) { try { WXBizMsgCrypt pc = new WXBizMsgCrypt ( getToken ( ) , getAESKey ( ) , getAppId ( ) ) ; result = pc . encryptMsg ( result , request . getParameter ( "timestamp" ) , request . getParameter ( "nonce" ) ) ; LOG . debug ( "加密后密文:{}" , result ) ; } catch ( AesException e ) { LOG . error ( "加密异常" , e ) ; } } } return result ; }
处理微信服务器发来的请求方法

@param request http请求对象
@return 处理消息的结果，已经是接口要求的xml报文了