1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace app\admin\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Option;
- use think\console\Output;
- use think\Request;
- class BuildTestUrl extends Command
- {
- const CPS_FILE_PATH = '/tmp/cps.txt';
- const H5_FILE_PATH = '/tmp/h5.txt';
- protected function configure()
- {
- $this->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;
- }
- }
|