<?php function kg_parse($shareUrl) { $options = [ 'http' => [ 'method' => 'GET', 'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36\r\n" . "Referer: https://www.baidu.com/\r\n", 'timeout' => 30 ] ]; $context = stream_context_create($options); $data = @file_get_contents($shareUrl, false, $context); preg_match("/window.__DATA__ =(.*?);/", $data, $json); $arr = json_decode($json[1], true); $value = [ 'code' => 0, 'data' => [ 'song_name' => $arr['detail']['song_name'], 'time' => $arr['detail']['ctime'], 'pic' => $arr['detail']['cover'], 'musiclink' => $arr['detail']['playurl'], 'author' => [ 'name' => $arr['detail']['avatar'], 'avatar' => $arr['detail']['kg_nick'] ] ] ]; return $value; } // 使用示例 $shareUrl = 'https://kg.qq.com/node/play?s=riEBRhrlX8YxXrUT'; $result = kg_parse($shareUrl); print_r($result);