文章内容 - 《酷狗音乐API代码》

酷狗音乐API代码

  2020-09-19    323

对接酷狗接口,优先返回SQ音质,测试服务器为国内,国外请自测。

来源于网络:http://www.xiaoapi.cn/index.php?act=pl&id=35

<?php
$msg = $_GET['msg'];
$b = $_GET['n'];
$data=curl('http://mobilecdnbj.kugou.com/api/v3/search/song?showtype=14&highlight=&pagesize=15&tag_aggr=1&plat=0&sver=5&correct=1&api_ver=1&version=9051&page=1&area_code=1&tag=1&with_res_tag=1&keyword='.$msg);
$data=str_replace('<!--KG_TAG_RES_START-->','',$data);
$data=str_replace('<!--KG_TAG_RES_END-->','',$data);
$json = json_decode($data, true);
$s=count($json["data"]["info"]);
if($s==0){exit("抱歉,返回数据为空。");}
if($b==""){
for( $i = 0 ; $i < $s ; $i ++ ){
$ga=$json["data"]["info"][$i]["songname_original"];
$gb=$json["data"]["info"][$i]["singername"];
$pay = $json["data"]["info"][$i]["pay_type"];
if($pay=="0"){
$pay="[免费]";}else{
$pay="[收费]";
}
echo ($i+1).":".$ga."--".$gb."".$pay."\n";}}else{
$i=($b-1);
$ga=$json["data"]["info"][$i]["songname_original"];
$gb=$json["data"]["info"][$i]["singername"];
$hash=$json["data"]["info"][$i]["sqhash"];
if($hash==""){$hash=$json["data"]["info"][$i]["320hash"];}
$data=curl('http://kmrcdn.service.kugou.com/container/v1/image?appid=1005&clientver=10009&author_image_type=4,5&album_image_type=-3&data=[{"hash":"'.$hash.'","filename":"'.$json["data"]["info"][$i]["filename"].'","album_audio_id":'.$json["data"]["info"][$i]["album_audio_id"].'}]');
$json = json_decode($data, true);
$img=str_replace(array('{size}'), array('', ''), $json["data"][0]["album"][0]["sizable_cover"]);
$r = 'http://www.kugou.com/webkugouplayer/?isopen=0&chl=yueku_index';
$u = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36';
$data=curl('http://trackercdn.kugou.com/i/?cmd=4&hash='.$hash.'&key='.md5($hash . "kgcloud").'&pid=1&acceptMp3=1',0,array('IPHONE_UA'=>0,'REFERER'=>$r,'USERAGENT'=>$u));
$json = json_decode($data, true);
$url=$json["url"];
if($url==""){exit("抱歉,解析失败。");}
echo 'json:{"app":"com.tencent.structmsg","desc":"音乐","view":"music","ver":"0.0.0.1","prompt":"[分享]'.$ga.'","appID":"","sourceName":"","actionData":"","actionData_A":"","sourceUrl":"","meta":{"music":{"action":"","android_pkg_name":"","app_type":1,"appid":100497308,"desc":"'.$gb.'","jumpUrl":"http://www.xiaoapi.cn","musicUrl":"'.$url.'","preview":"'.$img.'","sourceMsgId":"0","source_icon":"","source_url":"","tag":"酷狗音乐","title":"'.$ga.'"}},"config":{"autosize":true,"ctime":1575625127,"forward":true,"token":"7fef9b7d1e63b3500a42462126e9bc3d","type":"normal"},"text":"","sourceAd":""}';//,"config":{"forward":0,"showSender":0}
}
function curl($url,$data=0,$header_array=0,$referer=0,$time=30,$code=0) {
if($header_array==0) {
$header=array("CLIENT-IP: ".ip(),"X-FORWARDED-FOR: ".ip(),'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36');
} else {
$header=array("CLIENT-IP: ".ip(),"X-FORWARDED-FOR: ".ip(),'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36');
$header=array_merge($header_array,$header);
}
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
if($data) {
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);}
if($referer){
curl_setopt($curl,CURLOPT_REFERER,$referer);}
curl_setopt($curl,CURLOPT_TIMEOUT,$time);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl,CURLOPT_ENCODING,'gzip,deflate');
if($code){
curl_setopt($curl, CURLOPT_HEADER, 1);
$return=curl_exec($curl);
$code_code=curl_getinfo($curl);
curl_close($curl);
$code_int['exec']=substr($return,$code_code["header_size"]);
$code_int['code']=$code_code["http_code"];
$code_int['content_type']=$code_code["content_type"];
$code_int['header']=substr($return,0,$code_code["header_size"]);
return $code_int;
}else{
$return=curl_exec($curl);
curl_close($curl);
return $return;}}
function ip(){
$ip_long = array(
array('607649792','608174079'),
array('1038614528','1039007743'),
array('1783627776','1784676351'),
array('2035023872','2035154943'),
array('2078801920','2079064063'),
array('-1950089216','-1948778497'),
array('-1425539072','-1425014785'),
array('-1236271104', '-1235419137'),
array('-770113536','-768606209'),
array('-569376768','-564133889'),);
$rand_key=mt_rand(0,9);
return $ip=long2ip(mt_rand($ip_long[$rand_key][0], $ip_long[$rand_key][1]));
}
?>


上一篇:QQ音乐API代码

下一篇:我的熬夜之路