/app/api/controller/Postbot.php
接口文件放置位置
模塊不需要登錄, 模塊配置哪里直接選擇不登錄
發布模塊的表單字段及說明:
1. book_name 漫畫名
2. nick_name 漫畫別名
3. tags 分類,多個分類用|隔開
4. author 作者名字
5. end 狀態,1代表完結,0代表連載中
6. cover_url 封面圖遠程地址
7. chapter_name 章節名
8. area_id 地區id
9. images 由圖片標簽組成的字符串,示例:
自動檢測
<img src="http://www.m.com/1.jpg"><img src="http://www.m.com/2.jpg"><img src="http://www.m.com/3.jpg">
11. summary 漫畫簡介
12. api_key 后臺配置的api_key
13. src 用來區別采集源,自己寫
14. src_url 用來唯一定義每個漫畫,可以是該漫畫的url,也可以是該漫畫在被采集站的id
15. c_src_url 用來唯一定義每個章節,與src_url同理
<?php namespace apppicontroller; use appmodelAuthor; use appmodelBook; use appmodelPhoto; use thinkController; use thinkRequest; use appmodelChapter; use appservicechapterService; use appservicephotoService; class Postbot { protected $chapterService; protected $photoService; public function initialize() { $this->chapterService = new ppserviceChapterService(); $this->photoService = new ppservicePhotoService(); } public function save(Request $request) { if ($request->isPost()) { $data = $request->param(); $key = $data['api_key']; if (empty($key) || is_null($key)) { return 'api密鑰不能為空!'; } if ($key != config('site.api_key')) { return 'api密鑰錯誤!'; } $book = Book::where('book_name', '=', trim($data['book_name']))->where('unique_id', '=', trim($data['unique_id']))->find(); if (!$book) { //如果漫畫不存在 $author = Author::where('author_name', '=', trim($data['author']))->find(); if (is_null($author)) {//如果作者不存在 $author = new Author(); $author->author_name = $data['author'] ?: '俠名'; $author->save(); } $book = new Book(); $book->unique_id = $data['unique_id']; $book->author_id = $author->id; $book->author_name = $data['author'] ?: '俠名'; $book->area_id = trim($data['area_id']); $book->book_name = trim($data['book_name']); if (!empty($data['nick_name']) || !is_null($data['nick_name'])) { $book->nick_name = trim($data['nick_name']); } $book->tags = trim($data['tags']); $book->end = trim($data['end']); $book->start_pay = trim($data['start_pay']); $book->money = trim($data['money']); // $info = $this->getImage($data['cover_url'], './img/' . date("Ymd")); $book->cover_url = trim($data['cover_url']); $book->summary = trim($data['summary']); $book->last_time = time(); // $book->update_week = rand(1, 7); // $book->click = rand(1000, 9999); $book->save(); } $map[] = ['chapter_name', '=', trim($data['chapter_name'])]; $map[] = ['book_id', '=', $book->id]; $chapter = Chapter::where($map)->find(); if (!$chapter) { $chapter = new Chapter(); $chapter->chapter_name = trim($data['chapter_name']); $chapter->book_id = $book->id; $lastChapterOrder = 0; if ($data['chapter_order']) { $chapter->chapter_order = (int)$data['chapter_order']; } else { $lastChapter = $this->getLastChapter($book['id']); if ($lastChapter) { $lastChapterOrder = $lastChapter->chapter_order; } $chapter->chapter_order = $lastChapterOrder + 1; } $chapter->update_time = time(); $chapter->save(); } $book->last_time = time(); $book->save(); $preg = '/srcs*=s*['"]?([^'"]*)['"]?/i'; preg_match_all($preg, $data['images'], $img_urls); $lastOrder = 0; $lastPhoto = $this->getLastPhoto($chapter->id); if ($lastPhoto) { $lastOrder = $lastPhoto->pic_order + 1; } foreach ($img_urls[1] as $img_url) { $photo = new Photo(); $photo->chapter_id = $chapter->id; $photo->pic_order = $lastOrder; // $info = $this->getImage($img_url, './img/' . date("Ymd")); $photo->img_url = $img_url; $photo->save(); $lastOrder++; } echo "操作成功"; } } public function getLastChapter($book_id) { return Chapter::where('book_id', '=', $book_id)->order('chapter_order', 'desc')->limit(1)->find(); } public function getLastPhoto($chapter_id) { return Photo::where('chapter_id', '=', $chapter_id)->order('id', 'desc')->limit(1)->find(); } /*功能:php完美實現下載遠程圖片保存到本地 *參數:文件url,保存文件目錄,保存文件名稱,使用的下載方式 *當保存文件名稱為空時則使用遠程文件原來的名稱 */ function getImage($url, $save_dir = '/public/img/', $filename = '', $type = 1) { if (trim($url) == '') { return array('file_name' => '', 'save_path' => '', 'error' => 1); } if (trim($save_dir) == '') { $save_dir = './'; } $url = str_replace('jpg ', 'jpg', $url); file_put_contents("result.txt", "url:" . $url . " ", FILE_APPEND); if (trim($filename) == '') {//保存文件名 $ext = strrchr($url, '.'); // if($ext!='.gif'&&$ext!='.jpg'){ // return array('file_name'=>'','save_path'=>'','error'=>3); // } $filename = time() . rand(100000, 999999) . $ext; } if (0 !== strrpos($save_dir, '/')) { $save_dir .= '/'; } //創建保存目錄 if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) { return array('file_name' => '', 'save_path' => '', 'error' => 5); } //獲取遠程文件所采用的方法 if ($type) { $img =$this-> http_curl($url); !$img && $img = $this->http_curl($url); !$img && $img = $this->http_curl($url); } else { ob_start(); readfile($url); $img = ob_get_contents(); ob_end_clean(); } //$size=strlen($img); // dump($img);die;/ //文件大小 // dump($save_dir.$filename);die; $fp2 = @fopen($save_dir . $filename, 'a'); fwrite($fp2, $img); fclose($fp2); unset($img, $url); return array('file_name' => $filename, 'save_path' => str_replace('./', '/', $save_dir . $filename), 'error' => 0); } function http_curl($url) { $ch = curl_init(); $timeout = 5; $aHeader = array('Referer: https://www.baidu.com/'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $img = curl_exec($ch); curl_close($ch); return $img; } }相關知識點: 小碗熊cms5.0 小碗熊cms5.0api
- 1訪問寶塔控制面板出現無法訪問此網站拒絕了我們的連接請求!處理方法
- 2藍天采集器安裝出問題 顯示版本問題
- 3藍天采集器請問時間轉換為時間戳這個工具應該怎么使用?
- 4Bty分銷系統v5忘記密碼找回的2個操作方法
- 5藍天采集器反饋個BUG
- 6163K網站系統商城物流跟蹤-快遞鳥配置教程
- 7狂雨小說CMS后臺采集規則教程附帶操作演示案例
- 8藍天采集器采集中斷、自動采集無效、圖片下載不了,解決方法!
- 9藍天采集器這個網頁怎么采集
- 10藍天采集器文章分頁采集示例教程
- 11藍天采集器采集的到內容但是發布時沒采集到
- 12藍天采集器分類信息采集,列表數據循環入庫示例教程
- 13藍天采集器BUG反饋
- 14小碗熊cms5.0火車頭采集器免登陸發布模塊api
- 15163K網站系統X10_V1升級教程
- 16藍天采集器翻譯功能是可以使用的嗎,我測試了很多國外網站都不行。
- 17藍天采集器2.0版本后不能自動采集了
- 18藍天采集器無法檢測到本地CMS
- 19金融投資/證券理財網站建設方案
- 20藍天采集器后臺設置了郵件發送地址點測試報錯
-
pbootcms系統網站必須要做的s···
pbootcms系統已經越來越多的人在使用了,由于是在aspcms系統上面剝離出來的,很大一部分使用者都是aspcms系列的站長。今天呢蜀戎網給大家分享一下這個pbootcms系統做的網站必須要做的seo要點都有哪些呢。1、網站路徑設置偽靜···
-
藍天采集器安裝好后登錄提示這個
Call to undefined function AdminControllermysql_get_server_info() php7版本會有這個bug 可以試試訪問其他頁面 安裝網址/index.php?m=admin&am···
-
PbootCMS內容輪播多圖增加標題···
功能介紹PbootCMS后臺內容發布中輪播多圖(圖集)默認無法自定義圖片的alt名稱,這就導致在一些場合中無法方便的使用。因此這次J.Z.帶來的二開即實現內容發布中給圖集的每張圖片增加標題,并且還可以增加簡介,適應更多的使用場景。此為網友投···
-
藍天采集器提示信息
-
163K網站系統商城物流跟蹤-快遞鳥···
此教程是網站后臺-商城-基本配置-基本配置-快遞鳥接口配置的配置教程,其作用是在未送達的訂單中顯示該訂單快遞單號的物流跟蹤狀態。1、注冊登陸http://www.kdniao.com/api-track,在用戶信息界面 可以獲取到 用戶ID···