WebHook.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. class WebHook extends Command
  5. {
  6. /**
  7. * The name and signature of the console command.
  8. *
  9. * @var string
  10. */
  11. protected $signature = 'message:webhook {listener} {url} {title} {message}';
  12. protected $url = [
  13. "dingtalk1"=>"https://oapi.dingtalk.com/robot/send?access_token=34143dbec80a8fc09c1cb5897a5639ee3a9a32ecfe31835ad29bf7013bdb9fdf",
  14. "weixin1"=>"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9693cceb-bd2e-40c9-8c0c-3260b2c50aa8",
  15. ];
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '发送消息到一个服务器机器人,';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return int
  35. */
  36. public function handle()
  37. {
  38. switch ($this->argument('listener')) {
  39. case 'weixin':
  40. # code...
  41. break;
  42. case 'dingtalk':
  43. # code...
  44. $url = $url[$this->argument('url')];
  45. $param = [
  46. "markdown"=> [
  47. "title"=> $this->argument('title'),
  48. "text"=> $this->argument('message'),
  49. ],
  50. "msgtype"=>"markdown"
  51. ];
  52. break;
  53. default:
  54. # code...
  55. break;
  56. }
  57. $response = Http::post($url, $param);
  58. return 0;
  59. }
  60. }