qq音乐常用接口整理——亲测可用

xiaoxiao2021-02-28  161

1. 搜索音乐——可以获取歌曲id,歌手,专辑名,歌曲图片id等等等...

var urlString = 'http://s.music.qq.com/fcgi-bin/music_search_new_platform?t=0&n='+number+'&aggr=1&cr=1&loginUin=0&format=json&inCharset=GB2312&outCharset=utf-8¬ice=0&platform=jqminiframe.json&needNewCode=0&p=1&catZhida=0&remoteplace=sizer.newclient.next_song&w='+name; 注释:number为搜索数目量,name为搜索关键词(一般为歌曲名或歌手)

这里需要用到一个代理

<?php //搜索 $url=$_POST['urlString']; $res = file_get_contents($url); echo $res; ?>php返回的数据处理(返回的是json数据)

$.post("search.php", { urlString}, function(data) { data = JSON.parse(data); var html='<div class="song" id="song" style="border-bottom: 1px solid gray;border-right:1px solid gray;">歌曲名</div><div class="singer" id="singer" style="border-bottom: 1px solid gray;">歌手</div>'; $('#lyric').html(String(html)); data['data']['song']['list'].forEach()})foreach里面该怎么做就怎么做,这里不给代码了 2. 获取歌曲图片——先通过第一步获取图片id

‘http://imgcache.qq.com/music/photo/album_’+width+‘/’+(this.image_id0)+‘/’+width+‘_albumpic_’+image_id+‘_0.jpg’ 注释:width为图片宽度(自定义,不过我发现定义小于300就显示不出来),image_id为歌曲的图片id(通过歌曲搜索可以得到)

3. 获取歌曲——先通过第一步获取歌曲id

歌曲有个坑,通过搜索获取歌曲id的时候会发现有两种类型的id,一种是纯数字的,一种是字母的,这是一个坑,因为网上的歌曲api一般为:

‘http://ws.stream.qqmusic.qq.com/’+id+‘.m4a?fromtag=46'这只能用于数字的id,无法获取id为字母的

不过聪明的博主已经在搜索api获取的歌曲信息中找到第二种了

'http://ws.stream.qqmusic.qq.com/‘+id+’.m4a?fromtag=00‘

当然,这还不是全部的歌曲,有些曲子无法播放还有两种可能:

①qq音乐没有该歌曲版权(这个我也没办法)

②该歌曲为铃声(这个没有搞出来)

4.获取歌词

`http://music.qq.com/miniportal/static/lyric/${id0}/${id}.xml`得到的是xml数据(在我的另一篇博客中有说明怎么处理这个xml数据) 用了ajax获取的

<?php $url=$_POST['txt']; if(!empty($url)) { $res = file_get_contents($url); $s = iconv('gbk','UTF-8',$res); echo $s; } ?> $.ajax({ type:"post", url:"lyric.php", datatype:"xml", data:{txt}, success:function(data){}})函数里面该怎么处理就怎么处理

转载请注明原文地址: https://www.6miu.com/read-19568.html

最新回复(0)