利用axios僞造,抓取的網頁版qq音樂的接口,但這個接口有瑕疵...能獲取到Vkey,但不是每一首歌曲都能正常播放...後來發現網頁版音樂中每一個歌曲的播放地址的域名不是都同樣的,不能播放的歌曲有多是這個接口不對...還沒找到解決辦法
http://isure.stream.qqmusic.q...vue
song.js
webpack
export function createSong(musicData, songVkey) { return new Song({ id: musicData.songid, mid: musicData.songmid, singer: filterSinger(musicData.singer), name: musicData.songname, album: musicData.albumname, duration: musicData.interval, image: `https://y.gtimg.cn/music/photo_new/T002R300x300M000${musicData.albummid}.jpg?max_age=2592000`, url: `http://isure.stream.qqmusic.qq.com/C400${musicData.songmid}.m4a?guid=9244517832&vkey=${songVkey}&uin=0&fromtag=66` }) }
singer.js
ios
export function getSongVkey(songmid) { const url = '/api/getSongVkey' const data = Object.assign({}, commonParams, { songmid: songmid, notice: 0, platform: 'yqq.json', needNewCode: 0, format: 'json', data: {"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"9244517832","songmid":["001Qu4I30eVFYb"],"songtype":[0],"uin":"0","loginflag":1,"platform":"20"}},"comm":{"uin":0,"format":"json","ct":24,"cv":0}} }) return axios.get(url, { params: data }).then((res) => { return Promise.resolve(res.data) }) }
webpack.dev.config
web
app.get('/api/getSongVkey', function (req, res) { var url = 'https://u.y.qq.com/cgi-bin/musicu.fcg' axios.get(url, { headers: { referer: 'https://u.y.qq.com/', host: 'u.y.qq.com' }, params: req.query }).then((response) => { res.json(response.data) }).catch((e) => { console.log(e) }) })
singer-detail
express
_normallizeSongs(list, callback) { let ret = [] let index = 1 list.forEach((item) => { let {musicData} = item // 獲得music對象 if (musicData.songid && musicData.albummid) { getSongVkey(musicData.songmid).then((res) => { if (res.code === ERR_OK) { const sVkey = res.req_0.data.midurlinfo[0] const songVkey = sVkey.vkey const newSong = createSong(musicData, songVkey) console.log(newSong) ret.push(newSong) if (index === list.length) { callback && callback(ret) } index ++ } }) } }) }
這個是抓取的是h5版qq音樂的jsonp接口singer.js
json
export function getSongVkey(songmid) { const url = 'https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg' const data = Object.assign({}, { callback: 'musicJsonCallback', loginUin: 3051522991, format: 'jsonp', platform: 'yqq', needNewCode: 0, cid: 205361747, uin: 3051522991, guid: 5931742855, songmid: songmid, filename: `C400${songmid}.m4a` })
song.js
axios
export function createSong(musicData, songVkey) { return new Song({ id: musicData.songid, mid: musicData.songmid, singer: filterSinger(musicData.singer), name: musicData.songname, album: musicData.albumname, duration: musicData.interval, image: `https://y.gtimg.cn/music/photo_new/T002R300x300M000${musicData.albummid}.jpg?max_age=2592000`, url: `http://dl.stream.qqmusic.qq.com/C400${musicData.songmid}.m4a?fromtag=38&guid=5931742855&vkey=${songVkey}` }) }
singer-detail
api
_normallizeSongs(list) { let ret = [] list.forEach((item) => { let {musicData} = item // 獲得music對象 getSongVkey(musicData.songmid).then((res) => { const songVkey = res.data.items[0].vkey if (musicData.songid && musicData.albummid) { ret.push(createSong(musicData, songVkey)) } }) }) console.log(ret) return ret }