php对接钉钉机器人报警接口

 

 

 

 

 

 

 

 

 

 

<?php
    
function request_by_curl($remote_server, $post_string)
{

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $remote_server);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_HTTPHEADER,
        ['Content-Type: application/json;charset=utf-8']);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // 线下环境不用开启curl证书验证, 未调通情况可尝试添加该代码
    // curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
    // curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $data = curl_exec($ch);

    curl_close($ch);
    
    return $data;


    
}
 
// 机器人hook地址,access_token需要更换成自己的token哦!
$webhook = "https://oapi.dingtalk.com/robot/send?access_token=29ad07bbee37f32e8185f65a557932d80ac069fc";
$message = "【报警】头像更换完成~";  //内容必须要包含关键字,如你设置的是“报警”
$atMobile = ['158****423'];
$isAtAll = false;
$data = [
    'msgtype' => 'text',
    'text'    =>
        ['content' => $message],
    'at'      => [
        'atMobiles' => $atMobile,
        'isAtAll' => $isAtAll,
    ],
    
];
$data_string = json_encode($data);
 
$result = request_by_curl($webhook, $data_string);
echo $result;

 

posted on 2023-03-02 12:13  泽一年  阅读(40)  评论(0编辑  收藏  举报

导航