setName('BuildTestUrl') ->addOption('path', 'p', Option::VALUE_OPTIONAL, '书籍id文件的路径') ->setDescription('生成章节页面测试url'); } protected function execute(Input $input, Output $output) { Request::instance()->module('admin'); $bookIdFilePath = $input->getOption('path'); echo $bookIdFilePath; $handle = fopen($bookIdFilePath, 'r'); while (!feof($handle)) { $buffer = fgets($handle, 4096); $bookId = trim($buffer); if (empty($bookId)) { break; } $aChapter = $this->getChapterList($bookId); array_walk($aChapter, function ($cid) use ($bookId) { $cpsUrl = "https://wx79bfdb38ba28b749.zsjwn.cn/index/book/chapter?book_id=$bookId&chapter_id=$cid\r\n"; file_put_contents(self::CPS_FILE_PATH, $cpsUrl, FILE_APPEND); $h5Url = "http://m.kkyd.cn/book.html?bookId=$bookId&chapterId=$cid\r\n"; file_put_contents(self::H5_FILE_PATH, $h5Url, FILE_APPEND); }); } echo "执行完成\r\n"; echo "CPS链接文件路径:".self::CPS_FILE_PATH."\r\n"; echo "h5链接文件路径:".self::H5_FILE_PATH."\r\n"; } protected function getChapterList($bookId) { $list = model('Book')->getChapterList($bookId, 1, -1); $list = $list['data']['data'] ?? []; $list = array_column($list, 'id'); return $list; } }