只能解析普通QQ音乐歌曲 VIP歌曲不能解析
请求示例
```xxx.com/api.php?link=https://y.qq.com/n/ryqq/songDetail/003UkWuI0E8U0l```
接口代码如下
```<?php
header("content-type:application/json; charset=utf-8");
$link = $_REQUEST['link'];
if (empty($link)) {
exit(json_encode(['code' => 203, 'msg' => '分享链接为空,例如https://y.qq.com/n/ryqq/songDetail/003UkWuI0E8U0l'],320));
}
preg_match('/\/songDetail\/(.*)/',$link,$id);
$data=curl("https://i.y.qq.com/v8/playsong.html?_wv=14113&ADTAG=mqq_music&songmid=".$id[1]);
preg_match_all("/window.__ssrFirstPageData__ =(.*)<\/script>/",$data,$text);
$array = json_decode($text[1][0],true);
$value = array(
'code' => 1,
'msg' => '获取成功',
'albumname' => $array['songList'][0]['album']['name'],
'author' => $array['songList'][0]['singer'][0]['name'],
'pic' => $array['metaData']['image'],
'playurl' => $array['songList'][0]['url']);
echo json_encode($value,320);
function curl($url){ //Curl GET
$ch = curl_init(); // Curl 初始化
$timeout = 30; // 超时时间:30s
$ua='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36';// 伪造抓取 UA
$ip = mt_rand(11, 191) . "." . mt_rand(0, 240) . "." . mt_rand(1, 240) . "." . mt_rand(1, 240);
curl_setopt($ch, CURLOPT_URL, $url);// 设置 Curl 目标
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// Curl 请求有返回的值
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);// 设置抓取超时时间
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// 跟踪重定向
curl_setopt($ch, CURLOPT_REFERER, 'http://y.qq.com');//模拟来路
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip)); //伪造IP
curl_setopt($ch, CURLOPT_USERAGENT, $ua);// 伪造ua
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// https请求 不验证证书和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);//强制协议为1.0
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );//强制使用IPV4协议解析域名
$content = curl_exec($ch);
curl_close($ch);// 结束 Curl
return $content;// 函数返回内容
}```
请登录后发表评论
注册
停留在世界边缘,与之惜别