先来看下实现效果:
代码如下:
function send_dingtalk_markdown($webhook = '', $title = '', $message = "", $atMobiles = [], $atUserIds = [])
{$data = ["msgtype" => "markdown","markdown" => ["title" => $title,"text" => $message],"at" => ["atMobiles" => $atMobiles,"atUserIds" => $atUserIds,"isAtAll" => false]];return $this->request_by_curl($webhook, json_encode($data));
}$webhook = "https://oapi.dingtalk.com/robot/send?access_token=df1bb3bcce6a375eaaaed1112e13d1365a3ef4990ce9afc8c548005662bf7668";
$nowTime = date('y-m-d H:i:s',time());
$shareImg='https://opc.ahuyikao.com/files/system/2023/06-29/111337117bd7364902.jpg?6.13.3';
$title ='实时战报';
$atMobiles = [];//注意一定要是数组,不然@指定人实现不了,钉钉手机号 或者钉钉id其中一个参数就可以
$atUserIds=['141346562326214344'];
$corpName = '泡泡军团';
$msg = '风一样自由';
$msgContent="恭喜{$corpName} @141346562326214344 完成业绩100.00元 \n > {$msg}\n > ![screenshot]({$shareImg})\n > {$nowTime} [测试中心](https://www.ahuyikao.com) \n";
$result = $this->send_dingtalk_markdown($webhook, $title, $msgContent, $atMobiles, $atUserIds);
完事了,
忘记如何测试配置了 看下图
1.发起群聊 创建群聊
2.群里创建机器人
最后一部点击完成 会出现一个请求地址:
搞定 快去试试吧~~
其他机器人发送类型 查看钉钉文档