php计算QQ音乐guid,php实现网易云音乐 QQ音乐 酷狗音乐直链获取 搜索音乐及歌词...

抓取方法来源于

其中酷狗与QQ来源于网络上的Meting.php

访问形式为GET

参数:

method

值:

netease //网易

tencent //QQ

kugou //酷狗

参数:

types

值:

search //搜索单曲曲名

lrc //获取歌词

detailed //网易云音乐与酷狗音乐单曲详细信息

hash //酷狗音乐单曲详细用到的hash

参数:

MusicId //网易云音乐ID//仅网易云音乐获取歌词与单曲详细信息用到

选填参数:

参数:

pagesize //酷狗音乐用到 一次取几条数据

参数:

p //页码 QQ音乐用到

n //一次取几条数据 QQ音乐用到

limit://一次取几条数据 网易云音乐用到

上代码

/**

* [httpRequest description]

* @param  [type] $sUrl    [url]

* @param  [type] $aHeader [aHeader]

* @param  [type] $aData   [请求数据]

* @return [type]          [json]

*/

function 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($sError);

}

curl_close($ch);

return $sResult;

}

//网易

function netease(){

if(!empty($_GET)){

switch($_GET['types']){

case 'search':

//搜索音乐

if(empty($_GET['name'])){

echo '{"msg":"参数缺失","code":"-1"}';

}

if(empty($_GET['limit'])){

$_GET['limit']=30;

}

//请求地址

$sUrl = 'http://music.163.com/api/search/get/web';

//post数据

$aData = array(

"s"=> $_GET['name'],

"csrf_token"=> "",

"type"=> 1,

"offset"=> 0, //从第几条数据开始取

"limit"=> $_GET['limit'],//返回条数

"total"=> true

);

//header数据

$aHeader = array('Referer: http://music.163.com/search/');

//curl请求

$sResult = httpRequest($sUrl, $aHeader, $aData);

//转数组

$aResData = 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=json_encode($aResData['result']['songs'], JSON_UNESCAPED_UNICODE);

$json=str_replace('\/','/',$json);

echo ($json);

break;

case 'lrc':

//歌词获取

$url='http://music.163.com/api/song/lyric?os=pc&id='.$_GET['MusicId'].'&lv=-1&kv=-1&tv=-1';

$html = file_get_contents($url);

$arrObj=json_decode($html,TRUE);

echo ($arrObj['lrc']['lyric']);

break;

case 'detailed':

//单曲详细信息获取

$url='http://music.163.com/api/song/detail?id='.$_GET['MusicId'].'&ids=%5B'.$_GET['MusicId'].'%5D';

$html = file_get_contents($url);

$arrObj=json_decode($html,TRUE);

$json=json_encode($arrObj['songs'], JSON_UNESCAPED_UNICODE);

$json=str_replace('\/','/',$json);

echo ($json);

break;

}

}

}

//腾讯

function tencent(){

switch($_GET['types']){

case 'search':

$w=$_GET['name'];

$p=1;

$n=30;

if(!empty($_GET['p'])){

$p=$_GET['p'];

}

if(!empty($_GET['n'])){

$n=$_GET['n'];

}

$url='https://c.y.qq.com/soso/fcgi-bin/client_search_cp?';

$url.='p='.$p.'&n='.$n.'&w='.$w.'&aggr=1&lossless=1&cr=1&new_json=1';

$html = file_get_contents($url);

//删除影响转为数组的文本

$html = str_replace('callback(','',$html);

$html = str_replace(')','',$html);

$html = str_replace('','',$html);

$html = str_replace('','',$html);

//转数组

$arrObj=json_decode($html,TRUE);

//转json显示返回数据

$json=json_encode($arrObj['data']['song']['list'], JSON_UNESCAPED_UNICODE);

$json=str_replace('\/','/',$json);

echo ($json);

break;

}

}

//酷狗

function kugou(){

switch($_GET['types']){

case 'search':

$pagesize=30;

if(!empty($_GET['pagesize'])){

$pagesize=$_GET['pagesize'];

}

$url='http://mobilecdn.kugou.com/api/v3/search/song?api_ver=1&area_code=1&correct=1&pagesize='.$pagesize.'&plat=2&tag=1&sver=5&showtype=10&page=1&keyword='.$_GET['name'].'&version=8990';

$html = file_get_contents($url);

$arrObj=json_decode($html,TRUE);

$json=json_encode($arrObj['data']['info'], JSON_UNESCAPED_UNICODE);

echo ($json);

break;

case 'detailed':

if(empty($_GET['hash'])){

echo '{"msg":"参数缺失","code":"-1"}';

}

$url='http://www.kugou.com/yy/index.php?r=play/getdata&hash='.$_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);

break;

}

}

if(empty($_GET['method'])||empty($_GET['types'])){

echo '{"msg":"参数缺失","code":"-1"}';

}else {

switch($_GET['method']){

case 'netease':

netease();

break;

case 'tencent':

tencent();

break;

case 'kugou':

kugou();

break;

}

}

?>

标签: php

顶一下

(111)

91.7%

踩一下

(10)

8.3%

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值