|
- <?php) J2 p% b# A, e0 {, i; H: D
- header("Access-Control-Allow-Origin:*");
. E6 l) B8 x- g- |& ]5 M - header('Content-type: application/json');# Z5 ?4 R6 W4 T$ T( \ J% k$ b
- //判断传入ID值为空提示错误!
% { S9 F8 l" S3 n, d3 H - if(!isset($_GET['id'])||empty($_GET['id'])||$_GET['id']==''||preg_match('/^[\w-]{1,31}$/',$_GET['id'])){
2 ]0 c; R1 O5 ^2 [* J" i - echo "歌曲ID为空或ID不正确!";
# q! f* H# m# g7 ^ - exit();; t, L" L }6 E4 j6 o! d+ t6 V! J
- }1 Y1 I( i! @: W, q. R
- $id = $_GET['id'];
+ e4 m# Z: M8 h8 f. @7 c - //请求地址
( x, E6 z$ ]: g - $url = "https://wwwapi.kugou.com/yy/index.php?r=play/getdata&hash=$id&album_id=27087265&dfid=4EElpa2FNXgl0Mjybx38NRsJ&mid=23b2df7991ed66939dc451de9e6b9333&platid=4&_=1566133588877";1 W5 @6 [0 |$ `5 e F
- //设置来源以防时间戳失效5 E% ]( n9 [: f# O* Z% O
- $refer = "http://www.kugou.com/";# M! L2 E+ b$ O6 H- O1 M
- //如果失效请自行获取酷狗音乐cookie+ {7 T2 r# I0 e" Q' G6 H& `# }; a2 d n# m
- $header = array('Cookie:'.'appver=1.5.0.75771;kg_mid=23b2df7991ed66939dc451de9e6b9333;','CLIENT-IP:125.64.107.18','X-FORWARDED-FOR:125.64.107.18');
3 ]' t' v9 f; E) C6 D; r - $ch = curl_init();$ C% P: f$ L$ z a+ N4 p5 b7 b% K
- curl_setopt($ch, CURLOPT_URL, $url);7 M& P, R7 A+ s8 q. H6 I( o1 m
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
& P* z) U# m) i - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
5 l$ o: D0 m& P* V) W - curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);& U5 V; P) K8 |% L
- curl_setopt($ch, CURLOPT_ENCODING, 'gzip');. _: `" C5 s( U, J3 V( U" }
- curl_setopt($ch, CURLOPT_REFERER, $refer);! y W- u6 m- M) I* P
- $output = curl_exec($ch);2 @8 y+ M0 Q" c
- curl_close($ch);, R- V- Q, |3 P
- //打包JSON
h& |- ?5 k0 O5 e - $json=json_decode($output,true);
6 E o1 m2 Q& J" O - $name=$json['data']['song_name'];
! ?! E5 O: E! o- O - $mp3url=$json['data']['play_url'];! B; p% t {) v+ p6 ~! h6 D
- $pic=$json['data']['img'];
B2 c- {9 [3 C7 L0 b6 l - $author=$json['data']['author_name'];
3 x% J! ^+ X7 ~: I8 P& \ Z - $picimg=str_replace("imge.kugou.com","p3fx.kgimg.com", $pic);
+ w$ _+ C0 H# w# [; w - $picssl=str_replace("http://","https://", $picimg);0 |2 @' ]. T: L0 b8 g
- //生成json数据
+ O6 [8 K( Z- _/ S% }1 Q - $info = array('name' => $name,'mp3url' => $mp3url,'pic' => $picssl,'author' => $author);: I8 s1 X1 `2 ~+ g- a+ q; K
- echo json_encode($info,320);( W k2 Q3 K! f8 D! c
- ?>
复制代码 |
|