Feishu.php 2.2 KB
<?php
namespace Jiaoyin;

class Feishu{
    //发送预警通知
    static public function send($content)
    {
        $url = 'https://open.feishu.cn/open-apis/bot/v2/hook/f30bbb72-091c-499d-a577-43c45dceb158';
        $content = [
            'msg_type'=>"text",
            'content'=>[
                'text'=>$content
            ]
        ];
        $con = json_encode($content);
        return self::send_post_json($url,$con);
    }

    static public function sendNoError($content)
    {
        $url = 'https://open.feishu.cn/open-apis/bot/v2/hook/a344e313-4d5d-4aa4-912b-dda37b2e3ee8';
        $content = [
            'msg_type'=>"text",
            'content'=>[
                'text'=>$content
            ]
        ];
        $con = json_encode($content);
        return self::send_post_json($url,$con);
    }

    static public function notice($content,$channel="warning")
    {
        $urls = [
            'follow' => 'https://open.feishu.cn/open-apis/bot/v2/hook/f30bbb72-091c-499d-a577-43c45dceb158',
            'warning' => 'https://open.feishu.cn/open-apis/bot/v2/hook/d48c2e4a-0ef9-4684-88d4-e62d878fdaca',
            'error' => 'https://open.feishu.cn/open-apis/bot/v2/hook/a344e313-4d5d-4aa4-912b-dda37b2e3ee8',
        ];
        $url  = $urls[$channel] ?? $urls['warning'];
        $content = [
            'msg_type'=>"text",
            'content'=>[
                'text'=>$content
            ]
        ];
        $con = json_encode($content);
        return self::send_post_json($url,$con);
    }


    static public function send_post_json($url, $jsonStr)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json; charset=utf-8',
                'Content-Length: ' . strlen($jsonStr)
            )
        );
        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return array($httpCode, $response);
    }
}