欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

QQ音乐vkey获取,更新播放url

程序员文章站 2022-05-11 14:23:52
QQ音乐接口播放经常换, 最开始 url: `http://ws.stream.qqmusic.qq.com/${musicData.songid}.m4a?fromtag=46` 然后 url:`http://ws.stream.qqmusic.qq.com/C100${musicData.son ......

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}`
    })
}

调用调试完成!