baiduCommand.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\NewsModels\News;
  4. use Illuminate\Console\Command;
  5. class baiduCommand extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'baidu';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '百度站长推送';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. $urls = [
  36. 'https://www.jhcs888.com/#/Home',
  37. 'https://www.jhcs888.com/#/AboutUs',
  38. 'https://www.jhcs888.com/#/Cooperation',
  39. 'https://www.jhcs888.com/#/News',
  40. 'https://www.jhcs888.com/#/Contact',
  41. ];
  42. $news=News::where('is_del',0)->select(['id'])->get();
  43. foreach ($news as $new){
  44. $urls[]='https://www.jhcs888.com/#/NewDetail?id='.$new->{'id'};
  45. }
  46. $api = 'http://data.zz.baidu.com/urls?site=https://www.jhcs888.com&token=AhKx7OpIGiJFvpEK';
  47. $ch = curl_init();
  48. $options = array(
  49. CURLOPT_URL => $api,
  50. CURLOPT_POST => true,
  51. CURLOPT_RETURNTRANSFER => true,
  52. CURLOPT_POSTFIELDS => implode("\n", $urls),
  53. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  54. );
  55. curl_setopt_array($ch, $options);
  56. $result = curl_exec($ch);
  57. dd($result);
  58. }
  59. }