This commit is contained in:
toom1996
2025-07-31 11:43:28 +08:00
parent 1768c86693
commit cc15942e79
5 changed files with 33 additions and 22 deletions

View File

@ -22,11 +22,10 @@ class AutoPush extends BaseSpider
*/ */
protected string $baseUrl = 'http://data.zz.baidu.com/urls?site=https://hegsfc.com&token=5CtAd8vD3QQazJjh'; protected string $baseUrl = 'http://data.zz.baidu.com/urls?site=https://hegsfc.com&token=5CtAd8vD3QQazJjh';
protected const PLATFORM = 'elle-street';
public function __construct(protected ContainerInterface $container, LoggerFactory $loggerFactory) public function __construct(protected ContainerInterface $container, LoggerFactory $loggerFactory)
{ {
parent::__construct('baidu:auto-push'); parent::__construct('baidu:auto-push');
$this->commandLogger = $loggerFactory->get('log', 'command-baidu-auto-push');
} }
public function configure() public function configure()
@ -46,7 +45,6 @@ class AutoPush extends BaseSpider
$query = AppWebsiteConfig::query() $query = AppWebsiteConfig::query()
->select(['app_domain', 'id']) ->select(['app_domain', 'id'])
->where('is_delete', 0) ->where('is_delete', 0)
->where('is_record', 0)
->orderBy('id', 'DESC') ->orderBy('id', 'DESC')
->limit(10); ->limit(10);
if ($id = $input->getOption('platform')) { if ($id = $input->getOption('platform')) {
@ -66,7 +64,7 @@ class AutoPush extends BaseSpider
curl_setopt_array($ch, $options); curl_setopt_array($ch, $options);
$result = curl_exec($ch); $result = curl_exec($ch);
$pushArray = []; $pushArray = [];
var_dump($result); $this->commandLogger->info($result);
}; };
foreach ($query as $item) { foreach ($query as $item) {
$article = AppNews::query()->where('platform', $item['id'])->select(['id'])->get()->toArray(); $article = AppNews::query()->where('platform', $item['id'])->select(['id'])->get()->toArray();
@ -78,12 +76,6 @@ class AutoPush extends BaseSpider
} }
} }
// echo $result;
// var_dump($result);
var_dump($pushArray);
return 0; return 0;
} }

View File

@ -38,7 +38,7 @@ class BaiduRecordCommand extends BaseSpider
public function __construct(protected ContainerInterface $container, LoggerFactory $loggerFactory) public function __construct(protected ContainerInterface $container, LoggerFactory $loggerFactory)
{ {
parent::__construct('spider:baidu-record'); parent::__construct('spider:baidu-record');
$this->log = $loggerFactory->get('log', 'command-baidu-record'); $this->log = $loggerFactory->get('log', 'command-spider-baidu-record');
} }
public function configure() public function configure()

View File

@ -8,7 +8,9 @@ use Hyperf\Command\Command;
use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Coroutine\Coroutine; use Hyperf\Coroutine\Coroutine;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\Logger\LoggerFactory;
use Laminas\Stdlib\ArrayUtils; use Laminas\Stdlib\ArrayUtils;
use Psr\Log\LoggerInterface;
use Swoole\Coroutine\Channel; use Swoole\Coroutine\Channel;
use Swoole\Timer; use Swoole\Timer;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@ -44,6 +46,8 @@ class BaseSpider extends Command
protected array $commandConfigure = []; protected array $commandConfigure = [];
protected ?LoggerInterface $commandLogger = null;
private function init() private function init()
{ {
// 因为最外层还有个父协程, 所以加一 // 因为最外层还有个父协程, 所以加一
@ -79,7 +83,7 @@ class BaseSpider extends Command
return AppSpiderArticle::query()->where($condition)->first() ?: new AppSpiderArticle(); return AppSpiderArticle::query()->where($condition)->first() ?: new AppSpiderArticle();
} }
protected function request(string $url): array protected function request(string $url, array $headers = []): array
{ {
$ch = curl_init(); $ch = curl_init();
curl_setopt_array($ch, array( curl_setopt_array($ch, array(
@ -88,10 +92,13 @@ class BaseSpider extends Command
CURLOPT_ENCODING => '', CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10, CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 15, CURLOPT_TIMEOUT => 15,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FOLLOWLOCATION => true, CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
)); ));
// curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_HEADER, false); // curl_setopt($ch, CURLOPT_HEADER, false);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@ -130,7 +137,7 @@ class BaseSpider extends Command
$this->coroutineList[$cid] = 1; $this->coroutineList[$cid] = 1;
} }
protected function debugPrint(array|string $message = '', $level = 0) protected function debugPrint(array|string $message = '', $level = 0):void
{ {
if ($this->getCommandConfigure('prod') === false) { if ($this->getCommandConfigure('prod') === false) {
$printTime = date('H:i:s'); $printTime = date('H:i:s');

View File

@ -44,7 +44,7 @@ return [
], ],
], ],
], ],
'command-baidu-record' => [ 'command-spider-baidu-record' => [
'handler' => [ 'handler' => [
'class' => Monolog\Handler\RotatingFileHandler::class, 'class' => Monolog\Handler\RotatingFileHandler::class,
'constructor' => [ 'constructor' => [
@ -61,4 +61,21 @@ return [
], ],
], ],
], ],
'command-baidu-auto-push' => [
'handler' => [
'class' => Monolog\Handler\RotatingFileHandler::class,
'constructor' => [
'filename' => BASE_PATH . '/runtime/logs/baiduAutoPush.log',
'level' => Monolog\Level::Debug,
],
],
'formatter' => [
'class' => Monolog\Formatter\LineFormatter::class,
'constructor' => [
'format' => null,
'dateFormat' => 'Y-m-d H:i:s',
'allowInlineLineBreaks' => true,
],
],
],
]; ];

View File

@ -142,15 +142,10 @@ $platforms = call_user_func(function () {
} }
}, },
// field: "published_status", // field: "published_status",
},{
field:'created_at',
title: '发布日期'
}, },
// {
// title: "封面",
// field: "cover",
// templet: function (d) {
// return '<img src="'+encodeURI(d['cover'])+'" style="width:100%;height:100%" alt="" />'
// },
// width: 90,
// },
{ {
title: "操作", title: "操作",
toolbar: "#table-bar", toolbar: "#table-bar",