WebHookArticleNew.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Http;
  5. class WebHookArticleNew extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'message:webhookarticlenew {host} {type}';
  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 int
  32. */
  33. public function handle()
  34. {
  35. # 获取最新文章数据
  36. $url = env('APP_URL',"http://127.0.0.1:8000")."/api/v2/progress?view=chapter&channel_type=translation";
  37. $response = Http::get($url);
  38. if($response->successful()){
  39. $this->info("get data ok");
  40. $data = $response['data']['rows'];
  41. $title = "2022-7-3更新";
  42. $message = "# wikipali:最新更新\n\n";
  43. for ($i=0; $i < 4; $i++) {
  44. # code...
  45. $row = $data[$i];
  46. $book = $row['book'];
  47. $para = $row['para'];
  48. $title = $row['toc'];
  49. $link = env('APP_URL',"http://127.0.0.1:8000")."/app/article/index.php?view=chapter&book={$book}&par={$para}";
  50. $message .= "1. [{$title}]({$link})\n";
  51. }
  52. $this->info($message);
  53. $url = $this->argument('host');
  54. switch ($this->argument('type')) {
  55. case "dingtalk":
  56. $param = [
  57. "markdown"=> [
  58. "title"=> $title,
  59. "text"=> $message,
  60. ],
  61. "msgtype"=>"markdown"
  62. ];
  63. break;
  64. case "wechat":
  65. break;
  66. }
  67. $response = Http::post($url, $param);
  68. }else{
  69. $this->error("章节数据获取错误");
  70. }
  71. return 0;
  72. }
  73. }