部分音乐可能因为版权或者其他原因,用这个php脚本可能获取不到 请见谅!
http直链
<? error_reporting(0); function getMusic($MusicUrl) { $temp = explode('=',$MusicUrl); $id = $temp[1]; $MusicUrl = "http://music.163.com/api/song/enhance/player/url?id=".$id."&ids=[".$id."]&br=3200000"; $result = file_get_contents($MusicUrl); header('Content-Type:application/json; charset=utf-8'); print_r($result); } $MusicUrl = $_POST['url']; //$MusicUrl = "https://music.163.com/#/song?id=450795499"; getMusic($MusicUrl); ?>
访问php?url=(网易云地址)即可,若需要支持https可以用下面的代码
https 301跳转
就在前不久网易云直链获取地址突然从https变回成http了,这个是获取真实链接然后再替换成https,不知道能维持多久
<?php $id=$_GET['id']; $reg = '/^[0-9][0-9]*$/'; if(preg_match($reg,$id)){ $url_cxk = getrealurl('https://music.163.com/song/media/outer/url?id=' . $id . '.mp3'); $neturl = str_replace("http://","https://",$url_cxk); if($neturl=="https://music.163.com/404"){ header("Location: https://music.163.com/song/media/outer/url?id=".$id.".mp3"); exit; }else{ header("Location: ".$neturl.""); exit; } }else{ echo "非法参数"; } function getrealurl($url){ $header = get_headers($url,1); if (strpos($header[0],'301') || strpos($header[0],'302')) { if(is_array($header['Location'])) { return $header['Location'][count($header['Location'])-1]; }else{ return $header['Location']; } }else { return $url; } } exit; ?>
访问php?id=id即可302转到https渠道的音乐链接。(网易云的id)