QQ音樂API整理

QQ音樂API整理

blog
mdphp

最近準備用vue作個音樂播放器,網上找了找音樂API,看了一圈,仍是QQ音樂最合適,這裏作個整理html

歌曲搜索

接口地址

var num = 3,
    name = '王菲',
    urlString = `http://s.music.qq.com/fcgi-bin/music_search_new_platform?t=0&n=${num}&aggr=1&cr=1&loginUin=0&format=json&inCharset=GB2312&outCharset=utf-8&notice=0&platform=jqminiframe.json&needNewCode=0&p=1&catZhida=0&remoteplace=sizer.newclient.next_song&w=${name}`;

調用

//用了個PHP代理解決跨域問題
$.post("proxy.php", {
        urlString
      }, function(data) {
        data = JSON.parse(data)
        data['data']['song']['list'].forEach(
          e => console.log(e['f'])
        )
      })
<?php
$url=$_POST['urlString'];
$res = file_get_contents($url);
echo $res;
?>

註釋

num:請求搜索的數量vue

name:搜索的關鍵詞git

歌曲榜單

接口地址

// 新歌榜:http://music.qq.com/musicbox/shop/v3/data/hit/hit_newsong.js
// 總榜:http://music.qq.com/musicbox/shop/v3/data/hit/hit_all.js

調用

$.ajax({
  type: "get",
  async: false,
  url: "http://music.qq.com/musicbox/shop/v3/data/hit/hit_newsong.js",
  dataType: "jsonp",
  jsonp: "callback",
  jsonpCallback: "JsonCallback",
  scriptCharset: 'GBK',//設置編碼,不然會亂碼
  success: function(data) {
    console.log(JSON.stringify(data))
  },
  error: function() {
    alert('fail');
  }
});

註釋

主要獲取的是id(歌曲id)、albumId(圖片id)github

歌曲地址

接口地址

var id = 101369814,
    src = `http://ws.stream.qqmusic.qq.com/${id}.m4a?fromtag=46`

調用

<audio src="http://ws.stream.qqmusic.qq.com/101369814.m4a?fromtag=46" controls></audio>

註釋

沒啥好說的。。ajax

歌詞地址

接口地址

var id = 101369814,
    txt = `http://music.qq.com/miniportal/static/lyric/${id%100}/${id}.xml`;

調用

//用了個PHP代理解決跨域問題
$.post("proxy.php", {
        txt
      }, function(data) {
        console.log(data)
      })
<?php
$url=$_POST['txt'];
$res = file_get_contents($url);
$s = iconv('gbk','UTF-8',$res);//大坑,一是轉編碼,二是不能直接iconv輸出,得有個變量轉接
echo $s;
?>

註釋

沒啥說的json

歌曲圖片

接口地址

var image_id = 140820,
    width = 300,
    pic = `http://imgcache.qq.com/music/photo/album_${width}/${image_id%100}/${width}_albumpic_${image_id}_0.jpg`;

調用

<img src="http://imgcache.qq.com/music/photo/album_300/20/300_albumpic_140820_0.jpg" alt="">

註釋

image_id:圖片id跨域

width:圖片尺寸async

相關文章
相關標籤/搜索