diff --git a/.gitignore b/.gitignore index 4250e71..7e97b19 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,4 @@ npm-debug.log yarn-error.log /.idea /.vscode -/tests/ /public/ diff --git a/app/Http/Controllers/Function/Music.php b/app/Http/Controllers/Function/Music.php new file mode 100644 index 0000000..f632d54 --- /dev/null +++ b/app/Http/Controllers/Function/Music.php @@ -0,0 +1,207 @@ +data = $data->data; + $this->data['neteaseUserId'] = DB::table('info')->find(23)->data; + $this->data['neteaseArtistsId'] = DB::table('info')->find(24)->data; + $this->data['neteaseApi'] = DB::table('info')->find(25)->data; + } + + protected function viewMusic(): Application|Factory|View + { + $this->data['musicArist'] = $this->getArtist(); + $this->data['musicAlbum'] = $this->getArtistAlbum(); + $getMusic = $this->getArtistAllMusic(); + foreach ($this->data['musicAlbum'] as $value) { + $j = 0; + try { + for ($i = 0; $getMusic[$i]['id'] != null; $i++) { + if ($getMusic[$i]['album']->id == $value->id) { + $this->data['musicMusic'][$value->id][$j] = $getMusic[$i]; + unset($this->data['musicMusic'][$value->id][$j]['album']); + $j++; + } + } + } catch (ErrorException $e) { + } + } + return view('function.music', $this->data); + } + + private function getArtist(): array + { + // 从数据库获取歌手ID + $queryData = [ + 'query' => [ + 'id' => $this->data['neteaseArtistsId'], + ], + ]; + $verify = ['verify' => true]; + if ($_SERVER['SERVER_PORT'] != 443) $verify = ['verify' => false]; + $client = new Client($verify); + try { + $response = $client->get($this->data['neteaseApi'] . '/artist/detail', $queryData); + $returnJson = (array)json_decode($response->getBody()->getContents()); + $returnJson = $returnJson['data']; + unset($returnJson->videoCount); + unset($returnJson->vipRights); + unset($returnJson->secondaryExpertIdentiy); + unset($returnJson->user); + } catch (GuzzleException $e) { + $returnJson['code'] = 403; + $returnJson['Exception'] = json_decode($e); + } + return (array)$returnJson; + } + + private function getArtistAlbum(): array + { + // 从数据库获取歌手ID + $queryData = [ + 'query' => [ + 'id' => $this->data['neteaseArtistsId'], + ], + ]; + $verify = ['verify' => true]; + if ($_SERVER['SERVER_PORT'] != 443) $verify = ['verify' => false]; + $client = new Client($verify); + try { + $response = $client->get($this->data['neteaseApi'] . '/artist/album', $queryData); + $returnJson = (array)json_decode($response->getBody()->getContents()); + // 整理数据 + $returnJson = $returnJson['hotAlbums']; + for ($i = 0; ; $i++) { + try { + if ($returnJson[$i]->id != null) { + unset($returnJson[$i]->artist); + unset($returnJson[$i]->songs); + unset($returnJson[$i]->paid); + unset($returnJson[$i]->onSale); + unset($returnJson[$i]->mark); + unset($returnJson[$i]->awardTags); + } + } catch (ErrorException $e) { + break; + } + } + } catch (GuzzleException $e) { + $returnJson['code'] = 403; + $returnJson['Exception'] = json_decode($e); + } + return $returnJson; + } + + protected function apiDemo(): JsonResponse + { + + return Response::json($this->getArtistAllMusic()); + } + + private function getArtistAllMusic() + { + // 从数据库获取歌手ID + $queryData = [ + 'query' => [ + 'id' => $this->data['neteaseArtistsId'], + ], + ]; + $verify = ['verify' => true]; + if ($_SERVER['SERVER_PORT'] != 443) $verify = ['verify' => false]; + $client = new Client($verify); + try { + $response = $client->get($this->data['neteaseApi'] . '/artist/songs', $queryData); + $returnJson = (array)json_decode($response->getBody()->getContents()); + // 整理数据 + $returnJson = $returnJson['songs']; + for ($i = 0; ; $i++) { + try { + if ($returnJson[$i]->id != null) { + // 时间换算 + $sec = $returnJson[$i]->dt / 1000; + $minute = floor($sec / 60); + $second = $sec % 60; + $returnJson[$i] = [ + 'album' => $returnJson[$i]->al, + 'id' => $returnJson[$i]->id, + 'name' => $returnJson[$i]->name, + 'duration' => $minute . '分' . $second . '秒', + 'maxBrLevel' => $returnJson[$i]->privilege->maxBrLevel, + ]; + } + } catch (ErrorException $e) { + break; + } + } + } catch (GuzzleException $e) { + $returnJson['code'] = 403; + $returnJson['Exception'] = json_decode($e); + } + return $returnJson; + } + + private function getArtistSingleMusic(int $albumId): array + { + $queryData = [ + 'query' => [ + 'id' => $albumId, + ], + ]; + $verify = ['verify' => true]; + if ($_SERVER['SERVER_PORT'] != 443) $verify = ['verify' => false]; + $client = new Client($verify); + try { + $response = $client->get($this->data['neteaseApi'] . '/album', $queryData); + $returnJson = (array)json_decode($response->getBody()->getContents()); + $returnJson = $returnJson['songs']; + for ($i = 0; ; $i++) { + try { + if ($returnJson[$i]->id != null) { + // 时间换算 + $sec = $returnJson[$i]->dt / 1000; + $minute = floor($sec / 60); + $second = $sec % 60; + $returnJson[$i] = [ + 'id' => $returnJson[$i]->id, + 'name' => $returnJson[$i]->name, + 'picUrl' => $returnJson[$i]->al->picUrl, + 'duration' => $minute . '分' . $second . '秒', + 'maxBrLevel' => $returnJson[$i]->privilege->maxBrLevel, + ]; + } + } catch (ErrorException $e) { + break; + } + } + } catch (GuzzleException $e) { + $returnJson['code'] = 403; + $returnJson['Exception'] = json_decode($e); + } + return $returnJson; + } +} diff --git a/database/migrations/2023_06_13_060913_update_info_table.php b/database/migrations/2023_06_13_060913_update_info_table.php index 94c755e..6ee4abe 100644 --- a/database/migrations/2023_06_13_060913_update_info_table.php +++ b/database/migrations/2023_06_13_060913_update_info_table.php @@ -43,6 +43,9 @@ public function up() DB::table('info')->insert(['value' => 'sponsorInfo', 'created_at' => date('Y-m-d H:i:s')]); DB::table('info')->insert(['value' => 'afadianUserId', 'created_at' => date('Y-m-d H:i:s')]); DB::table('info')->insert(['value' => 'afadianToken', 'created_at' => date('Y-m-d H:i:s')]); + DB::table('info')->insert(['value' => 'neteaseUserId', 'created_at' => date('Y-m-d H:i:s')]); + DB::table('info')->insert(['value' => 'neteaseArtistsId', 'created_at' => date('Y-m-d H:i:s')]); + DB::table('info')->insert(['value' => 'neteaseApi', 'created_at' => date('Y-m-d H:i:s')]); }); } diff --git a/resources/views/function/music.blade.php b/resources/views/function/music.blade.php index b3d9bbc..161aa51 100644 --- a/resources/views/function/music.blade.php +++ b/resources/views/function/music.blade.php @@ -1 +1,151 @@ - + +
+ + + + + + @include('modules.head') + {!! $webHeader !!} + + ++ 歌单名字 + | ++ 时长 + | ++ 音质 + | ++ 操作 + | +
---|---|---|---|
+ + {{ $music['name'] }} + + | ++ {{ $music['duration'] }} + | ++ {{ $music['maxBrLevel'] }} + | ++ + + Go! + + | +