① 接口基础 GET
统一入口:index.php,所有接口均通过 source 参数切换平台,参数形式为 GET 查询串。
返回格式:统一 JSON,包含 code、text、type、now、data 字段。
{
"code": 200,
"text": "解析成功",
"type": "歌曲解析",
"now": "2026-08-05 12:00:00",
"data": [ ... ] // 列表或单曲对象
}
💡 支持 CORS 跨域(Access-Control-Allow-Origin:*),前端可直接 fetch 调用。
② 通用参数 全部接口
| 参数 | 说明 | 默认 |
source | 平台:netease / qq / kugou / kuwo | 必填 |
type | 解析类型(各平台不同,见下方接口表) | song |
msg | 搜索关键词(歌名 / MV名) | 必填 |
n | 歌曲序号,从 0 开始;不传=返回列表,传入=返回单曲播放直链 | — |
page | 页码 | 1 |
count | 每页数量 | 10~20 |
id | 歌曲ID / 歌单ID / rid(按平台而定) | — |
hash | 酷狗歌曲/MV hash | — |
auto | 外链播放器是否自动播放(0/1) | 0 |
③ 网易云音乐 netease
搜索
index.php?source=netease&type=song&msg=晴天
搜索歌曲;加 n 参数返回该歌曲的播放直链与专辑封面
可选:n、page、count
直链
index.php?source=netease&type=songid&id=316100
按歌曲 ID 直接获取播放链接
必填:id
随机
index.php?source=netease&type=random&id=3778678
歌单内随机一首歌(id 为空时默认热歌榜)
可选:id(歌单ID)
外链
index.php?source=netease&type=outchain&id=316100&auto=1
返回歌曲信息 + 播放直链 + 官方 iframe 外链播放器代码
必填:id;可选:auto(自动播放)
④ QQ音乐 qq
搜索
index.php?source=qq&type=song&msg=晴天
搜索歌曲,返回 songmid 与专辑封面;加 n 尝试解析播放直链(VIP歌曲可能受限)
可选:n、page、count
直链
index.php?source=qq&type=songid&id=songmid
按 songmid 获取播放链接
必填:id
💡 QQ音乐播放链接受官方接口风控,可能返回 null(提示付费歌曲或接口受限)
⑤ 酷狗音乐 kugou
搜索
index.php?source=kugou&type=song&msg=晴天
搜索歌曲,返回 hash 与专辑封面;加 n 返回播放直链
可选:n、page、count
MV
index.php?source=kugou&type=mv&msg=晴天
搜索 MV;加 n 返回 MV 播放地址
可选:n、page、count
歌曲解析
index.php?source=kugou&type=shash&hash=歌曲hash
按歌曲 hash 获取播放信息
必填:hash
MV解析
index.php?source=kugou&type=mhash&hash=MV hash
按 MV hash 获取视频信息
必填:hash
⑥ 酷我音乐 kuwo
搜索
index.php?source=kuwo&type=song&msg=晴天
搜索歌曲,返回 rid 与 VIP 标记;加 n 返回播放直链
可选:n、page、count
MV
index.php?source=kuwo&type=mv&msg=晴天
搜索 MV(当前接口可能受限)
可选:n、page、count
歌曲解析
index.php?source=kuwo&type=rid&id=MUSIC_495008567
按 rid 获取播放直链(无需 cookie)
必填:id
MV解析
index.php?source=kuwo&type=mid&id=MV mid
按 mid 获取 MV 信息(当前接口可能受限)
必填:id
⑦ 调用示例 JavaScript
搜索歌曲列表
// 搜索「晴天」返回列表
fetch('index.php?source=netease&type=song&msg=' + encodeURIComponent('晴天'))
.then(r => r.json())
.then(d => console.log(d.data)); // [{id,name,singername,album_img,vip}, ...]
播放歌曲(第 n 首)
// n 从 0 开始,返回单曲直链
fetch('index.php?source=netease&type=song&msg=' + encodeURIComponent('晴天') + '&n=0')
.then(r => r.json())
.then(d => { document.getElementById('audio').src = d.data.song_url; });
网易云外链播放器
// 一次拿到:封面 + 直链 + iframe 代码
fetch('index.php?source=netease&type=outchain&id=316100')
.then(r => r.json())
.then(d => {
console.log(d.data.album_img); // 专辑封面
console.log(d.data.song_url); // 播放直链
document.body.insertAdjacentHTML('beforeend', d.data.iframe); // 外链播放器
});
⑧ 常见问题 FAQ
Q:为什么搜索不到 / 返回「接口暂无响应」? 音乐平台接口偶尔风控,稍后重试或换平台。
Q:为什么有的歌曲播放不了? VIP 歌曲受版权保护无法获取免费直链,列表中已用 vip 标记标注。
Q:接口在服务器上怎么部署? 整个目录(index.php + api/ + assets/)上传到 PHP 7.0+ 环境即可,建议开启 curl 扩展。
Q:CORS 跨域? 已内置 Access-Control-Allow-Origin:*,前端可直接调用。
Music API · 仅供学习交流使用 ♪