PHP获取网易云歌曲真实链接

PHP获取网易云歌曲真实链接

陌路离殇
2024-11-27 / 0 评论 / 4 阅读 / 正在检测是否收录...
<?php
function getMusicUrl($songId) {
    $apiUrl = 'http://music.163.com/song/media/outer/url?id='.$songId.'.mp3';
    $headers = array(
        'Referer: http://music.163.com/',
        'Host: music.163.com',
        'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $apiUrl);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    $retURL = $info['url'];
    curl_close($ch);
    return $retURL;
}
?>

本文共934个字符,其中有 0 个汉字,平均阅读时长 ≈ 3分钟
0

打赏

海报

正在生成.....

评论

博主关闭了所有页面的评论