BuildTestUrl.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\input\Option;
  6. use think\console\Output;
  7. use think\Request;
  8. class BuildTestUrl extends Command
  9. {
  10. const CPS_FILE_PATH = '/tmp/cps.txt';
  11. const H5_FILE_PATH = '/tmp/h5.txt';
  12. protected function configure()
  13. {
  14. $this->setName('BuildTestUrl')
  15. ->addOption('path', 'p', Option::VALUE_OPTIONAL, '书籍id文件的路径')
  16. ->setDescription('生成章节页面测试url');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. Request::instance()->module('admin');
  21. $bookIdFilePath = $input->getOption('path');
  22. echo $bookIdFilePath;
  23. $handle = fopen($bookIdFilePath, 'r');
  24. while (!feof($handle)) {
  25. $buffer = fgets($handle, 4096);
  26. $bookId = trim($buffer);
  27. if (empty($bookId)) {
  28. break;
  29. }
  30. $aChapter = $this->getChapterList($bookId);
  31. array_walk($aChapter, function ($cid) use ($bookId) {
  32. $cpsUrl = "https://wx79bfdb38ba28b749.zsjwn.cn/index/book/chapter?book_id=$bookId&chapter_id=$cid\r\n";
  33. file_put_contents(self::CPS_FILE_PATH, $cpsUrl, FILE_APPEND);
  34. $h5Url = "http://m.kkyd.cn/book.html?bookId=$bookId&chapterId=$cid\r\n";
  35. file_put_contents(self::H5_FILE_PATH, $h5Url, FILE_APPEND);
  36. });
  37. }
  38. echo "执行完成\r\n";
  39. echo "CPS链接文件路径:".self::CPS_FILE_PATH."\r\n";
  40. echo "h5链接文件路径:".self::H5_FILE_PATH."\r\n";
  41. }
  42. protected function getChapterList($bookId)
  43. {
  44. $list = model('Book')->getChapterList($bookId, 1, -1);
  45. $list = $list['data']['data'] ?? [];
  46. $list = array_column($list, 'id');
  47. return $list;
  48. }
  49. }