QQ音乐接口集合–javascript
以下接口仅供测试开发
通用配置
const option = {g_tk: 5381,loginUin: 0,hostUin: 0,notice: 0,uin: 0,format: 'json',inCharset: 'utf8',outCharset: 'utf-8',platform: 'yqq.json',needNewCode: 0
}
通用接口
https://u.y.qq.com/cgi-bin/musicu.fcg
data参数说明
数据格式如下
{ g_tk: 5381,loginUin: 0,hostUin: 0,notice: 0,uin: 0,format: 'json',inCharset: 'utf8',outCharset: 'utf-8',platform: 'yqq.json',needNewCode: 0,'-': 'recom2467930613445628',data:{ {"comm": {"ct": 24},"category": { //分类"method": "get_hot_category","param": {"qq": ""},"module": "music.web_category_svr"},"recomPlaylist": {//歌单推荐"method": "get_hot_recommend","param": {"async": 1,"cmd": 2},"module": "playlist.HotRecommendServer"},"playlist": {//播放列表"method": "get_playlist_by_category","param": {"id": 8,"curPage": 1,"size": 40,"order": 5,"titleid": 8},"module": "playlist.PlayListPlazaServer"},"new_song": {//新歌推送"module": "newsong.NewSongServer","method": "get_new_song_info","param": {"type": 5}},"new_album": {//新碟首发"module": "newalbum.NewAlbumServer","method": "get_new_album_info","param": {"area": 1,"sin": 0,"num": 10}},"new_album_tag": {//新碟首发分类"module": "newalbum.NewAlbumServer","method": "get_new_album_area","param": {}},"toplist": {//热门"module": "musicToplist.ToplistInfoServer","method": "GetAll","param": {}},"focus": {//精彩推荐--轮播图"module": "QQMusic.MusichallServer","method": "GetFocus","param": {}}} }
jsonp数据格式处理
//处理jsonp格式;var data = response.data;const reg = /^\w+\(({.+})\)$/;const matches = data.match(reg);const output = JSON.parse(matches[1]);res.json(output.cdlist[0])//返回数据
1.精彩推荐–轮播图
请求接口
https://u.y.qq.com/cgi-bin/musicu.fcg
data数据
var dataChild = {focus: {module: "QQMusic.MusichallServer",method: "GetFocus",param: {}}}var data = Object.assign({}, option,{"-": "recom" + (Math.random() + "").replace("0.", ""),data:dataChild});
请求headers
headers: {'Referer': 'https://y.qq.com','Origin': 'https://y.qq.com',}
请求事例
/** 1、* 轮播* @return [{picUrl: 图片,type: 类型,albummid: 歌曲id}]* @getCarouselList*/
apiRoutes.get('/getCarouselList', function (req, res) {var url = 'https://u.y.qq.com/cgi-bin/musicu.fcg';var dataChild = {comm,focus: {module: "QQMusic.MusichallServer",method: "GetFocus",param: {}}}dataChild = JSON.stringify(dataChild)var data = {"-": "recom" + (Math.random() + "").replace("0.", ""),data:dataChild}data = Object.assign({}, option, data);axios.get(url, {headers: {'Referer': 'https://y.qq.com','Origin': 'https://y.qq.com',},params: data,}).then(function(response) {res.json(response.data)}).catch(function(e){console.log(e)})
});
2.推荐歌曲
/** * 推荐歌曲* @param {sin:开始位置,end:结束位置}* @return [{imgurl: 图片,dissname: 名称,listenNum: 歌曲播放数量,dissid:歌曲id}]*/
请求接口
https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg
data数据
var data = Object.assign({},option,{platform:'yqq',picmid:1,sin:req.query.sin ? req.query.sin :0 ,//歌曲开始位置ein:req.query.end ? req.query.end :60,//歌曲结束位置sortId:5,categoryId:10000000,rnd:Math.random(),});
3.获取推荐歌曲详细列表
/** * * @param {dissid:歌曲id}* @return jsonp => songlist:[]*/
data数据
var data = Object.assign({}, option, {"disstid":歌曲dissid,"type" : 1,"json" : 1,"utf8" : 1,"onlysong" : 0,"platform" : "yqq","g_tk" : 1928093487,"format" : "jsonp"});
headers
headers: {'referer':'https://c.y.qq.com/','host':'c.y.qq.com'},
4.排行榜
/**
* return topid 排行id
*/
请求接口
https://c.y.qq.com/v8/fcg-bin/fcg_myqq_toplist.fcg
data数据
var data = Object.assign({}, option, {uin: 0,needNewCode: 1,platform: 'h5',g_tk: 1928093487,
});
headers
headers: {'referer':'https://c.y.qq.com/','host':'c.y.qq.com'},
5.排行榜详情
/**
* params {topid:排行榜id}
* return 详情
*/
请求接口
https://c.y.qq.com/v8/fcg-bin/fcg_v8_toplist_cp.fcg
data数据
var topid = req.query.topid;//排行榜idvar data = Object.assign({}, option, {uin: 0,needNewCode: 1,platform: 'h5',g_tk: 1928093487,topid:topid
});
6.热门搜索列表
请求接口
https://c.y.qq.com/splcloud/fcgi-bin/gethotkey.fcg
data数据
var data = Object.assign({}, option, {uin: 0,needNewCode: 1,platform: 'h5',g_tk: 1928093487
});
headers
headers: {'referer':'https://c.y.qq.com/','host':'c.y.qq.com'},
7.搜索歌曲
/**
* params {keyword:关键字,page:分页}
*/
请求接口
https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp
data数据
var keyword = req.query.keyword;//关键字var page = req.query.page;//分页var data = {w: keyword,p: page,perpage:20,n: 20,catZhida: 1,zhidaqu: 1,t: 0,flag: 1,ie: 'utf-8',sem: 1,aggr: 0,remoteplace: 'txt.mqq.all',uin: 0,needNewCode: 1,platform: 'h5'};data = Object.assign({}, option, data);
headers
headers: {'referer':'https://c.y.qq.com/','host':'c.y.qq.com'},
8.搜索专辑、歌曲(备用接口)
/** * params {type:类型,keyword:关键字}*/
请求接口
https://c.y.qq.com/soso/fcgi-bin/client_search_cp
data数据
/*** params {* type :搜索类型* album:专辑 ; mv:mv;song:歌曲* recommend:推荐* }*/var type = req.query.type || 'song';var searchid = type == 'song' ? 3 : type == 'album' ? 4 : 7;var t = type == 'song' ? 0 : type == 'album' ? 8 : 12;var recommend = req.query.recommend || false;var data = {ct: 24,qqmusic_ver: 1298,remoteplace: 'txt.yqq.'+type,searchid: sessionIdGenerator.get(searchid),aggr: 0,catZhida: recommend,lossless: 0,sem: 1,t: t,p: page,n: limit,w: keyword,};data = Object.assign({}, option, data);
headers
headers: {'referer':'https://c.y.qq.com/','host':'c.y.qq.com'},
9.歌曲播放地址
/** * @params [ songmid:歌曲ID ]* @return {歌曲信息}*/
请求接口
https://u.y.qq.com/cgi-bin/musicu.fcg
var t = (new Date).getUTCMilliseconds()var jsonData = JSON.parse(req.query.songmid)var guid = '' + Math.round(2147483647 * Math.random()) * t % 1e10var songtype = new Array(jsonData.length).fill(0);var data = {"-": "recom" + (Math.random() + "").replace("0.", ""),data:{comm,url_mid: {"module": "vkey.GetVkeyServer","method": "CgiGetVkey","param": {"guid": guid,"songmid": jsonData,"songtype": songtype,"uin": '0',"loginflag": 0,"platform": '23'}}}}data = Object.assign({},option,data);
headers
headers: {referer: 'https://y.qq.com/',origin: 'https://y.qq.com','Content-type': 'application/x-www-form-urlencoded'},
10.歌曲歌词
/** * @params {* songmid:歌曲ID* }* @return {lyric:歌词}*/
请求接口
https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg
data数据
const data =Object.assign({},option,{songmid:req.query.songmid,pcachetime:new Date(),platform:'yqq',hostUin:0,needNewCode:0,format:'json',categoryId: 10000000,})
headers
headers:{referer:'https://c.y.qq.com/',host:'c.y.qq.com'},
11.热门mv
请求接口
https://c.y.qq.com/mv/fcgi-bin/getmv_by_tag
data数据
const data = Object.assign({},option,{cmd: 'shoubo',lan: 'all',sin:20,num:20})
headers
headers:{referer:'https://c.y.qq.com/',host:'c.y.qq.com'},
12.mv播放地址
/** * @params * [mvMid]* @return {歌曲地址}*/
请求接口
https://u.y.qq.com/cgi-bin/musicu.fcg
data数据
var mvMid = req.query.mvMidvar data = {data: {"getMvUrl": {"module": "gosrf.Stream.MvUrlProxy","method": "GetMvUrls","param": {"vids": [mvMid],//["d00300szwxf"],"request_typet": 10001}}},g_tk: 5381,callback: "jQuery" + ("1.12.3" + Math.random()).replace(/\D/g, "") + '_' + new Date().getTime(),//'jQuery112307530572030680409_1559215268063',format: 'jsonp',inCharset: 'utf8',outCharset: 'GB2312',platform: 'yqq',}data = Object.assign({},option,data);
headers
headers: {referer: 'https://y.qq.com/',origin: 'https://y.qq.com','Content-type': 'application/x-www-form-urlencoded'},