예제 #1
0
 public function actionLrc()
 {
     $song_id = intval($this->post("song_id", 0));
     if (!$song_id) {
         return $this->renderJSON([], "歌曲不存在", -1);
     }
     $info = Music::findOne(['song_id' => $song_id, 'status' => 1]);
     if (!$info) {
         return $this->renderJSON([], "歌曲不存在", -1);
     }
     /*获取歌词*/
     $lrc_url = QQMusicService::getSongLrcUrl($song_id);
     $lrc_data = HttpClient::get($lrc_url);
     $lrc = '';
     if (substr($lrc_data, 0, 5) == "<?xml") {
         if (stripos(strtolower($lrc_data), 'encoding="GB2312"') !== false) {
             $lrc_data = mb_convert_encoding($lrc_data, "utf-8", "gb2312");
             $lrc_data = str_replace('encoding="GB2312"', 'encoding="utf-8"', $lrc_data);
         }
         //var_dump($lrc_data);exit();
         $parser = xml_parser_create();
         xml_parse_into_struct($parser, $lrc_data, $values, $index);
         //解析到数组
         xml_parser_free($parser);
         $lrc = isset($values[0]['value']) ? $values[0]['value'] : '';
     }
     $data = ['lrc' => $lrc, 'song_url' => QQMusicService::getSongUrl($song_id)];
     return $this->renderJSON($data);
 }
예제 #2
0
 private function searchMusicByKw($kw)
 {
     $songs = QQMusicService::search($kw);
     $list = [];
     if ($songs) {
         foreach ($songs as $_song_info) {
             $list[] = ["title" => $_song_info['song_author'] . " -- " . $_song_info['song_title'], "description" => '', "picurl" => $_song_info['cover_image'], "url" => $_song_info['view_url']];
         }
     }
     $data = $list ? $this->getRichXml($list) : "抱歉没有搜索到关于 {$kw} 的歌曲";
     $type = $list ? "rich" : "text";
     return ['type' => $type, "data" => $data];
 }