diff --git a/app/Command/baidu/AutoPush.php b/app/Command/baidu/AutoPush.php index 6d2d6ab..7f8fc43 100644 --- a/app/Command/baidu/AutoPush.php +++ b/app/Command/baidu/AutoPush.php @@ -22,11 +22,10 @@ class AutoPush extends BaseSpider */ 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) { parent::__construct('baidu:auto-push'); + $this->commandLogger = $loggerFactory->get('log', 'command-baidu-auto-push'); } public function configure() @@ -46,7 +45,6 @@ class AutoPush extends BaseSpider $query = AppWebsiteConfig::query() ->select(['app_domain', 'id']) ->where('is_delete', 0) - ->where('is_record', 0) ->orderBy('id', 'DESC') ->limit(10); if ($id = $input->getOption('platform')) { @@ -66,7 +64,7 @@ class AutoPush extends BaseSpider curl_setopt_array($ch, $options); $result = curl_exec($ch); $pushArray = []; - var_dump($result); + $this->commandLogger->info($result); }; foreach ($query as $item) { $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; } diff --git a/app/Command/spider/BaiduRecordCommand.php b/app/Command/spider/BaiduRecordCommand.php index f76b8fd..ec544b5 100644 --- a/app/Command/spider/BaiduRecordCommand.php +++ b/app/Command/spider/BaiduRecordCommand.php @@ -38,7 +38,7 @@ class BaiduRecordCommand extends BaseSpider public function __construct(protected ContainerInterface $container, LoggerFactory $loggerFactory) { 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() diff --git a/app/Command/spider/BaseSpider.php b/app/Command/spider/BaseSpider.php index e17eda7..8012584 100755 --- a/app/Command/spider/BaseSpider.php +++ b/app/Command/spider/BaseSpider.php @@ -8,7 +8,9 @@ use Hyperf\Command\Command; use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Coroutine\Coroutine; use Hyperf\Di\Annotation\Inject; +use Hyperf\Logger\LoggerFactory; use Laminas\Stdlib\ArrayUtils; +use Psr\Log\LoggerInterface; use Swoole\Coroutine\Channel; use Swoole\Timer; use Symfony\Component\Console\Input\InputInterface; @@ -44,6 +46,8 @@ class BaseSpider extends Command protected array $commandConfigure = []; + protected ?LoggerInterface $commandLogger = null; + private function init() { // 因为最外层还有个父协程, 所以加一 @@ -79,7 +83,7 @@ class BaseSpider extends Command 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(); curl_setopt_array($ch, array( @@ -88,10 +92,13 @@ class BaseSpider extends Command CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 15, + CURLOPT_SSL_VERIFYPEER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => $headers, )); + // curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt($ch, CURLOPT_HEADER, false); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -130,7 +137,7 @@ class BaseSpider extends Command $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) { $printTime = date('H:i:s'); diff --git a/config/autoload/logger.php b/config/autoload/logger.php index 56b4c87..01b4eac 100755 --- a/config/autoload/logger.php +++ b/config/autoload/logger.php @@ -44,7 +44,7 @@ return [ ], ], ], - 'command-baidu-record' => [ + 'command-spider-baidu-record' => [ 'handler' => [ 'class' => Monolog\Handler\RotatingFileHandler::class, '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, + ], + ], + ], ]; diff --git a/storage/view/news/index.blade.php b/storage/view/news/index.blade.php index 8b56b43..c07ede8 100755 --- a/storage/view/news/index.blade.php +++ b/storage/view/news/index.blade.php @@ -142,15 +142,10 @@ $platforms = call_user_func(function () { } }, // field: "published_status", + },{ + field:'created_at', + title: '发布日期' }, - // { - // title: "封面", - // field: "cover", - // templet: function (d) { - // return '' - // }, - // width: 90, - // }, { title: "操作", toolbar: "#table-bar",