diff --git a/README.md b/README.md index 6e89481..fa8cebd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ -# NeteaseCloudMusic-300 -网易云音乐每日听满300首的PHP项目 +## Netease-cloud-api + +这是一个能够提供网易云音乐每日听满300首歌曲的基于PHP语言的API项目,配合python全自动脚本项目使用更佳。 + +## 功能特性 + +1. 登录 +2. 签到 +3. 查询用户信息 +4. 听完300首歌曲 + +## 安装部署 + +建议新手使用自动托管方式,可以完全不需要编程基础即可搭建api接口,推荐使用网站:[glitch](https://glitch.com/) + +1. fork本项目到你的仓库 + +2. 打开网站注册并登陆,新建项目,选择从GitHub导入,地址为本项目的git地址 +3. 修改你的glitch项目名,例如:netease-test +4. 那么你的接口名为“项目名.glitch.com”:https://netease-test.glitch.me/ +5. 访问你的接口看到欢迎页面即部署成功 + +使用这种方式部署网站接口,0成本且快速可用,且不用担心环境部署运维等问题,当然如果有条件用自己的服务器搭建也是可以的。 + + + diff --git a/glitch.json b/glitch.json new file mode 100644 index 0000000..a48fd30 --- /dev/null +++ b/glitch.json @@ -0,0 +1,4 @@ +{ + "start": "php -S 0.0.0.0:8080" + } + \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..48e4dc8 --- /dev/null +++ b/index.php @@ -0,0 +1,227 @@ +aes_encode(json_encode($raw),$this->_NONCE); + $data['params']=$this->aes_encode($data['params'],$this->_secretKey); + $data['encSecKey']=$this->_encSecKey; + return $data; + } + protected function aes_encode($secretData,$secret){ + return openssl_encrypt($secretData,'aes-128-cbc',$secret,false,$this->_VI); + } + + // CURL + protected function curl($url,$data=null,$cookie=false){ + $curl=curl_init(); + curl_setopt($curl,CURLOPT_URL,$url); + if($data){ + if(is_array($data))$data=http_build_query($data); + curl_setopt($curl,CURLOPT_POSTFIELDS,$data); + curl_setopt($curl,CURLOPT_POST,1); + } + curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl,CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($curl,CURLOPT_REFERER,$this->_REFERER); + curl_setopt($curl,CURLOPT_COOKIE,$this->_COOKIE."__csrf=".$_COOKIE["__csrf"]."; MUSIC_U=".$_COOKIE["MUSIC_U"]); + curl_setopt($curl,CURLOPT_USERAGENT,$this->_USERAGENT); + if($cookie==true){ + curl_setopt($curl,CURLOPT_HEADER,1); + $result=curl_exec($curl); + preg_match_all('/\{(.*)\}/', $result, $json); + if(json_decode($json[0][0],1)["code"]==200){ + preg_match_all('/Set-Cookie: MUSIC_U=(.*?)\;/', $result, $musicu); + preg_match_all('/Set-Cookie: __csrf=(.*?)\;/', $result, $csrf); + setcookie("MUSIC_U",$musicu[1][0]); + setcookie("__csrf",$csrf[1][0]); + } + $result = $json[0][0]; + }else{ + $result=curl_exec($curl);} + curl_close($curl); + return $result; + } + + // main function + // login by phone + public function login($cell,$pwd){ + $url="https://music.163.com/weapi/login/cellphone"; + $data=array( + "phone"=>$cell, + "countrycode"=>"86", + "password"=>$pwd, + "rememberLogin"=>"true"); + return $this->curl($url,$this->prepare($data),true); + } + // login by email + public function loginByEmail($cell,$pwd){ + $url="https://music.163.com/weapi/login"; + $data=array( + "username"=>$cell, + "password"=>$pwd, + "rememberLogin"=>"true"); + return $this->curl($url,$this->prepare($data),true); + } + // get user detail + public function detail($uid){ + $url="https://music.163.com/weapi/v1/user/detail/${uid}"; + return $this->curl($url,$this->prepare($data),true); + } + public function follow(){ + $url="https://music.163.com/weapi/user/follow/0"; + return '{"code":'.json_decode($this->curl($url,$this->prepare(array('csrf_token'=>$_COOKIE["__csrf"]))),1)["code"].'}'; + } + public function recommend(){ + $url="https://music.163.com/weapi/v1/discovery/recommend/resource"; + $json = json_decode($this->curl($url,$this->prepare(array('csrf_token'=>$_COOKIE["__csrf"]))), 1); + foreach ($json["recommend"] as $i => $k) { + $id[$i] = $k["id"]; + } + return $id; + + } + public function daka_new(){ + $playlist = $this->recommend(); + $ids = array(); + $count=0; + for ($i = 0; sizeof($ids) < 310; $i++) { + $songid = $this->getsongid($playlist[rand(0,sizeof($playlist)-1)]); + for ($k=0;sizeof($ids) < 310&&$kcurl($url,$this->prepare(array("logs"=>$data))); + return '{"code":200,"count":'.$count.'}'; + } + public function getsongid($playlist_id){ + $url='https://music.163.com/weapi/v3/playlist/detail?csrf_token='; + $data=array( + 'id'=>$playlist_id, + 'n'=>1000, + 'csrf_token'=>'', + ); + $raw=$this->curl($url,$this->prepare($data)); + $json=json_decode($raw,1); + + return $json["playlist"]["trackIds"]; + //return json_decode($raw,1)[]; + } + + + + + public function daka(){ + $playlist = $this->recommend(); + $ids = array(); + for ($i = 0; sizeof($ids) < 300; $i++) { + $songid = $this->playlist($playlist[rand(0,sizeof($playlist))]); + foreach ($songid as $id) { + $ids[] = $id; + } + } + return '{"code":200,"count":'.$this->scrobble($ids).'}'; + } + public function sign(){ + $url="https://music.163.com/weapi/point/dailyTask"; + $data=array("type"=>0); + return $this->curl($url,$this->prepare($data),true); + } + public function scrobble($songid){ + $url="http://music.163.com/weapi/feedback/weblog"; + $res = array(); + $count=0; + $cookies=$this->_COOKIE."__csrf=".$_COOKIE["__csrf"]."; MUSIC_U=".$_COOKIE["MUSIC_U"]; + $mh = curl_multi_init(); + foreach ($songid as $k => $id) { + $data[$k]=$this->prepare(array("logs"=>'[{"action":"play","json":{"download":0,"end":"playend","id":"'.$id.'","sourceId":"","time":240,"type":"song","wifi":0}}]')); + $data[$k]=http_build_query($data[$k]); + $conn[$k] = curl_init($k); + curl_setopt($conn[$k], CURLOPT_URL, $url); + curl_setopt($conn[$k],CURLOPT_POST,1); + curl_setopt($conn[$k],CURLOPT_POSTFIELDS,$data[$k]); + //curl_setopt($conn[$k], CURLOPT_TIMEOUT, $timeout); + curl_setopt($conn[$k], CURLOPT_COOKIE, $cookies); + curl_setopt($conn[$k], CURLOPT_RETURNTRANSFER, 1); + curl_multi_add_handle($mh, $conn[$k]); + $count++; + } + do { + $mrc = curl_multi_exec($mh, $active); + } + while ($mrc == CURLM_CALL_MULTI_PERFORM); + while ($active and $mrc == CURLM_OK) { + if (curl_multi_select($mh) != -1) { + do { + $mrc = curl_multi_exec($mh, $active); + } + while ($mrc == CURLM_CALL_MULTI_PERFORM); + } + } + foreach ($array as $k => $value) { + curl_error($conn[$k]); + $res[$k] = curl_multi_getcontent($conn[$k]); + //$header[$k] = curl_getinfo($conn[$k]); + curl_close($conn[$k]); + curl_multi_remove_handle($mh, $conn[$k]); + } + curl_multi_close($mh); + //return array('return' => $res, 'header' => $header); + //return "233"; + return $count; + } + + public function playlist($playlist_id){ + $url='https://music.163.com/weapi/v3/playlist/detail?csrf_token='; + $data=array( + 'id'=>$playlist_id, + 'n'=>1000, + 'csrf_token'=>'', + ); + $raw=$this->curl($url,$this->prepare($data)); + $json=json_decode($raw,1); + foreach ($json["playlist"]["trackIds"] as $i => $k) { + $ids[$i] = $k["id"]; + } + return $ids; + //return json_decode($raw,1)[]; + } +} +$api= new API(); +$api->follow(); +//test(); +if($_REQUEST["do"]=="login"){ + echo $api->login($_REQUEST["uin"],$_REQUEST["pwd"]);} + elseif($_REQUEST["do"]=="email"){echo $api->loginByEmail($_REQUEST["uin"],$_REQUEST["pwd"]);} + elseif($_REQUEST["do"]=="sign"){echo $api->sign();} + elseif($_REQUEST["do"]=="daka"){echo $api->daka_new();} + elseif($_REQUEST["do"]=="check"){echo $api->follow();} + elseif($_REQUEST["do"]=="detail"){echo $api->detail($_REQUEST["uid"]);} + +?> \ No newline at end of file