<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[music]]></MsgType>
<Music>
<Title><![CDATA[TITLE]]></Title>
<Description><![CDATA[DESCRIPTION]]></Description>
<MusicUrl><![CDATA[MUSIC_Url]]></MusicUrl>
<HQMusicUrl><![CDATA[HQ_MUSIC_Url]]></HQMusicUrl>
<ThumbMediaId><![CDATA[media_id]]></ThumbMediaId>
</Music>
</xml>
回复格式中字段说明:
Title | 标题 |
Description | 描述 |
MusicUrl | 音乐文件地址 |
HQMusicUrl | 高质量音乐链接,WIFI环境优先使用该链接播放音乐 |
ThumbMediaId | 缩略图资源,也是要上传到服务器,和图片的MediaId一样 该资源未生效,不知为何,有知道的朋友可以告知一下。 |
两个音乐链接必须填写。
增加“音乐”菜单,并定义key值。参照《创建菜单》
{
"type":"click",
"name":"音乐",
"key":"mh004"
}
修改WXMessgeBean。
@XmlRootElement(name="xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class WXMessgeBean {
......
private MusicMessage Music;
......
public MusicMessage getMusic() {
return Music;
}
public void setMusic(MusicMessage music) {
Music = music;
}
//增加音乐消息Bean
public static class MusicMessage{
private String title;
private String description;
private String musicUrl;
private String hQMusicUrl;
private String thumbMediaId;
public String getTitle() {
return title;
}
@XmlElement(name = "Title")
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
@XmlElement(name = "Description")
public void setDescription(String description) {
this.description = description;
}
public String getMusicUrl() {
return musicUrl;
}
@XmlElement(name = "MusicUrl")
public void setMusicUrl(String musicUrl) {
this.musicUrl = musicUrl;
}
public String gethQMusicUrl() {
return hQMusicUrl;
}
@XmlElement(name = "HQMusicUrl")
public void sethQMusicUrl(String hQMusicUrl) {
this.hQMusicUrl = hQMusicUrl;
}
public String getThumbMediaId() {
return thumbMediaId;
}
@XmlElement(name = "ThumbMediaId")
public void setThumbMediaId(String thumbMediaId) {
this.thumbMediaId = thumbMediaId;
}
}
}
回复代码(音乐处理部分):
else if (wxMessgeBean.getEventKey().equals("mh004")){
bean.setMsgType("music");
bean.setMusic(new WXMessgeBean.MusicMessage());
bean.getMusic().setTitle("吴青峰");
bean.getMusic().setDescription("歌曲-起风了");
bean.getMusic().setMusicUrl("http://yraupc.natappfree.cc/wind.mp3");
bean.getMusic().sethQMusicUrl("http://yraupc.natappfree.cc/wind.mp3");
bean.getMusic().setThumbMediaId("tMTFqPwg6c4fokYu8BKAXsNKHwjI2y4YqgGmQYT38xktk9P8dMJpDQEe9yT6vW5Q");
}
这里的音乐地址使用NATAPP内网穿透模拟的,不是公网上的。效果如图: