QQ音乐歌曲链接获取API

聚光网络博客

发表文章数:27

首页 » 技术分享 » QQ音乐歌曲链接获取API

在这之前也研究过QQ音乐歌曲链接获取,也写过文件找不到了,于是就重新写了份,API可以获取付费歌曲的地址,需要设置QQ音乐会员COOIKE,亲自行设置

代码如下:

<?php
$url='程响《世界这么大还是遇见你》(清新的小女孩(中文版)) https://c.y.qq.com/base/fcgi-bin/u?__=fm6kin5 @QQ音乐';
//正则匹配音乐链接
if(preg_match('@[a-zA-z]+://[^\s]*@i',$url, $matches)){
  //判断分享的链接是电脑端还是手机端
  if( substr($matches[0] , 0 , 9) == 'https://y'){
    //正则匹配电脑端链接中的音乐mid
    preg_match('@/song/(.*?)[email protected]',$matches[0], $mid);
    $url= get($mid[1]);
    echo "&amp;amp;lt;/pre&amp;amp;gt;
&amp;amp;lt;a href="$url" target="_blank" rel="noopener"&amp;amp;gt;$url&amp;amp;lt;/a&amp;amp;gt;
&amp;amp;lt;pre&amp;amp;gt;";
  }elseif(substr($matches[0] , 0 , 9) == 'https://c'){
    //获取手机端链接重定向后的链接
    $headers = get_headers($matches[0], TRUE);
    //正则匹配手机端链接中的音乐mid
    preg_match('@&amp;amp;amp;amp;songmid=(.*?)&amp;amp;amp;amp;[email protected]',$headers['Location'], $mid);
    $url= get($mid[1]);
    echo "&amp;amp;lt;/pre&amp;amp;gt;
&amp;amp;lt;a href="$url" target="_blank" rel="noopener"&amp;amp;gt;$url&amp;amp;lt;/a&amp;amp;gt;
&amp;amp;lt;pre&amp;amp;gt;";
    
  }else{
    echo '请输入正确的音乐分享链接';
  }
}else {
  echo '请输入正确的音乐分享链接';
}
function get($mid){
  
  $url='https://u.y.qq.com/cgi-bin/musicu.fcg?-=getplaysongvkey25242642025174344&amp;amp;amp;amp;g_tk=478375240&amp;amp;amp;amp;loginUin=1612000422&amp;amp;amp;amp;hostUin=0&amp;amp;amp;amp;format=json&amp;amp;amp;amp;inCharset=utf8&amp;amp;amp;amp;outCharset=utf-8&amp;amp;amp;amp;notice=0&amp;amp;amp;amp;platform=yqq.json&amp;amp;amp;amp;needNewCode=0&amp;amp;amp;amp;data={"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"830161100","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"830161100","songmid":["'.$mid.'"],"songtype":[0],"uin":"1612000422","loginflag":1,"platform":"20"}},"comm":{"uin":1612000422,"format":"json","ct":24,"cv":0}}';
  $cookie='';//设置QQ音乐会员COOKIE 没有请留空,
  
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_ENCODING, "");
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36");
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    $content = curl_exec($ch);
    curl_close($ch);
    $content = json_decode($content,true);
    return 'http://ws.stream.qqmusic.qq.com/'.$content['req_0']['data']['midurlinfo'][0]['purl'];
}

标签:

未经允许不得转载:作者:聚光网络博客, 转载或复制请以 超链接形式 并注明出处 聚光网络博客
原文地址:《QQ音乐歌曲链接获取API》 发布于2020-03-10

分享到:
赞(1) 生成海报

评论 1

7 + 5 =
  1. #1
    qq_avatar

    QQ音乐

    锟斤拷小锟桔撅拷锟斤拷9个月前 (03-10)回复

长按图片转发给朋友

Vieu4.5主题
专业打造轻量级个人企业风格博客主题!专注于前端开发,全站响应式布局自适应模板。
切换注册

登录

忘记密码 ?

切换登录

注册