PHP code example of ljguo-latex / dingtalk-robot

1. Go to this page and download the library: Download ljguo-latex/dingtalk-robot library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ljguo-latex / dingtalk-robot example snippets


use DingTalk\Robot;

$robot = new Robot('ACCESS_TOKEN', 'SECRET'); // SECRET 可省略(不启用加签)

$robot->text('服务器 CPU 超过 90%')
      ->at(['138xxxxxxxx'])   // @指定手机号
      ->send();

$robot->text('紧急通知')->atAll()->send(); // @全体

$robot->markdown('上线通知', "## v1.2.0 已上线\n- 修复登录 bug\n- 新增导出功能")
      ->at(['138xxxxxxxx'])
      ->send();

$robot->link('每日周报', '本周精选文章,点击查看', 'https://example.com/weekly', 'https://example.com/cover.jpg')
      ->send();

$robot->actionCard('请假审批', '张三申请 2026-05-08 ~ 05-10 请假')
      ->single('去审批', 'https://example.com/approve/123')
      ->send();

$robot->actionCard('代码审查', '## PR #88\n新增支付模块')
      ->addButton('合并', 'https://example.com/pr/88/merge')
      ->addButton('拒绝', 'https://example.com/pr/88/reject')
      ->horizontal()  // 横排,默认竖排
      ->send();

$robot->feedCard()
      ->addLink('Go 1.22 新特性', 'https://example.com/go122', 'https://example.com/go.png')
      ->addLink('PHP 8.4 发布',   'https://example.com/php84', 'https://example.com/php.png')
      ->send();

use DingTalk\Exception\DingTalkException;

try {
    $robot->text('Hello')->send();
} catch (DingTalkException $e) {
    echo $e->getMessage();
}