visuddhinanda 2 năm trước cách đây
mục cha
commit
5e7c2905ee
1 tập tin đã thay đổi với 62 bổ sung0 xóa
  1. 62 0
      app/Tools/WebHook.php

+ 62 - 0
app/Tools/WebHook.php

@@ -0,0 +1,62 @@
+<?php
+namespace App\Tools;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Http;
+
+class WebHook{
+        /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+
+    }
+    public function wechat($url, $title=null, $message=null)
+    {
+
+        $param["msgtype"]="markdown";
+        if(empty($title) &&  empty($message) ){
+            return 0;
+        }
+        if($title !== null){
+            $param["markdown"]['title'] = $title;
+        }
+        if($message !== null){
+            $param["markdown"]['content'] = $message;
+        }
+        return $this->send($url, $param);
+    }
+    public function dingtalk($url, $title=null, $message=null){
+        $param = array();
+        $param["msgtype"]="markdown";
+        if(empty($title) &&  empty($message) ){
+            return 0;
+        }
+        if($title !== null){
+            $param["markdown"]['title'] = $title;
+        }
+        if($message !== null){
+            $param["markdown"]['text'] = $message;
+        }
+
+        return $this->send($url, $param);
+    }
+
+    private function send($url, $param){
+        Log::info($param);
+        try{
+            $response = Http::post($url, $param);
+            if($response->successful()){
+                return 0;
+            }else{
+                return 1;
+            }
+        }catch(\Exception $e){
+            Log::error($e);
+            return 1;
+        }
+        return 0;
+    }
+}