commandLogger = $loggerFactory->get('log', 'command-baidu-auto-push'); } public function configure() { parent::configure(); // 普通收录 //使用说明 //1、普通收录工具可以向百度搜索主动推送资源,缩短爬虫发现网站链接的时间,不保证收录和展现效果。 //2、API提交和手动提交共享配额,sitemap提交配额不与其他方式共享,具体配额以站点页面显示数据为准 。配额不可累计,当日有效。 //3、若链接存在跳转关系,请直接提交跳转后链接。如网站换域名,需提交新域名资源;进行HTTPS改造页面,请提交HTTPS资源。 $this->setDescription('自动向百度推送'); $this->addOption('platform', 'p', InputOption::VALUE_OPTIONAL, '指定的平台.', false); } public function execute(InputInterface $input, OutputInterface $output): int { $query = AppWebsiteConfig::query() ->select(['app_domain', 'id']) ->where('is_delete', 0); if ($id = $input->getOption('platform')) { $query = $query->where('id', $id); } $query = $query->get()->toArray(); $pushArray = []; $push = function () use (&$pushArray) { $ch = curl_init(); $options = array( CURLOPT_URL => $this->baseUrl, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $pushArray), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); $pushArray = []; $this->commandLogger->info($result); }; foreach ($query as $item) { $article = AppNews::query()->where('platform', $item['id'])->select(['id'])->limit(10)->orderBy('id', 'DESC')->get()->toArray(); foreach ($article as $articleItem) { $pushArray[] = 'https://' . $item['app_domain'] . '/news/' . $articleItem['id']; } if ($pushArray) { $push(); } } $this->commandLogger->info(print_r($pushArray, true)); return 0; } private function _getTask($brand): \Generator { $query = Db::table('app_brands'); if ($brand) { $query->where(['id' => $brand]); } $query->where('id', '>', 1)->orderBy('id'); foreach ($query->cursor() as $row) { yield $row; } } private function _getTaskName($name): string { return strtolower(strtr($name, [ '.' => '-', ' ' => '-' ])); } public function spiderStart(): void { list($result, $httpCode) = $this->request($this->getBaseUrl() . '/fashion/street-style/'); preg_match_all('/