QQ音樂vkey獲取,更新播放url
阿新 • • 發佈:2018-11-20
QQ音樂介面播放經常換,
最開始
url: `http://ws.stream.qqmusic.qq.com/${musicData.songid}.m4a?fromtag=46`
然後
url:`http://ws.stream.qqmusic.qq.com/C100${musicData.songmid}.m4a?fromtag=0&guid=126548448`
現在
url: `http://dl.stream.qqmusic.qq.com/C400${musicData.songmid}.m4a?fromtag=38&guid=5931742855&vkey=${vkey}`
vkey的獲取
// 獲取歌曲的vkey 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` }) return jsonp(url, data) }
呼叫
//重組 res.data.list 資料,只拿需要的 _formatSongs(list){ let result = [] list.forEach((item)=>{ // console.log('item',item) // 解構賦值-拿到item 下的 musicData 列表資料 let {musicData} = item //------------- 更新的加上vkey getSongVkey(musicData.songmid).then((res) => { const vkey= res.data.items[0].vkey; if (musicData.songid && musicData.albummid) { result.push(CreatSong(musicData, vkey)) } }) //------------- // console.log('musicData',musicData) // if(musicData.songid && musicData.albummid){ // result.push(CreatSong(musicData)) // } }) return result }
export function CreatSong(musicData,vkey){ //加了一個傳參和更新了url return new Song({ id: musicData.songid, mid: musicData.songmid, singer: filterSinger(musicData.singer),//filterSinger 中處理一遍 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=${vkey}` }) }
呼叫除錯完成!