Created
December 27, 2015 15:24
-
-
Save keepanote/b331cd0accf516cd026a to your computer and use it in GitHub Desktop.
网易云音乐 外部链接 - PHP 解析
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Original Author: Moon | |
// Save as: 163.php | |
// Format: http://localhost/163.php?id=619623.mp3 | |
ERROR_REPORTING(0); | |
preg_match('/\d+/i', $_GET['id'], $id_matches); | |
$id = $id_matches[0]; | |
$url = "http://music.163.com/api/song/detail/?id=".$id."&ids=%5B".$id."%5D"; | |
$refer = "http://music.163.com/"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); | |
curl_setopt($ch, CURLOPT_REFERER, $refer); | |
$output = curl_exec($ch); | |
curl_close($ch); | |
$output_arr = json_decode($output, true); | |
$mp3_url = $output_arr["songs"][0]["mp3Url"]; | |
header('Content-Type:audio/mp3'); | |
header("Location:".$mp3_url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment