android网易云音乐api调用,网易云音乐常用API浅析 – Moonlib
話不多說
PC客戶端抓包而來
0.說明
關于頭部信息
1
2
Cookie: os=pc; deviceId=B55AC773505E5606F9D355A1A15553CE78B89FC7D8CB8A157B84; osver=Microsoft-Windows-8-Professional-build-9200-64bit; appver=1.5.0.75771; usertrack=ezq0alR0yqJMJC0dr9tEAg==; MUSIC_A=088a57b553bd8cef58487f9d01ae
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.138 Safari/537.36\r\n
上面是抓到的信息,其中必要的只有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版使用示例
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Created by PhpStorm.
* User: Moon
* Date: 2014/11/26 0026
* Time: 2:06
*/
function curl_get($url)
{
$refer = "http://music.163.com/";
$header[] = "Cookie: " . "appver=1.5.0.75771;";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, $refer);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function music_search($word, $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=" . $music_id . "&ids=%5B" . $music_id . "%5D";
return curl_get($url);
}
function get_artist_album($artist_id, $limit)
{
$url = "http://music.163.com/api/artist/albums/" . $artist_id . "?limit=" . $limit;
return curl_get($url);
}
function get_album_info($album_id)
{
$url = "http://music.163.com/api/album/" . $album_id;
return curl_get($url);
}
function get_playlist_info($playlist_id)
{
$url = "http://music.163.com/api/playlist/detail?id=" . $playlist_id;
return curl_get($url);
}
function get_music_lyric($music_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 = "http://music.163.com/api/mv/detail?id=319104&type=mp4";
return curl_get($url);
}
#echo music_search("Moon Without The Stars", "1");
#get_music_info("28949444");
#echo get_artist_album("166009", "5");
#echo get_album_info("3021064");
#echo get_playlist_info("22320356");
#echo get_music_lyric("29567020");
#echo get_mv_info();
PS:搜索的接口我用CURL調用失敗,原因未知,于是搜索是用文件操作實現的
總結
以上是生活随笔為你收集整理的android网易云音乐api调用,网易云音乐常用API浅析 – Moonlib的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 面向对象(二)——三大特性(封装、继承、
- 下一篇: c语言编写单片机技巧