php实现网易云音乐 QQ音乐 酷狗音乐直链获取 搜索音乐及歌词
抓取方法来源于 其中酷狗与QQ来源于网络上的Meting.php 访问形式为GET 参数: method 值: netease //网易 tencent //QQ kugou //酷狗 参数: t
顺晟科技
2021-06-16 10:58:53
945
抓取方法来源于
其中酷狗与即时通信软件来源于网络上的Meting.php
访问形式为得到
参数:
方法
值:
网易//网易
腾讯//QQ
kugou /酷狗
参数:
类型
值:
搜索/搜索单曲曲名
lrc //获取歌词
详细/网易云音乐与酷狗音乐单曲详细信息
hash //酷狗音乐单曲详细用到的混杂
参数:
MusicId //网易云音乐ID//仅网易云音乐获取歌词与单曲详细信息用到
选填参数:
参数:
pagesize //酷狗音乐用到一次取几条数据
参数:
p /页码即时通信软件音乐用到
n /一次取几条数据即时通信软件音乐用到
limit://一次取几条数据网易云音乐用到
上代码
?服务器端编程语言(专业超文本预处理器的缩写)
/**
* [httpRequest描述]
* @param [type] $sUrl [url]
* @param [type] $aHeader [aHeader]
* @param [type] $aData [请求数据]
* @return [type] [json]
*/
函数httpRequest($sUrl,$aHeader,$aData){
$ ch=curl _ init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_URL,$ SurL);
curl_setopt($ch,CURLOPT_HTTPHEADER,$ aHeader);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT _ POSTFIELDS,http _ build _ query($ Adata));
$ SResult=curl _ exec($ ch);
if($sError=curl_error($ch)){
die($ ser ROr);
}
curl _ close($ ch);
返回$ sResult
}
//网易
函数网易(){
if(!空($_GET)){
开关($ _ GET[' type ']){
案例"搜索":
//搜索音乐
if(空($ _ GET[' name ']){
回应" { msg":参数缺失,' code ' : '-1 ' } ';
}
if(空($ _ GET[' limit ']){
$ _ GET[' limit ']=30;
}
//请求地址
$ sUrl='http://music.163.com/api/search/get/web';
//post数据
$aData=数组(
s'=$_GET['name'],
csrf_token'=' ',
type'=1,
offset'=0,//从第几条数据开始取
limit'=$_GET['limit'],//返回条数
total'=true
);
//表头数据
$ aHeader=array(' Referer : http://music。163 .com/search/');
//卷曲请求
$sResult=httpRequest($sUrl,$aHeader,$ aData);
//转数组
$ Arestdata=JSON _ decode($ sResult,true);
foreach($ aResData[' result '][' songs ']as $ key=$ value){
$ aResData[' result '][' songs '][$ key][' MurL ']=' https://music。163 .com/song/media/outer/URL?id=' .$value['id'].MP3 ';
}
//转数据显示返回数据
$ JSON=JSON _ encode($ aResData[' result '][' songs '],JSON _ UNESCAPED _ UNICODE);
$json=str_replace('\/','/',$ JSON);
echo($ JSON);
打破;
case 'lrc':
//歌词获取
$ URL=' http://音乐。163 .com/API/song/抒情?os=pcid=' .$_GET['MusicId'].LV=-1kv=-1tv=-1 ';
$ html=file _ get _ contents($ URL);
$arrObj=json_decode($html,TRUE);
echo ($arrObj['lrc']['抒情']);
打破;
案例"详细":
//单曲详细信息获取
$ URL=' http://音乐。163 .com/API/歌曲/细节?id=' .$_GET['MusicId'].ids=[" .$_GET['MusicId'].']';
$ html=file _ get _ contents($ URL);
$arrObj=json_decode($html,TRUE);
$ JSON=JSON _ encode($ arrObj[' songs '],JSON _ UNESCAPED _ UNICODE);
$json=str_replace('\/','/',$ JSON);
echo($ JSON);
打破;
}
}
}
//腾讯
功能腾讯(){
开关($ _ GET[' type ']){
案例"搜索":
$ w=$ _ GET[' name '];
$ p=1;
$ n=30
if(!空($ _ GET[' p ']){
$ p=$ _ GET[' p '];
}
if(!空($ _ GET[' n ']){
$ n=$ _ GET[' n '];
}
$ URL=' https://c . y . QQ。com/搜搜/fcgi-bin/client_search_cp?
$url .='p=' .$ p . n=' .$ n . w=' .$w,' aggr=1亏损减=1cr=1 new _ JSON=1 ';
$ html=file _ get _ contents($ URL);
//删除影响转为数组的文本
$html=str_replace('callback(','',$ html);
$html=str_replace(')','',$ html);
$html=str_replace('em ','',$ html);
$html=str_replace('/em ','',$ html);
//转数组
$arrObj=json_decode($html,TRUE);
//转数据显示返回数据
$ JSON=JSON _ encode($ arrObj[' data '][' song '][' list '],JSON _ UNESCAPED _ UNICODE);
$json=str_replace('\/','/',$ JSON);
echo($ JSON);
打破;
}
}
//酷狗
function kugou(){
开关($ _ GET[' type ']){
案例"搜索":
$ pagesize=30
if(!空($ _ GET['页面大小']){
$ page size=$ _ GET[' page size '];
}
$ URL=' http://移动cdn。酷狗。com/API/v3/search/song?API _ ver=1 rea _ code=1正确=1页面大小=' .$页面大小.plat=2tag=1 ver=5 show type=10 page=1 keyword=' .$_GET['name'].版本=8990 ';
$ html=file _ get _ contents($ URL);
$arrObj=json_decode($html,TRUE);
$ JSON=JSON _ encode($ arrObj[' data '][' info '],JSON _ UNESCAPED _ UNICODE);
echo($ JSON);
打破;
案例"详细":
if(空($ _ GET[' hash ']){
回应" { msg":参数缺失,' code ' : '-1 ' } ';
}
$ URL=' http://www .酷狗。请访问www . analog.com/YY/index。PHP?r=play/getdatahash=' .$ _ GET[' hash '];
$ html=file _ get _ contents($ URL);
$arrObj=json_decode($html,TRUE);
$ JSON=JSON _ encode($ arrObj[' data '],JSON _ UNESCAPED _ UNICODE);
$json=str_replace('\/','/',$ JSON);
$json=str_replace('\r ','',$ JSON);
$json=str_replace('\n ','',$ JSON);
echo($ JSON);
打破;
}
}
if(empty($ _ GET[' method '])| | empty($ _ GET[' type ']){
回应" { msg":参数缺失,' code ' : '-1 ' } ';
}else {
switch($_GET['method']){
案例'网易':
网易();
打破;
案例'腾讯':
腾讯();
打破;
case 'kugou':
ku Gou();
打破;
}
}
?