View Javadoc
1   package com.foxinmy.weixin4j.response;
2   
3   /**
4    * 回复音乐消息
5    * 
6    * @className MusicResponse
7    * @author jinyu(foxinmy@gmail.com)
8    * @date 2015年5月5日
9    * @since JDK 1.6
10   * @see
11   */
12  public class MusicResponse implements WeixinResponse {
13  
14  	/**
15  	 * 缩略图的媒体id,通过上传多媒体文件,得到的id
16  	 */
17  	private String thumbMediaId;
18  	/**
19  	 * 音乐标题
20  	 */
21  	private String title;
22  	/**
23  	 * 音乐描述
24  	 */
25  	private String desc;
26  	/**
27  	 * 音乐链接
28  	 */
29  	private String musicUrl;
30  	/**
31  	 * 高质量音乐链接,WIFI环境优先使用该链接播放音乐
32  	 */
33  	private String hqMusicUrl;
34  
35  	public MusicResponse(String thumbMediaId) {
36  		this.thumbMediaId = thumbMediaId;
37  	}
38  
39  	@Override
40  	public String toContent() {
41  		StringBuilder content = new StringBuilder();
42  		content.append("<Music>");
43  		content.append(String.format(
44  				"<ThumbMediaId><![CDATA[%s]]></ThumbMediaId>", thumbMediaId));
45  		content.append(String.format("<Title><![CDATA[%s]]></Title>",
46  				title != null ? title : ""));
47  		content.append(String.format(
48  				"<Description><![CDATA[%s]]></Description>",
49  				desc != null ? desc : ""));
50  		content.append(String.format("<MusicUrl><![CDATA[%s]]></MusicUrl>",
51  				musicUrl != null ? musicUrl : ""));
52  		content.append(String.format("<HQMusicUrl><![CDATA[%s]]></HQMusicUrl>",
53  				hqMusicUrl != null ? hqMusicUrl : ""));
54  		content.append("</Music>");
55  		return content.toString();
56  	}
57  
58  	public String getThumbMediaId() {
59  		return thumbMediaId;
60  	}
61  
62  	public String getMusicUrl() {
63  		return musicUrl;
64  	}
65  
66  	public void setMusicUrl(String musicUrl) {
67  		this.musicUrl = musicUrl;
68  	}
69  
70  	public String getHqMusicUrl() {
71  		return hqMusicUrl;
72  	}
73  
74  	public void setHqMusicUrl(String hqMusicUrl) {
75  		this.hqMusicUrl = hqMusicUrl;
76  	}
77  
78  	public String getTitle() {
79  		return title;
80  	}
81  
82  	public void setTitle(String title) {
83  		this.title = title;
84  	}
85  
86  	public String getDesc() {
87  		return desc;
88  	}
89  
90  	public void setDesc(String desc) {
91  		this.desc = desc;
92  	}
93  
94  	@Override
95  	public String getMsgType() {
96  		return "music";
97  	}
98  }