setDescription('自动向百度推送'); } public function execute(InputInterface $input, OutputInterface $output): int { $url = AppWebsiteConfig::query()->select(['app_domain', 'id'])->where('is_delete', 0)->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 = []; var_dump($result); }; foreach ($url as $item) { $article = AppNews::query()->where('platform', $item['id'])->select(['id'])->get()->toArray(); foreach ($article as $articleItem) { $pushArray[] = 'https://' . $item['app_domain'] . '/news/' . $articleItem['id']; } if ($pushArray) { $push(); } } // echo $result; // var_dump($result); var_dump($pushArray); 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('/