有输出xml文件,但是公众号不能提供服务,直接在地址栏上写music的url也不能找到音乐资源

/**

 * 音乐消息转为xml

 * @param newsMessage

 * @return

 */

public static String musicMessageToXml(MusicMessage musicMessage){

XStream xstream = new XStream();

xstream.alias("xml",musicMessage.getClass());//将xml的根节点改为xml,而不是包名类名

return xstream.toXML(musicMessage);

}

/**

 * 音乐消息的组装

 * @param fromUserName

 * @param toUserName

 * @return

 */

public static String initMusicMessage(String fromUserName,String toUserName){

String message=null;

MusicMessage musicMessage=new MusicMessage();//图文消息对象,该对象有消息体属性

Music music=new Music();

music.setTitle("音乐");

music.setDescription("好听的音乐");

music.setMusicURL("http://ghm.tunnel.mobi/Weixin/resource/See You Again.mp3");

music.setHQMusicUrl("http://ghm.tunnel.mobi/Weixin/resource/See You Again.mp3");

music.setThumbMediaId("yFcvFcHnli26TTtyDrqKVyUZL7dPTiaU5C4iv2DBwPvg4Of2v9TnKGBJ-OOG74x4");

musicMessage.setFromUserName(toUserName);

musicMessage.setToUserName(fromUserName);

musicMessage.setMusic(music);

musicMessage.setCreateTime(new Date().getTime()+"");

musicMessage.setMsgType(MESSAGE_MUSIC);

message=musicMessageToXml(musicMessage);//将消息转换为xml格式

return message;

}


输出的xml文件为:

<xml>

  <ToUserName>oTEV-wt2udKmZ0Ao8jcHA0BW6-9U</ToUserName>

  <FromUserName>gh_80f9f1461235</FromUserName>

  <CreateTime>1442297612460</CreateTime>

  <MsgType>music</MsgType>

  <Music>

    <Title>音乐</Title>

    <Description>好听的音乐</Description>

    <MusicURL>http://ghm.tunnel.mobi/Weixin/resource/See You Again.mp3</MusicURL>

    <HQMusicUrl>http://ghm.tunnel.mobi/Weixin/resource/See You Again.mp3</HQMusicUrl>

    <ThumbMediaId>yFcvFcHnli26TTtyDrqKVyUZL7dPTiaU5C4iv2DBwPvg4Of2v9TnKGBJ-OOG74x4</ThumbMediaId>

  </Music>

</xml>


silence1074563
浏览 1266回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java