Book.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Heanup\Library;
  3. class Book
  4. {
  5. private static $instance;
  6. private $domain = [
  7. 'index' => "https://scxs.pigqq.com/prov8/base/man2.html",
  8. 'search' => 'https://souxs.pigqq.com/search.aspx?key=%s&page=%d&siteid=%s',
  9. 'image' => 'https://imgapixs.pigqq.com/BookFiles/BookImages/%s',
  10. 'detail' => 'https://infosxs.pigqq.com/BookFiles/Html/%d/%d/info.html',
  11. 'chapter' => 'https://infosxs.pigqq.com/BookFiles/Html/%d/%d/index.html',
  12. 'content_info' => 'https://contentxs.pigqq.com/BookFiles/Html/%d/%d/%d.html',
  13. ];
  14. /**
  15. * 搜索小说
  16. * @return false|string
  17. */
  18. public function getIndexData()
  19. {
  20. $url = $this->domain['index'];
  21. return Curl::get($url);
  22. }
  23. /**
  24. * 搜索小说
  25. * @param $keyword
  26. * @param int $page
  27. * @return false|string
  28. */
  29. public function search($keyword, $page = 1)
  30. {
  31. $siteid = "app2";
  32. $url = sprintf($this->domain['search'], urlencode($keyword), $page, $siteid);
  33. return Curl::get($url);
  34. }
  35. /**
  36. * 获取小说详情
  37. * @param $book_id
  38. * @return false|string
  39. */
  40. public function getBookDetail($book_id)
  41. {
  42. $pre = (int)ceil($book_id / 1000);
  43. $url = sprintf($this->domain['detail'], $pre, $book_id);
  44. return Curl::get($url);
  45. }
  46. /**
  47. * 获取章节内容
  48. * @param $book_id
  49. * @return false|string
  50. */
  51. public function getChapter($book_id)
  52. {
  53. $pre = (int)ceil($book_id / 1000);
  54. $url = sprintf($this->domain['chapter'], $pre, $book_id);
  55. $result=Curl::get($url);
  56. $result=str_replace("},]", "}]", $result);
  57. return $result;
  58. }
  59. /**
  60. * 获取章节内容
  61. * @param $book_id
  62. * @param $chapter_id
  63. * @return false|string
  64. */
  65. public function getContent($book_id,$chapter_id){
  66. $pre = (int)ceil($book_id / 1000);
  67. $url = sprintf($this->domain['content_info'], $pre, $book_id,$chapter_id);
  68. return Curl::get($url);
  69. }
  70. /**
  71. * 获取完整图片URL
  72. * @param $img
  73. * @return string
  74. */
  75. public function getImageUrl($img)
  76. {
  77. return $url = sprintf($this->domain['image'], $img);
  78. }
  79. public function __construct()
  80. {
  81. Curl::get("https://scxs.pigqq.com/prov8/base/initconf.html");//初始化接口配置
  82. }
  83. public static function getInstance(): Book
  84. {
  85. if (!isset(self::$instance)) {
  86. $instance = new self();
  87. self::$instance = $instance;
  88. } else {
  89. $instance = self::$instance;
  90. }
  91. return $instance;
  92. }
  93. }