钉钉机器人消息推送php

钉钉群机器人定义


$webhook = "https://oapi.dingtalk.com/robot/send?access_token=xxxx";//access_token在刚刚新建的机器人里面有

        // text类型
        $textString = json_encode([
            'msgtype' => 'text',
            'text' => [
                "content" => "1"
            ],
            'at' => [
                'atMobiles' => [
                    "156xxxx8827",
                    "189xxxx8325"
                ],
                'isAtAll' => false

            ]
        ]);
        $result = request_by_curl($webhook, $textString);
//request_by_curl方法
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;
}

效果

消息类型官方说明文档地址:https://ding-doc.dingtalk.com/doc#/serverapi3/xxxza0

Pasa吴技术博客
请先登录后发表评论
  • latest comments
  • 总共0条评论