From 88806a909404c592c66ee78729c2df5279e7facf Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Mon, 24 Jul 2023 22:41:49 +0800 Subject: [PATCH] =?UTF-8?q?AddFeature:=20=E9=9F=B3=E4=B9=90=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增: - music.blade.php - Music.php 修改: - 2023_06_13_060913_update_info_table.php - web.php Signed-off-by: XiaoLFeng --- app/Http/Controllers/Function/Music.php | 207 ++++++++++++++++++ .../2023_06_13_060913_update_info_table.php | 3 + resources/views/function/music.blade.php | 152 ++++++++++++- routes/web.php | 5 +- 4 files changed, 363 insertions(+), 4 deletions(-) create mode 100644 app/Http/Controllers/Function/Music.php 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 !!} + + +
+ @include('modules.navbar') +
+ +
+
+
+ image description +
{{ $musicArist['artist']->name }}
+
{{ $musicArist['identify']->imageDesc }}
+ +
+
+ + 专辑 {{ $musicArist['artist']->albumSize }} +
+
+ + 歌曲 {{ $musicArist['artist']->musicSize }} +
+
+
+
+
+ @if(!empty($musicAlbum[0]->id)) +
    + @php $i = 0; @endphp + @foreach($musicAlbum as $value) +
  1. + + Thomas Lean image + +
    +
    + +
    《{{ $value->name }}》
    +
    +
    + + + + + + + + + + + @foreach($musicMusic[$value->id] as $music) + + + + + + + @endforeach + +
    + 歌单名字 + + 时长 + + 音质 + + 操作 +
    + + {{ $music['name'] }} + + + {{ $music['duration'] }} + + {{ $music['maxBrLevel'] }} + + + + Go! + +
    +
    +
    +
  2. + @php $i++; @endphp + @endforeach +
+ @endif +
+
+
+ + @include('modules.footer') +
+
+ + + + + +{!! $webFooter !!} + diff --git a/routes/web.php b/routes/web.php index ba2c576..8d0ab0d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,6 +10,7 @@ use App\Http\Controllers\Console\Sponsor as ConsoleSponsor; use App\Http\Controllers\DataBase; use App\Http\Controllers\Function\Link as UserLink; +use App\Http\Controllers\Function\Music; use App\Http\Controllers\Function\Sponsor; use App\Http\Controllers\Index; use Illuminate\Support\Facades\Auth; @@ -40,9 +41,7 @@ Route::get('edit-search/{friendId}', [UserLink::class, 'viewSearchFriend'])->name('function.edit-searchOnly'); Route::get('edit-friend/{friendId}', [UserLink::class, 'viewEditFriend'])->name('function.edit-friend'); Route::get('sponsor', [Sponsor::class, 'viewSponsor'])->name('function.sponsor'); - Route::get('music', function () { - return view('function.music'); - })->name('function.music'); + Route::get('music', [Music::class, 'viewMusic'])->name('function.music'); }); Route::prefix('account')->middleware('auth')->group(function () {