WebhookDingtalk.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Http;
  5. use Illuminate\Support\Facades\Log;
  6. class WebhookDingtalk extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'webhook:dingtalk {url} {title} {message}';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'send webhook message to dingtalk';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. if(\App\Tools\Tools::isStop()){
  37. return 0;
  38. }
  39. $url = $this->argument('url');
  40. $param = ["markdown"=> [
  41. "title"=> $this->argument('title'),
  42. "text"=> $this->argument('message'),
  43. ],
  44. "msgtype"=>"markdown"
  45. ];
  46. $this->info("url={$url}");
  47. try{
  48. $response = Http::post($url, $param);
  49. if($response->successful()){
  50. return 0;
  51. }else{
  52. return 1;
  53. }
  54. }catch(\Exception $e){
  55. Log::error($e);
  56. return 1;
  57. }
  58. return 0;
  59. }
  60. }