示例api:https://www.79xj.cn/api/music/Qmusic.php?song_id=0013WPvt4fQH2b
返回结果:
20201003144145.png
song_id的值是:
20201003144044.png

<?php

/**
 * Auther: yinshen
 * url:https://www.79xj.cn
 * 创建时间:2020/10/2 20:25
 */
class Qmusic
{
    public function getMusic($song_id)
    {
        if (!empty($song_id)) {
            $url = 'https://u.y.qq.com/cgi-bin/musicu.fcg?g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data={"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"8348972662","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"8348972662","songmid":["' . $song_id . '"],"songtype":[1],"uin":"0","loginflag":1,"platform":"20"}},"comm":{"uin":0,"format":"json","ct":24,"cv":0}}';
            $res = $this->geturl($url);
            $sip = $res['req']['data']['sip'];
            $purl = $res['req_0']['data']['midurlinfo'][0]['purl'];
            $rand = rand(0, 4);
            $url = $sip[$rand] . $purl;
            $arr = ["code" => 200, "data" => $url, "msg" => "ok"];
            return json_encode($arr, 448);
        } else {
            $arr = ["code" => 200, "data" => "", "msg" => "非法请求"];
            return json_encode($arr, 448);
        }

    }

    private function geturl($url)
    {
        $headerArray = array("Content-type:application/json;", "Accept:application/json");
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        $output = json_decode($output, true);
        return $output;
    }
}

$a = new Qmusic();

echo($a->getMusic($_GET["song_id"]))
?>

Last modification:October 3rd, 2020 at 02:42 pm
如果觉得我的文章对你有用,请随意赞赏