Explorar o código

给机器人发消息命令

visuddhinanda %!s(int64=3) %!d(string=hai) anos
pai
achega
5882e401e5
Modificáronse 2 ficheiros con 79 adicións e 19 borrados
  1. 13 19
      app/Console/Commands/UpgradeDaily.php
  2. 66 0
      app/Console/Commands/WebHook.php

+ 13 - 19
app/Console/Commands/UpgradeDaily.php

@@ -40,18 +40,14 @@ class UpgradeDaily extends Command
     public function handle()
     {
         $start = time();
-        $url = "https://oapi.dingtalk.com/robot/send?access_token=34143dbec80a8fc09c1cb5897a5639ee3a9a32ecfe31835ad29bf7013bdb9fdf";
-        $param = [
-        "markdown"=> [
-            "title"=> "后台任务", 
-            "text"=> " wikipali: 每日统计后台任务开始执行。", 
-        ], 
-        "msgtype"=>"markdown"
-        ];
-        $response = Http::post($url, $param);
-
+		$this->call('message:webhook',[
+			'listener' => 'dingtalk',
+			'url' => 'dingtalk1',
+			'title' => "后台任务",
+			'message' => " wikipali: 每日统计后台任务开始执行。",
+		]);
         # 刷巴利语句子uuid 仅调用一次
-        //$this->call('upgrade:palitextid');
+        $this->call('upgrade:palitextid');
         //巴利原文段落库目录结构改变时运行
         $this->call('upgrade:palitext'); 
         #巴利段落标签
@@ -65,15 +61,13 @@ class UpgradeDaily extends Command
         $this->call('upgrade:wbwanalyses');
 
         $time = time()-$start;
-        $param = [
-        "markdown"=> [
-            "title"=> "后台任务", 
-            "text"=> " wikipali: 每日统计后台任务执行完毕。用时{$time}", 
-        ], 
-        "msgtype"=>"markdown"
-        ];
 
-        $response = Http::post($url, $param);
+		$this->call('message:webhook',[
+			'listener' => 'dingtalk',
+			'url' => 'dingtalk1',
+			'title' => "后台任务",
+			'message' => "wikipali: 每日统计后台任务执行完毕。用时{$time}",
+		]);;
 
         return 0;
     }

+ 66 - 0
app/Console/Commands/WebHook.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class WebHook extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'message:webhook {listener} {url} {title} {message}';
+	protected $url = [
+		"dingtalk1"=>"https://oapi.dingtalk.com/robot/send?access_token=34143dbec80a8fc09c1cb5897a5639ee3a9a32ecfe31835ad29bf7013bdb9fdf",
+		"weixin1"=>"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9693cceb-bd2e-40c9-8c0c-3260b2c50aa8",
+	];
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '发送消息到一个服务器机器人,';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+		switch ($this->argument('listener')) {
+			case 'weixin':
+				# code...
+				break;
+			case 'dingtalk':
+				# code...
+				$url = $url[$this->argument('url')];
+				$param = [
+				"markdown"=> [
+					"title"=> $this->argument('title'), 
+					"text"=> $this->argument('message'), 
+				], 
+				"msgtype"=>"markdown"
+				];
+				break;				
+			default:
+				# code...
+				break;
+		}
+		$response = Http::post($url, $param);
+        return 0;
+    }
+}