话不多说
PC客户端抓包而来
0.说明
关于头部信息
上面是抓到的信息,其中必要的只有cookie中的appver。而且如果要调用api,必须加上Referer,只要是music.163.com的就可以
1
2
|
Cookie: appver=1.5.0.75771;
Referer: http://music.163.com/
|
以上两条即可
返回的格式均为json
1.搜索
抓取到的信息如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
Full request URI:http://music.163.com/api/search/pc
Key: hlpretag
Value:
Key: hlposttag
Value:
Key: s
Value: \345\226\234\346\254\242\344\275\240
Key: offset
Value: 0
Key: total
Value: true
Key: limit
Value: 100
Key: type
Value: 1
|
URL:
POST http://music.163.com/api/search/pc
必要参数:
s:搜索的内容
offset:偏移量(分页用)
limit:获取的数量
type:搜索的类型
歌曲 1
专辑 10
歌手 100
歌单 1000
用户 1002
mv 1004
歌词 1006
主播电台 1009
2.歌曲信息
1
|
Full request URI: http://music.163.com/api/song/detail/?id=28377211&ids=%5B28377211%5D
|
URL:
GET http://music.163.com/api/song/detail/
必要参数:
id:歌曲ID
ids:不知道干什么用的,用[]括起来的歌曲ID
3.歌手专辑
1
|
Full request URI: http://music.163.com/api/artist/albums/166009?id=166009&offset=0&total=true&limit=5
|
URL:
GET http://music.163.com/api/artist/albums/歌手ID
必要参数:
limit:获取的数量(不知道为什么这个必须加上)
4.专辑信息
1
|
Full request URI: http://music.163.com/api/album/2457012?ext=true&id=2457012&offset=0&total=true&limit=10
|
URL:
GET http://music.163.com/api/album/专辑ID
5.歌单
1
|
Full request URI: http://music.163.com/api/playlist/detail?id=37880978&updateTime=-1
|
URL:
GET http://music.163.com/api/playlist/detail
必要参数:
id:歌单ID
6.歌词
1
|
Full request URI: http://music.163.com/api/song/lyric?os=pc&id=93920&lv=-1&kv=-1&tv=-1
|
URL:
GET http://music.163.com/api/song/lyric
必要参数:
id:歌曲ID
lv:值为-1,我猜测应该是判断是否搜索lyric格式
kv:值为-1,这个值貌似并不影响结果,意义不明
tv:值为-1,是否搜索tlyric格式
7.MV
1
|
Full request URI: http://music.163.com/api/mv/detail?id=319104&type=mp4
|
URL:
GET http://music.163.com/api/mv/detail
必要参数:
id:mvid
type:值为mp4,视频格式,不清楚还有没有别的格式
PHP版使用示例
{
$url = “http://music.163.com/api/search/pc”;
$post_data = array(
‘s’ => $word,
‘offset’ => ‘0’,
‘limit’ => ‘20’,
‘type’ => $type,
);
$referrer = “http://music.163.com/”;
$URL_Info = parse_url($url);
$values = [];
$result = ”;
$request = ”;
foreach ($post_data as $key => $value) {
$values[] = "$key=” . urlencode($value);
}
$data_string = implode("&", $values);
if (!isset($URL_Info[“port”])) {
$URL_Info[“port”] = 80;
}
$request .= "POST " . $URL_Info[“path”] . ” HTTP/1.1\n”;
$request .= "Host: " . $URL_Info[“host”] . “\n”;
$request .= "Referer: $referrer\n”;
$request .= “Content-type: application/x-www-form-urlencoded\n”;
$request .= "Content-length: " . strlen($data_string) . “\n”;
$request .= “Connection: close\n”;
$request .= “Cookie: ” . “appver=1.5.0.75771;\n”;
$request .= “\n”;
$request .= $data_string . “\n”;
$fp = fsockopen($URL_Info[“host”], $URL_Info[“port”]);
fputs($fp, $request);
$i = 1;
while (!feof($fp)) {
if ($i >= 15) {
$result .= fgets($fp);
} else {
fgets($fp);
$i++;
}
}
fclose($fp);
return $result;
}
function get_music_info( type){ $url = “http://music.163.com/api/search/pc”; $post_data = array( ‘s’ => $word, ‘offset’ => ‘0’, ‘limit’ => ‘20’, ‘type’ => $type, ); $referrer = “http://music.163.com/”; $URL_Info = parse_url($url); $values = []; $result = ”; $request = ”; foreach ($post_data as $key => $value) { $values[] = "$key=” . urlencode($value); } $data_string = implode("&", $values); if (!isset($URL_Info[“port”])) { $URL_Info[“port”] = 80; } $request .= "POST " . $URL_Info[“path”] . ” HTTP/1.1\n”; $request .= "Host: " . $URL_Info[“host”] . “\n”; $request .= "Referer: $referrer\n”; $request .= “Content-type: application/x-www-form-urlencoded\n”; $request .= "Content-length: " . strlen($data_string) . “\n”; $request .= “Connection: close\n”; $request .= “Cookie: ” . “appver=1.5.0.75771;\n”; $request .= “\n”; $request .= $data_string . “\n”; $fp = fsockopen($URL_Info[“host”], $URL_Info[“port”]); fputs($fp, $request); $i = 1; while (!feof($fp)) { if ($i >= 15) { $result .= fgets($fp); } else { fgets($fp); $i++; } } fclose($fp); return $result;}function get_music_info( music_id) { url="http://music.163.com/api/song/detail/?id=". u r l =" h t t p : / / m u s i c .163 . c o m / a p i / s o n g / d e t a i l / ? i d =" . music_id . “&ids=%5B” . musicid.“returncurlget( m u s i c i d . “ r e t u r n c u r l g e t ( url); } function get_artist_album( artistid, a r t i s t i d , limit) { url="http://music.163.com/api/artist/albums/". u r l =" h t t p : / / m u s i c .163 . c o m / a p i / a r t i s t / a l b u m s / " . artist_id . “?limit=” . limit;returncurlget( l i m i t ; r e t u r n c u r l g e t ( url); } function get_album_info( albumid)$url="http://music.163.com/api/album/".$albumid;returncurlget($url);functiongetplaylistinfo( a l b u m i d ) $ u r l =" h t t p : / / m u s i c .163 . c o m / a p i / a l b u m / " . $ a l b u m i d ; r e t u r n c u r l g e t ( $ u r l ) ; f u n c t i o n g e t p l a y l i s t i n f o ( playlist_id) { url="http://music.163.com/api/playlist/detail?id=". u r l =" h t t p : / / m u s i c .163 . c o m / a p i / p l a y l i s t / d e t a i l ? i d =" . playlist_id; return curl_get( url);
}
function get_music_lyric( url);}function get_music_lyric( music_id) { url = "http://music.163.com/api/song/lyric?os=pc&id=" . url = "http://music.163.com/api/song/lyric?os=pc&id=" . music_id . “&lv=-1&kv=-1&tv=-1”; return curl_get( url);
}
function get_mv_info()
{ url);}function get_mv_info(){ url = “http://music.163.com/api/mv/detail?id=319104&type=mp4”; return curl_get($url); }