Open
Description
QQ音乐API整理
最近准备用vue做个音乐播放器,网上找了找音乐API,看了一圈,还是QQ音乐最合适,这里做个整理
歌曲搜索
接口地址
var num = 3,
name = '王菲',
urlString = `http://s.music.qq.com/fcgi-bin/music_search_new_platform?t=0&n=${num}&aggr=1&cr=1&loginUin=0&format=json&inCharset=GB2312&outCharset=utf-8¬ice=0&platform=jqminiframe.json&needNewCode=0&p=1&catZhida=0&remoteplace=sizer.newclient.next_song&w=${name}`;
调用
//用了个PHP代理解决跨域问题
$.post("proxy.php", {
urlString
}, function(data) {
data = JSON.parse(data)
data['data']['song']['list'].forEach(
e => console.log(e['f'])
)
})
<?php
$url=$_POST['urlString'];
$res = file_get_contents($url);
echo $res;
?>
注释
num
:请求搜索的数量
name
:搜索的关键词
歌曲榜单
接口地址
// 新歌榜:http://music.qq.com/musicbox/shop/v3/data/hit/hit_newsong.js
// 总榜:http://music.qq.com/musicbox/shop/v3/data/hit/hit_all.js
调用
$.ajax({
type: "get",
async: false,
url: "http://music.qq.com/musicbox/shop/v3/data/hit/hit_newsong.js",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "JsonCallback",
scriptCharset: 'GBK',//设置编码,否则会乱码
success: function(data) {
console.log(JSON.stringify(data))
},
error: function() {
alert('fail');
}
});
注释
主要获取的是id
(歌曲id)、albumId
(图片id)
歌曲地址
接口地址
var id = 101369814,
src = `http://ws.stream.qqmusic.qq.com/${id}.m4a?fromtag=46`
调用
<audio src="http://ws.stream.qqmusic.qq.com/101369814.m4a?fromtag=46" controls></audio>
注释
没啥好说的。。
歌词地址
接口地址
var id = 101369814,
txt = `http://music.qq.com/miniportal/static/lyric/${id%100}/${id}.xml`;
调用
//用了个PHP代理解决跨域问题
$.post("proxy.php", {
txt
}, function(data) {
console.log(data)
})
<?php
$url=$_POST['txt'];
$res = file_get_contents($url);
$s = iconv('gbk','UTF-8',$res);//大坑,一是转编码,二是不能直接iconv输出,得有个变量转接
echo $s;
?>
注释
没啥说的
歌曲图片
接口地址
var image_id = 140820,
width = 300,
pic = `http://imgcache.qq.com/music/photo/album_${width}/${image_id%100}/${width}_albumpic_${image_id}_0.jpg`;
调用
<img src="http://imgcache.qq.com/music/photo/album_300/20/300_albumpic_140820_0.jpg" alt="">
注释
image_id
:图片id
width
:图片尺寸
Activity
hiyangguo commentedon Apr 10, 2017
👍
xue1234jun commentedon Apr 27, 2017
👍
ag2s20150909 commentedon May 2, 2017
大图api接口
$big_image_url="https://y.gtimg.cn/music/photo_new/T002R300x300M000".$image_id.".jpg";
ag2s20150909 commentedon May 2, 2017
小图api
$image_id=$msg[22];
$img_1=substr($image_id,strlen($image_id)-1,strlen($image_id));
$img_2=substr($image_id,strlen($image_id)-2,strlen($image_id));
$img_2=substr_replace($img_2,"",1,1);
$small_image_url="http://imgcache.qq.com/music/photo/mid_album_90/".$img_2."/".$img_1."/".$image_id.".jpg";
shihp commentedon Jul 28, 2017
请问现在的歌曲搜索 里面:
f: "108668363|丑八怪|5062|薛之谦|8623|空|1968648|228|1|1|0|0|3654071|128000|0|0|0|0|0|0|002uw2lS00iXS4|002J4UUk29y8BY|001ZaCQY2OxVMg|0|8013"
怎么理解呀?
ellyliang commentedon Aug 11, 2017
大神,大神,qq音乐的API可以设置音乐的音质么?正在寻求这个问题的解决方法