PHPackages                             calject/ding-robot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. calject/ding-robot

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

calject/ding-robot
==================

钉钉机器人推送

v1.1.1(6y ago)9703MITPHPPHP ^7.0

Since Aug 27Pushed 6y ago1 watchersCompare

[ Source](https://github.com/calject/ding-robot)[ Packagist](https://packagist.org/packages/calject/ding-robot)[ Docs](https://github.com/calject/ding-robot)[ RSS](/packages/calject-ding-robot/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (4)Used By (0)

dingRobot
=========

[](#dingrobot)

**Table of Contents**

- [一、介绍](#%E4%B8%80%E4%BB%8B%E7%BB%8D-top)
- [二、安装教程](#%E4%BA%8C%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B-top)
- [三、说明](#%E4%B8%89%E8%AF%B4%E6%98%8E-top)
    - [3.1 说明](#31-%E8%AF%B4%E6%98%8E)
    - [3.2 推送响应说明](#32-%E6%8E%A8%E9%80%81%E5%93%8D%E5%BA%94%E8%AF%B4%E6%98%8E)
- [四、使用](#%E5%9B%9B%E4%BD%BF%E7%94%A8-top)
    - [4.1 at(@) 说明](#41-at-%E8%AF%B4%E6%98%8E)
    - [4.2 api各类型消息推送使用说明](#42-api%E5%90%84%E7%B1%BB%E5%9E%8B%E6%B6%88%E6%81%AF%E6%8E%A8%E9%80%81%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E)
        - [1. 推送文本消息](#1-%E6%8E%A8%E9%80%81%E6%96%87%E6%9C%AC%E6%B6%88%E6%81%AF)
        - [2. 推送markdown消息](#2-%E6%8E%A8%E9%80%81markdown%E6%B6%88%E6%81%AF)
        - [3. 推送ActionCard类型消息(一)](#3-%E6%8E%A8%E9%80%81ActionCard%E7%B1%BB%E5%9E%8B%E6%B6%88%E6%81%AF%E4%B8%80)
        - [4. 推送ActionCard类型消息(二)](#4-%E6%8E%A8%E9%80%81ActionCard%E7%B1%BB%E5%9E%8B%E6%B6%88%E6%81%AF%E4%BA%8C)
        - [5. 推送link类型消息](#5-%E6%8E%A8%E9%80%81link%E7%B1%BB%E5%9E%8B%E6%B6%88%E6%81%AF)
        - [6. 推送FeedCard类型消息](#6-%E6%8E%A8%E9%80%81FeedCard%E7%B1%BB%E5%9E%8B%E6%B6%88%E6%81%AF)
- [五、拓展](#expand)
    - [1. `markdown` 类型拓展](#expand-1)
    - [2. 消息拓展](#expand-2)

### v1.1.0 新版自定义机器人`webhook`

[](#v110-新版自定义机器人webhook)

- 添加安全验证`加签`实现
- `DingRobot __construct(string $token, string $signToken = null)`

```
# 原创建
$robot = DingRobot::get('access_token');
$robot = new DingRobot('access_token');

# new
$robot = DingRobot::get('access_token', 'signToken | null');
$robot = new DingRobot('access_token', 'signToken | null');

```

### 一、介绍 [top](#dingrobot)

[](#一介绍-top)

钉钉机器人消息推送 简单封装

### 二、安装教程 [top](#dingrobot)

[](#二安装教程-top)

`composer require "calject/ding-robot"`

### 三、说明 [top](#dingrobot)

[](#三说明-top)

#### 3.1 说明

[](#31-说明)

- [官方开发文档](https://open-doc.dingtalk.com/microapp/serverapi2/qf2nxq)

#### 3.2 推送响应说明

[](#32-推送响应说明)

> `DingRobot` 该类未实现对接口响应的处理，默认`request`方法会返回curl原始的返回数据。

- 推送结果处理:

1. 继承`DingRobot`类，并重新`request`方法, 使用自定义的请求类实现并返回
2. 新建类并实现`CalJect\DingRobot\Contacts\IPush`接口
3. 在外部判断响应接口。注: 成功将返回`{"errmsg":"ok","errcode":0}`

- 示例

```
$response = DingRobot::get('access_token')->push(DPushText::make('测试'));
if ($response === false) {
    // success
}else {
    $response = json_decode($response, true);
    if ($response['errcode'] === 0) {
        // success
    }else {
        // error
        $err_msg = $response['errmsg'];
        $err_code = $response['errcode'];
    }
}
```

### 四、使用 [top](#dingrobot)

[](#四使用-top)

#### 4.1 at(@) 说明

[](#41-at-说明)

1. 在`message`实例中若提供有`atAll()`或者`atMobile()`,则表示该类型消息可以@指定或者所有人

- 示例1 @所有人

```
$message = DPushText::make('这是一条测试消息');
$message->atAll();
DingRobot::get('access_token')->push($message);
```

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_at_all.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_at_all.png)

- 示例2 @指定的人

```
$message = DPushText::make('这是一条测试消息');
// $message->atMobiles('156********');  // at 单人
// $message->atMobiles('156********', '176********'); //1: at 多人
// $message->atMobiles(['156********', '176********']); //2: at 多人
DingRobot::get('access_token')->push($message);
```

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_at_mobile.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_at_mobile.png)

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_at_mobile_more.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_at_mobile_more.png)

2. `@所有人`文本显示与隐藏, 部分消息需要设置该参数以显示`@所有人`文本

- 例`DPushMD`类型消息推送时设置`atAll()`,会@群内所有人，但是不显示`@所有人`的文本
- 如果需要显示`@所有人`文本，需要额外设置`isShowAtAll(true)`参数

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_md_at_all.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_md_at_all.png)

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_md_at_mobile.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_md_at_mobile.png)

#### 4.2 api各类型消息推送使用说明

[](#42-api各类型消息推送使用说明)

##### 1. 推送文本消息

[](#1-推送文本消息)

```
$message = DPushText::make('这是一条测试消息');
DingRobot::get('access_token')->push($message);
```

- 推送示例

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_text_message.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_text_message.png)

##### 2. 推送`markdown`消息

[](#2-推送markdown消息)

```
$message = DPushMD::make('左侧标题');
$message->appendTitle('Title');
$message->appendCite('text: cite');
$message->appendHyperlink('百度', 'http://www.baidu.com');
$message->appendImage('https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=22102217,2573612035&fm=27&gp=0.jpg');
$message->appendItemsOrderly([' o-item1', ' o-item2', ' o-item3']);
$message->appendText(new class('自定义测试文本', 'custom') extends AbsMDText {

    /**
     * handle the text
     * @param string $text
     * @param array $args
     * @return string
     */
    public function handle(string $text, ... $args): string
    {
        return 'content: ' . $text . self::NEXT_LINE.
            '传入参数: ' . json_encode($args, JSON_UNESCAPED_UNICODE) . self::NEXT_LINE .
            '处理结果: ' . '* '.$text;
    }
});

DingRobot::get('access_token')->push($message);
```

- 推送示例

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_md_message.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_md_message.png)

##### 3. 推送`ActionCard`类型消息(一)

[](#3-推送actioncard类型消息一)

```
/* ======== 设置描述文本(markdown或者纯文本) ======== */
$message = DPushActionCardList::make("聊天显示概要");
$message->appendCite("审批申请！");
$message->appendCite("这是一段审批简介1");
$message->appendCite("这是一段审批简介2");
$message->appendCite(MDTextHyperlink::make('详情', 'http://www.baidu.com'));
/* ======== 设置排列方式为横向 ======== */
$message->setBtnOrientation(DPushActionCard::BTN_ORIENTATION_HORIZONTAL);
$message->appendBtn("同意","http://www.baidu.com");
$message->appendBtn("拒绝", "http://www.baidu.com");
DingRobot::get('access_token')->push($message);
```

- 横向排列示例 `$message->setBtnOrientation(DPushActionCard::BTN_ORIENTATION_HORIZONTAL);`

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_btn_list_horizontal.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_btn_list_horizontal.png)

- 竖直排列示例 `$message->setBtnOrientation(DPushActionCard::BTN_ORIENTATION_VERTICAL);`

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_btn_list_vertical.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_btn_list_vertical.png)

##### 4. 推送`ActionCard`类型消息(二)

[](#4-推送actioncard类型消息二)

```
$message = DPushActionCardOne::make("聊天显示概要");
$message->appendTitle("标题");
$message->appendCite("概要介绍1");
$message->appendCite("概要介绍2");

$message->setSingleTitle("这是跳转链接标题");
$message->setSingleURL("http://www.baidu.com");
DingRobot::get('access_token')->push($message);
```

- 推送示例

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_action_card.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_action_card.png)

##### 5. 推送`link`类型消息

[](#5-推送link类型消息)

```
$messageUrl = 'https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1548921909883_R&pv=&ic=&nc=1&z=&hd=&latest=&copyright=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&hs=2&word=%E7%8B%82%E4%B8%89';
$picUrl = 'https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1548922085&di=4f7f0aa0f29792e6c5d38cc1fe29e994&src=http://b-ssl.duitang.com/uploads/item/201607/29/20160729212858_FyiLZ.jpeg';
$text = '简介，即简明扼要的介绍。是当事人全面而简洁地介绍情况的一种书面表达方式，它是应用写作学研究的一种日常应用文体。';
$message = DPushLink::make("百度一下，你就知道", $text, $messageUrl, $picUrl);
DingRobot::get('access_token')->push($message);
```

- 推送示例

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_link.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_link.png)

##### 6. 推送`FeedCard`类型消息

[](#6-推送feedcard类型消息)

```
$message = DPushFeedCard::make();
$message->appendLink("大标题", "http://www.baidu.com", "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1548932526783&di=3d8345d0e2657a52310575f6a2ad47ed&imgtype=0&src=http%3A%2F%2Fs7.sinaimg.cn%2Fmw690%2F006886pozy74XL8aocu76%26690");
$message->appendLink("小标题1", "http://www.baidu.com", "http://imgsrc.baidu.com/imgad/pic/item/34fae6cd7b899e51fab3e9c048a7d933c8950d21.jpg");
$message->appendLink("小标题2", "http://www.baidu.com", "http://img15.3lian.com/2015/a1/14/d/23.jpg");
$message->appendLink("小标题3", "http://www.baidu.com", "http://f7.topitme.com/7/91/0f/11321340208bd0f917o.jpg");
DingRobot::get('access_token')->push($message);
```

- 推送示例

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_feed_card.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_feed_card.png)

### 五、拓展 [top](#dingrobot)

[](#五拓展-top)

1\. `markdown` 类型拓展

继承`CalJect\DingRobot\Contacts\MarkDown\AbsMDText`抽象类，并实现`handle`函数，返回处理后的文本

2\. 消息拓展

```
1. 继承`CalJect\DingRobot\Contacts\PushData\AbsPushDataAt` 或 `CalJect\DingRobot\Contacts\PushData\AbsPushData` 抽象类，实现`type()`方法返回消息类型，实现`typeData()`方法返回消息实体数据
2. 继承已有的数据模型，并重写或拓展方法

```

- 示例 `CalJect\DingRobot\Model\Customs\DPushException` 实现了一个自定义异常消息推送

```
$exception = new \Exception('这是一条异常消息', 500);
$message = DPushException::make($exception);
DingRobot::get('access_token')->push($message);
```

[![Image text](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_custom_message.png)](https://raw.githubusercontent.com/calject/resources/master/ding-robot/images/robot_custom_message.png)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Total

3

Last Release

2340d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eaa53504f6aa5ddf4f9749d54fbaae3adef90963da9241c244506f4148e044dd?d=identicon)[calject](/maintainers/calject)

---

Top Contributors

[![chanlly](https://avatars.githubusercontent.com/u/18607258?v=4)](https://github.com/chanlly "chanlly (5 commits)")[![calject](https://avatars.githubusercontent.com/u/52476799?v=4)](https://github.com/calject "calject (2 commits)")

---

Tags

phppushrobotdingdingDing

### Embed Badge

![Health badge](/badges/calject-ding-robot/health.svg)

```
[![Health](https://phpackages.com/badges/calject-ding-robot/health.svg)](https://phpackages.com/packages/calject-ding-robot)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)[calchen/laravel-dingtalk-robot-notification

钉钉智能群助手 Laravel/Lumen 消息通知扩展包（Dingtalk robot message notifications for Laravel/Lumen）

2326.4k](/packages/calchen-laravel-dingtalk-robot-notification)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
