WebHook.php 1.4 KB

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