WebHook.php 1.7 KB

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