Explorar el Código

增加 最新更新消息

visuddhinanda hace 3 años
padre
commit
2e9a65ea1d

+ 5 - 1
app/Console/Commands/UpgradeDaily.php

@@ -71,7 +71,11 @@ class UpgradeDaily extends Command
 				'url' => 'dingtalk1',
 				'title' => "后台任务",
 				'message' => "wikipali: 每日统计后台任务执行完毕。用时{$time}",
-			]);			
+			]);
+			$this->call('message:webhookarticlenew',[
+				'host' => 'https://oapi.dingtalk.com/robot/send?access_token=34143dbec80a8fc09c1cb5897a5639ee3a9a32ecfe31835ad29bf7013bdb9fdf',
+				'type' => 'dingtalk',
+			]);
 		}
 
 

+ 80 - 0
app/Console/Commands/WebHookArticleNew.php

@@ -0,0 +1,80 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Http;
+
+class WebHookArticleNew extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'message:webhookarticlenew {host} {type}';
+
+    /**
+     * 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()
+    {
+		# 获取最新文章数据
+		$url = env('APP_URL',"http://127.0.0.1:8000")."/api/v2/progress?view=chapter&channel_type=translation";
+
+		$response = Http::get($url);
+		if($response->successful()){
+			$this->info("get data ok");
+			$data = $response['data']['rows'];
+			$title = "2022-7-3更新";
+			$message = "# wikipali:最新更新\n\n";
+			for ($i=0; $i < 4; $i++) { 
+				# code...
+				$row = $data[$i];
+				$book = $row['book'];
+                $para = $row['para'];
+                $title = $row['toc'];
+				$link = env('APP_URL',"http://127.0.0.1:8000")."/app/article/index.php?view=chapter&book={$book}&par={$para}";
+				$message .= "1. [{$title}]({$link})\n";				
+			}
+			$this->info($message);
+			$url = $this->argument('host');
+			switch ($this->argument('type')) {
+				case "dingtalk":
+					$param = [
+						"markdown"=> [
+							"title"=> $title, 
+							"text"=> $message, 
+						], 
+						"msgtype"=>"markdown"
+						];
+					break;
+				case "wechat":
+					break;
+			}
+			$response = Http::post($url, $param);
+		}else{
+			$this->error("章节数据获取错误");
+		}
+        return 0;
+    }
+}