陈德本 5 éve
szülő
commit
dd8cd4c26c

+ 4 - 0
App/Api/Controller/Category.php

@@ -12,6 +12,10 @@ class Category extends Controller
 {
     protected function main()
     {
+        if (isMobile()) {
+            header("location: /tao.php");
+            die();
+        }
 //        $id = $this->getQuery()->intval("id");
         $id = $this->getQuery()->string("args_0");
         $page = $this->getQuery()->string("args_1");

+ 4 - 0
App/Api/Controller/Detail.php

@@ -12,6 +12,10 @@ class Detail extends Controller
 {
     protected function main()
     {
+        if (isMobile()) {
+            header("location: /tao.php");
+            die();
+        }
         $id = $this->getQuery()->intval("id");
         $u = Site::getData("user_tag");
         $url = sprintf(Site::getData('site_url') . "/tao.php?r=l/d&id=%s&u=%s", $id, $u);

+ 4 - 0
App/Api/Controller/Index.php

@@ -13,6 +13,10 @@ class Index extends Controller
 
     protected function main()
     {
+        if (isMobile()) {
+            header("location: /tao.php");
+            die();
+        }
         $url = Site::getData('site_url') . "/tao.php";
         $page = $this->getQuery()->string("args_0");
         $request=[

+ 91 - 0
App/Api/Controller/Novel/Api.php

@@ -0,0 +1,91 @@
+<?php
+
+
+namespace Heanup\App\Api\Controller\Novel;
+
+
+use Heanup\App\Api\Controller;
+use Heanup\Library\Book;
+
+class Api extends Controller
+{
+    protected function main()
+    {
+        $do = $this->getRequest()->string("do", "index");
+        $keyword = $this->getRequest()->string("keyword");
+        $book_id = $this->getRequest()->intval("book_id");
+        $chapter_id = $this->getRequest()->intval("chapter_id");
+        $page = $this->getRequest()->intval("page", 1);
+        $result = "[]";
+        if ($do == "index") {
+            $result = Book::getInstance()->getIndexData();
+            $result = json_decode($result, true);
+            $result = $result['data'];
+        }
+        if ($do == "search") {
+            $result = Book::getInstance()->search($keyword);
+            $result = json_decode($result, true);
+            $response = [];
+            foreach ($result['data'] as $item) {
+                $response[] = [
+                    'id' => $item['Id'],
+                    'img' => $item['Img'],//Book::getInstance()->getImageUrl($item['Img']),
+                    'name' => $item['Name'],
+                    'author' => $item['Author'],
+                    'introduce' => $item['Desc']
+                ];
+            }
+            $result = $response;
+        }
+        if ($do == "detail") {
+            $result = Book::getInstance()->getBookDetail($book_id);
+            $result = json_decode(trim($result), true);
+            $result = $result['data'];
+            $response=[];
+            $response['id']=$result['Id'];
+            $response['name']=$result['Name'];
+            $response['author']=$result['Author'];
+            $response['sort']=$result['CName'];
+            $response['state']=$result['BookStatus'];
+            $response['time']=$result['LastTime'];
+            $response['img']=Book::getInstance()->getImageUrl($result['Img']);
+            $response['intro']=$result['Desc'];
+            $response['news']=$result['LastChapter'];
+            $chapter=Book::getInstance()->getChapter($book_id);
+            $chapter=json_decode($chapter,true);
+            $_chapter=[];
+            foreach ($chapter['data']['list'] as $item) {
+                foreach ($item['list'] as $val) {
+                    $_chapter[]=$val;
+                }
+            }
+            $response=[
+                'data'=>$response,
+                'list'=>$_chapter
+            ];
+            $result = $response;
+        }
+        if ($do == "list") {
+            $chapter=Book::getInstance()->getChapter($book_id);
+            $chapter=json_decode($chapter,true);
+            $_chapter=[];
+            foreach ($chapter['data']['list'] as $item) {
+                foreach ($item['list'] as $key=>$val) {
+                    $_chapter[]=[
+                        'index'=>$key,
+                        'id'=>$val['id'],
+                        'name'=>$val['name']
+                    ];
+                }
+            }
+            $result = $_chapter;
+        }
+        if ($do == "content") {
+            $result = Book::getInstance()->getContent($book_id, $chapter_id);
+            $result = json_decode($result, true);
+            $result = nl2br($result['data']['content']);
+        }
+
+        $this->showSuccess($result);
+    }
+}

+ 4 - 0
App/Api/Controller/Pages.php

@@ -12,6 +12,10 @@ class Pages extends Controller
 {
     protected function main()
     {
+        if (isMobile()) {
+            header("location: /tao.php");
+            die();
+        }
         $route=[
             'fengqiang'=>'p',
             'nine'=>'nine',

+ 4 - 0
App/Api/Controller/Search.php

@@ -12,6 +12,10 @@ class Search extends Controller
 {
     public function main()
     {
+        if (isMobile()) {
+            header("location: /tao.php");
+            die();
+        }
         $kw = $this->getQuery()->string("kw") ?: $this->getQuery()->string("args_0");
         $bids = $this->getQuery()->string("bids");
         $cid = $this->getQuery()->string("cid");

+ 109 - 0
Library/Book.php

@@ -0,0 +1,109 @@
+<?php
+
+
+namespace Heanup\Library;
+
+
+class Book
+{
+    private static $instance;
+    private $domain = [
+        'index' => "https://scxs.pigqq.com/prov8/base/man2.html",
+        'search' => 'https://souxs.pigqq.com/search.aspx?key=%s&page=%d&siteid=%s',
+        'image' => 'https://imgapixs.pigqq.com/BookFiles/BookImages/%s',
+        'detail' => 'https://infosxs.pigqq.com/BookFiles/Html/%d/%d/info.html',
+        'chapter' => 'https://infosxs.pigqq.com/BookFiles/Html/%d/%d/index.html',
+        'content_info' => 'https://contentxs.pigqq.com/BookFiles/Html/%d/%d/%d.html',
+    ];
+
+
+    /**
+     * 搜索小说
+     * @return false|string
+     */
+    public function getIndexData()
+    {
+        $url = $this->domain['index'];
+        return Curl::get($url);
+    }
+    /**
+     * 搜索小说
+     * @param $keyword
+     * @param int $page
+     * @return false|string
+     */
+    public function search($keyword, $page = 1)
+    {
+        $siteid = "app2";
+        $url = sprintf($this->domain['search'], urlencode($keyword), $page, $siteid);
+        return Curl::get($url);
+    }
+
+
+    /**
+     * 获取小说详情
+     * @param $book_id
+     * @return false|string
+     */
+    public function getBookDetail($book_id)
+    {
+        $pre = (int)ceil($book_id / 1000);
+        $url = sprintf($this->domain['detail'], $pre, $book_id);
+        return Curl::get($url);
+    }
+
+    /**
+     * 获取章节内容
+     * @param $book_id
+     * @return false|string
+     */
+    public function getChapter($book_id)
+    {
+        $pre = (int)ceil($book_id / 1000);
+        $url = sprintf($this->domain['chapter'], $pre, $book_id);
+        $result=Curl::get($url);
+        $result=str_replace("},]", "}]", $result);
+        return $result;
+    }
+
+    /**
+     * 获取章节内容
+     * @param $book_id
+     * @param $chapter_id
+     * @return false|string
+     */
+    public function getContent($book_id,$chapter_id){
+        $pre = (int)ceil($book_id / 1000);
+        $url = sprintf($this->domain['content_info'], $pre, $book_id,$chapter_id);
+        return Curl::get($url);
+    }
+
+    /**
+     * 获取完整图片URL
+     * @param $img
+     * @return string
+     */
+    public function getImageUrl($img)
+    {
+        return $url = sprintf($this->domain['image'], $img);
+    }
+
+
+    public function __construct()
+    {
+        Curl::get("https://scxs.pigqq.com/prov8/base/initconf.html");//初始化接口配置
+    }
+
+    public static function getInstance(): Book
+    {
+        if (!isset(self::$instance)) {
+            $instance = new self();
+            self::$instance = $instance;
+        } else {
+            $instance = self::$instance;
+        }
+        return $instance;
+    }
+
+
+}

+ 2 - 2
Library/Curl.php

@@ -28,7 +28,7 @@ class Curl
     {
         if (!$url)
             return false;
-        $ssl = stripos($url, 'https://') === 0 ? true : false;
+        $ssl = stripos($url, 'https://') === 0;
         $curl = curl_init();
         if (!is_null($proxy))
             curl_setopt($curl, CURLOPT_PROXY, $proxy);
@@ -61,7 +61,7 @@ class Curl
         }
 //        $this->http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
         curl_close($curl);
-        return $content;
+        return removeBOM($content);
     }
 
     /**

+ 5 - 2
functions.php

@@ -88,6 +88,9 @@ function isMobile()
     return false;
 }
 
-if (isMobile()) {
-    header("location: /tao.php");
+function removeBOM($data) {
+    if (0 === strpos(bin2hex($data), 'efbbbf')) {
+        return substr($data, 3);
+    }
+    return $data;
 }