1.创建好机器人
2.搭建好消息接收服务器,此处用php实现
image
<?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, array('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);
//$info = curl_getinfo($ch);
//var_dump($info);
curl_close($ch);
return $data;
}
$file_contents = json_decode(file_get_contents('php://input'), true);
$webhook = "https://oapi.dingtalk.com/robot/send?access_token=xxxxx";
$data = array('msgtype' => 'text', 'text' => array('content' => $file_contents ));
$data_string = json_encode($data);
$result = request_by_curl($webhook, $data_string);
echo($data_string);
echo($result);
?>
当@机器人时,机器人会post一段消息到php
php可以处理过后在通过webhook返回消息
网友评论