public static void asXml(Writer writer, WxOutMsg msg) {
        try {
            Writer _out = writer;
            if (DEV_MODE) {
                writer = new StringWriter();
            }
            writer.write("<xml>\n");
            writer.write(tag("ToUserName", cdata(msg.getToUserName())));
            writer.write(tag("FromUserName", cdata(msg.getFromUserName())));
            writer.write(tag("CreateTime", "" + msg.getCreateTime()));
            writer.write(tag("MsgType", cdata(msg.getMsgType())));
            switch (WxMsgType.valueOf(msg.getMsgType())) {
            case text:
                writer.write(tag("Content", cdata(msg.getContent())));
                break;
            case image:
                writer.write(tag("Image", tag("MediaId", msg.getImage().getMediaId())));
                break;
            case voice:
                writer.write(tag("Voice", tag("MediaId", msg.getVoice().getMediaId())));
                break;
            case video:
                writer.write("<Video>\n");
                writer.write(tag("MediaId", cdata(msg.getVideo().getMediaId())));
                if (msg.getVideo().getTitle() != null)
                    writer.write(tag("Title", cdata(msg.getVideo().getTitle())));
                if (msg.getVideo().getDescription() != null)
                    writer.write(tag("Description", cdata(msg.getVideo().getDescription())));
                writer.write("</Video>\n");
                break;
            case music:
                writer.write("<Music>\n");
                WxMusic music = msg.getMusic();
                if (music.getTitle() != null)
                    writer.write(tag("Title", cdata(music.getTitle())));
                if (music.getDescription() != null)
                    writer.write(tag("Description", cdata(music.getDescription())));
                if (music.getMusicUrl() != null)
                    writer.write(tag("MusicUrl", cdata(music.getMusicUrl())));
                if (music.getHQMusicUrl() != null)
                    writer.write(tag("HQMusicUrl", cdata(music.getHQMusicUrl())));
                writer.write(tag("ThumbMediaId", cdata(music.getThumbMediaId())));
                writer.write("</Music>\n");
                break;
            case news:
                writer.write(tag("ArticleCount", "" + msg.getArticles().size()));
                writer.write("<Articles>\n");
                for (WxArticle article : msg.getArticles()) {
                    writer.write("<item>\n");
                    if (article.getTitle() != null)
                        writer.write(tag("Title", cdata(article.getTitle())));
                    if (article.getDescription() != null)
                        writer.write(tag("Description", cdata(article.getDescription())));
                    if (article.getPicUrl() != null)
                        writer.write(tag("PicUrl", cdata(article.getPicUrl())));
                    if (article.getUrl() != null)
                        writer.write(tag("Url", cdata(article.getUrl())));
                    writer.write("</item>\n");
                }
                writer.write("</Articles>\n");
                break;
            case transfer_customer_service:
                if (msg.getKfAccount() != null) {
                    writer.write("<TransInfo>\n");
                    writer.write(tag("KfAccount", cdata(msg.getKfAccount().getAccount())));
                    writer.write("</TransInfo>\n");
                }
                break;
            default:
                break;
            }
            writer.write("</xml>");
            if (DEV_MODE) {
                String str = writer.toString();
                log.debug("Outcome >>\n" + str);
                _out.write(str);
            }
        }
        catch (IOException e) {
            throw Lang.wrapThrow(e);
        }
    }
public static void asXml ( Writer writer , WxOutMsg msg ) { try { Writer _out = writer ; if ( DEV_MODE ) { writer = new StringWriter ( ) ; } writer . write ( "<xml>\n" ) ; writer . write ( tag ( "ToUserName" , cdata ( msg . getToUserName ( ) ) ) ) ; writer . write ( tag ( "FromUserName" , cdata ( msg . getFromUserName ( ) ) ) ) ; writer . write ( tag ( "CreateTime" , "" + msg . getCreateTime ( ) ) ) ; writer . write ( tag ( "MsgType" , cdata ( msg . getMsgType ( ) ) ) ) ; switch ( WxMsgType . valueOf ( msg . getMsgType ( ) ) ) { case text : writer . write ( tag ( "Content" , cdata ( msg . getContent ( ) ) ) ) ; break ; case image : writer . write ( tag ( "Image" , tag ( "MediaId" , msg . getImage ( ) . getMediaId ( ) ) ) ) ; break ; case voice : writer . write ( tag ( "Voice" , tag ( "MediaId" , msg . getVoice ( ) . getMediaId ( ) ) ) ) ; break ; case video : writer . write ( "<Video>\n" ) ; writer . write ( tag ( "MediaId" , cdata ( msg . getVideo ( ) . getMediaId ( ) ) ) ) ; if ( msg . getVideo ( ) . getTitle ( ) != null ) writer . write ( tag ( "Title" , cdata ( msg . getVideo ( ) . getTitle ( ) ) ) ) ; if ( msg . getVideo ( ) . getDescription ( ) != null ) writer . write ( tag ( "Description" , cdata ( msg . getVideo ( ) . getDescription ( ) ) ) ) ; writer . write ( "</Video>\n" ) ; break ; case music : writer . write ( "<Music>\n" ) ; WxMusic music = msg . getMusic ( ) ; if ( music . getTitle ( ) != null ) writer . write ( tag ( "Title" , cdata ( music . getTitle ( ) ) ) ) ; if ( music . getDescription ( ) != null ) writer . write ( tag ( "Description" , cdata ( music . getDescription ( ) ) ) ) ; if ( music . getMusicUrl ( ) != null ) writer . write ( tag ( "MusicUrl" , cdata ( music . getMusicUrl ( ) ) ) ) ; if ( music . getHQMusicUrl ( ) != null ) writer . write ( tag ( "HQMusicUrl" , cdata ( music . getHQMusicUrl ( ) ) ) ) ; writer . write ( tag ( "ThumbMediaId" , cdata ( music . getThumbMediaId ( ) ) ) ) ; writer . write ( "</Music>\n" ) ; break ; case news : writer . write ( tag ( "ArticleCount" , "" + msg . getArticles ( ) . size ( ) ) ) ; writer . write ( "<Articles>\n" ) ; for ( WxArticle article : msg . getArticles ( ) ) { writer . write ( "<item>\n" ) ; if ( article . getTitle ( ) != null ) writer . write ( tag ( "Title" , cdata ( article . getTitle ( ) ) ) ) ; if ( article . getDescription ( ) != null ) writer . write ( tag ( "Description" , cdata ( article . getDescription ( ) ) ) ) ; if ( article . getPicUrl ( ) != null ) writer . write ( tag ( "PicUrl" , cdata ( article . getPicUrl ( ) ) ) ) ; if ( article . getUrl ( ) != null ) writer . write ( tag ( "Url" , cdata ( article . getUrl ( ) ) ) ) ; writer . write ( "</item>\n" ) ; } writer . write ( "</Articles>\n" ) ; break ; case transfer_customer_service : if ( msg . getKfAccount ( ) != null ) { writer . write ( "<TransInfo>\n" ) ; writer . write ( tag ( "KfAccount" , cdata ( msg . getKfAccount ( ) . getAccount ( ) ) ) ) ; writer . write ( "</TransInfo>\n" ) ; } break ; default : break ; } writer . write ( "</xml>" ) ; if ( DEV_MODE ) { String str = writer . toString ( ) ; log . debug ( "Outcome >>\n" + str ) ; _out . write ( str ) ; } } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } }
将一个WxOutMsg转为被动响应所需要的XML文本

@param msg
微信消息输出对象

@return 输出的 XML 文本