Skip to content

Commit

Permalink
add source ping & seo push url
Browse files Browse the repository at this point in the history
  • Loading branch information
copyrenzhe committed Aug 25, 2017
1 parent ea46660 commit 0d91fb4
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ WECHAT_PAYMENT_DEVICE_INFO
WECHAT_PAYMENT_SUB_APP_ID
WECHAT_PAYMENT_SUB_MERCHANT_ID

WECHAT_TYPE
WECHAT_TYPE

BAIDU_PUSH_API
8 changes: 8 additions & 0 deletions app/Jobs/SnatchInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public function handle()
$instance::snatch($novel);
Log::info("小说[$novel->id]:[$novel->name] 已采集完毕");
}

//百度推送
$urls[] = route('book', ['bookId' => $novel->id], true);
$ret = baiduPush($urls);
$retMessage = $ret ? 'success' : 'failed';
Log::info('baidu push '.var_export($urls, true) . $retMessage);
//百度推送END

$dtEnd = microtime_float();
Log::info('expire time '.($dtEnd-$dtStart).' seconds');
Log::info('----- FINISHED THE PROCESS FOR INIT NOVEL FROM LINK:'.$this->link. '-----');
Expand Down
13 changes: 11 additions & 2 deletions app/Repositories/Snatch/Biquge.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ public function getNovelList()
public function init($link)
{
$novel_html = $this->send($link, 'GET', false, 'utf-8');
if (!$novel_html) {
return false;
}
if (preg_match('/property="og:novel:book_name" content="(.*?)"/s', $novel_html, $novel_name)) {
preg_match('/property="og:novel:author" content="(.*?)"/s', $novel_html, $novel_author);
preg_match('/property="og:novel:category" content="(.*?)"/s', $novel_html, $category);
Expand Down Expand Up @@ -221,11 +224,14 @@ public function init($link)
/**
* @desc 使用curl_multi 多线程更新章节
* @param Novel $novel
* @return string|void
* @return string|mixed
*/
public function update(Novel $novel)
{
$novel_html = $this->send(self::DOMAIN . $novel->source_link, 'GET', false, 'utf-8');
if (!$novel_html) {
return false;
}

$chapter_list = $this->getChapterList($novel_html);
if (!$chapter_list[1]) {
Expand Down Expand Up @@ -319,11 +325,14 @@ public function update(Novel $novel)
/**
* 采集小说章节实现方法
* @param Novel $novel
* @return array
* @return array|mixed
*/
public function snatch(Novel $novel)
{
$novel_html = $this->send(self::DOMAIN . $novel->source_link, 'GET', false, 'utf-8');
if (!$novel_html) {
return false;
}
$chapter_list = $this->getChapterList($novel_html);
if (!$chapter_list[1]) {
Log::error('getChapterList failed');
Expand Down
6 changes: 6 additions & 0 deletions app/Repositories/Snatch/Snatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class Snatch
protected $page_size = 200;
protected $source;

public function ping()
{
$ret = $this->send(static::DOMAIN, 'GET', false, 'utf-8');
return $ret;
}

/**
* 单线程模拟请求
* @param $url
Expand Down
2 changes: 2 additions & 0 deletions app/Repositories/Snatch/SnatchInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

Interface SnatchInterface
{
public function ping();

//获取小说列表
public function getNovelList();

Expand Down
34 changes: 31 additions & 3 deletions app/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ function async_get_url($urls, $append_url = '', $page_size = 500, $source_encode
$handle = $info['handle'];
// 读取收到的内容
$content = curl_multi_getcontent($handle);
$recv[] = curl_errno($handle) == 0 ? (($source_encode != 'utf-8') ? mb_convert_encoding($content, 'UTF-8', 'gbk') : $content) : '';
$recv[] = curl_errno($handle) == 0 ? (($source_encode != 'utf-8') ? mb_convert_encoding($content,
'UTF-8', 'gbk') : $content) : '';
// 移除本资源
curl_multi_remove_handle($mh, $handle);
// 关闭资源
Expand Down Expand Up @@ -217,8 +218,10 @@ function getFileSize($url)
$tmp = fgets($fp);
if (trim($tmp) == '') {
break;
} else if (preg_match('/Content-Length:(.*)/si', $tmp, $arr)) {
return trim($arr[1]);
} else {
if (preg_match('/Content-Length:(.*)/si', $tmp, $arr)) {
return trim($arr[1]);
}
}
}
return null;
Expand Down Expand Up @@ -251,4 +254,29 @@ function qidianRank($mod = 'click', $dataType = '1', $chn = '-1', $maxPage = 10)
}
return $nameArr;
}
}

/**
* 百度SEO推送
*/
if (!function_exists('baiduPush')) {
function baiduPush($urls)
{
if (config('app.baidu_push_api')) {
$api = config('app.baidu_push_api');
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\n", $urls),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);;
return $httpCode == 200;
} else {
return true;
}
}
}
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

'url' => env('APP_URL', 'https://localhost'),

'baidu_push_api' => env('BAIDU_PUSH_API', ''),

/*
|--------------------------------------------------------------------------
| Application Timezone
Expand Down

0 comments on commit 0d91fb4

Please sign in to comment.