WebHook.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. if(\App\Tools\Tools::isStop()){
  40. return 0;
  41. }
  42. switch ($this->argument('listener')) {
  43. case 'weixin':
  44. break;
  45. case 'dingtalk':
  46. # code...
  47. $url = $this->url[$this->argument('url')];
  48. $param = [
  49. "markdown"=> [
  50. "title"=> $this->argument('title'),
  51. "text"=> $this->argument('message'),
  52. ],
  53. "msgtype"=>"markdown"
  54. ];
  55. break;
  56. default:
  57. # code...
  58. break;
  59. }
  60. $response = Http::post($url, $param);
  61. return 0;
  62. }
  63. }