{"id":18493829,"url":"https://github.com/igaowei/laravel-dingbot","last_synced_at":"2026-05-01T04:39:11.893Z","repository":{"id":191715969,"uuid":"685447525","full_name":"iGaoWei/laravel-dingbot","owner":"iGaoWei","description":"钉钉机器人消息推送拓展","archived":false,"fork":false,"pushed_at":"2024-04-10T02:36:04.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-27T20:48:43.469Z","etag":null,"topics":["ding-notice","dingbot","dingtalk","dingtalk-robot","laravel"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iGaoWei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-31T08:50:27.000Z","updated_at":"2024-04-08T00:38:06.000Z","dependencies_parsed_at":"2024-12-25T16:27:10.883Z","dependency_job_id":"3c0cea20-6fa9-405f-865f-ce991fa88f29","html_url":"https://github.com/iGaoWei/laravel-dingbot","commit_stats":null,"previous_names":["igaowei/laravel-dingbot"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iGaoWei%2Flaravel-dingbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iGaoWei%2Flaravel-dingbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iGaoWei%2Flaravel-dingbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iGaoWei%2Flaravel-dingbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iGaoWei","download_url":"https://codeload.github.com/iGaoWei/laravel-dingbot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239208997,"owners_count":19600240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ding-notice","dingbot","dingtalk","dingtalk-robot","laravel"],"created_at":"2024-11-06T13:16:42.538Z","updated_at":"2026-05-01T04:39:06.871Z","avatar_url":"https://github.com/iGaoWei.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 钉钉机器人消息发送\n\n\n# 介绍\n企业内部有较多系统支撑着公司的核心业务流程，譬如CRM系统、交易系统、监控报警系统等等。通过钉钉的自定义机器人，可以将这些系统事件同步到钉钉的聊天群。\nlaravel-dingbot 是一款钉钉机器人消息推送的Laravel扩展，您可以通过此扩展简单高效的推送消息通知到钉钉，进行监控和提醒操作。\n\n### [钉钉官方文档](https://open.dingtalk.com/document/robots/custom-robot-access)\n\n# 安装\n\n```php\ncomposer require dreamcoders/laravel-dingbot\n```\n\n# 在laravel项目中使用\n\n安装成功后执行\n```php\nphp artisan vendor:publish --provider=\"DreamCoders\\DingBot\\DingBotServiceProvider\"\n```\n会自动将`dingbot.php`添加到您项目的config配置文件当中\n\n# 相关配置\n\n```php\nreturn [\n    'webhookUrl' =\u003e env('DING_ROBOT_URL', 'https://oapi.dingtalk.com/robot/send'),\n\n    'default' =\u003e [\n        // 机器人的access_token default\n        'access_token' =\u003e env('DING_TOKEN','4c8ed2083bcd5cc9d38343211900ea29ef7bbef9156ad0892'),\n        // 加签 （不开启加签则为空）\n        'secret' =\u003e env('DING_SECRET',''),\n    ],\n    'bot1' =\u003e [\n        // 机器人的access_token  bot1\n        'access_token' =\u003e env('DING_TOKEN1',''),\n        // 加签 （不开启加签则为空）\n        'secret' =\u003e env('DING_SECRET1',''),\n    ],\n    'bot2' =\u003e [\n        // 机器人的access_token  bot2\n        'access_token' =\u003e env('DING_TOKEN2',''),\n        // 加签 （不开启加签则为空）\n        'secret' =\u003e env('DING_SECRET2',''),\n    ],\n];\n```\n\n\n### 钉钉推送access_token\n- 钉钉推送链接Webhook:https://oapi.dingtalk.com/robot/send?access_token=you-push-token\n- 发送钉钉机器人的token，即在您创建机器人Webhook之后的access_token\n\n.env配置\n```php\nDING_TOKEN=you-push-token\n```\n\n\n### 多机器人配置\n如果想要添加多个机器人，则在`dingbot.php`当中添加机器人名字和对应的token配置即可\n\n```php\n    'default' =\u003e [\n        // 机器人的access_token default\n        'access_token' =\u003e env('DING_TOKEN','4c8ed2083bcd5cc9d38343211900ea29ef7bbef9156ad0892'),\n        // 加签 （不开启加签则留空）\n        'secret' =\u003e env('DING_SECRET',''),\n    ],\n    'bot1' =\u003e [\n        // 机器人的access_token  bot1\n        'access_token' =\u003e env('DING_TOKEN1',''),\n        // 加签 （不开启加签则留空）\n        'secret' =\u003e env('DING_SECRET1',''),\n    ],\n    'bot2' =\u003e [\n        // 机器人的access_token  bot2\n        'access_token' =\u003e env('DING_TOKEN2',''),\n        // 加签 （不开启加签则留空）\n        'secret' =\u003e env('DING_SECRET2',''),\n    ]\n```\n\n.env配置\n```php\nDING_TOKEN=you-push-token\nDING_TOKEN1=you-push-token\n```\n\n# 安全配置\n### 自定义关键词\n最多可以设置10个关键词，消息中至少包含其中1个关键词才可以发送成功。\n例如添加了一个自定义关键词：监控报警，则这个机器人所发送的消息，必须包含监控报警这个词，才能发送成功。\n\n### 加签\n钉钉创建机器人时选择加签，将`secret`复制到对应配置文件中即可，如果开启加签方式，则必须填写`secret`,否则留空即可\n```php\nDING_SECRET=you-bot-secret\nDING_SECRET1=you-bot-secret\nDING_SECRET2=you-bot-secret\n```\n### IP地址（段）\n设定后，只有来自IP地址范围内的请求才会被正常处理。支持两种设置方式：IP地址和IP地址段，暂不支持IPv6地址白名单\n\n\n# 使用示例\n\n## 发送纯文字消息\n```php\nDing()-\u003etext(\"服务器通知报警,请紧急处理\")-\u003esend();\n```\nor\n```php\n(new DingBot())-\u003etext('服务器通知报警,请紧急处理')-\u003esend();\n```\n\n发送消息@指定人员\n```php\nDing()-\u003etext(\"服务器通知报警,请紧急处理\")\n-\u003esetAtMobiles(['13218899188'])\n-\u003esend();\n```\n发送消息@所有人\n```php\nDing()-\u003etext(\"服务器通知报警,请紧急处理\")\n-\u003esetAtAll()\n-\u003esend();\n```\n\n\n## 发送markdown类型的消息\n\n```php\n$title = '杭州天气';\n$markdown = \"#### 杭州天气  \\n \".\n            \"\u003e 9度，@1825718XXXX 西北风1级，空气良89，相对温度73%\\n\\n \".\n            \"\u003e ![screenshot](http://i01.lw.aliimg.com/media/lALPBbCc1ZhJGIvNAkzNBLA_1200_588.png)\\n\".\n            \"\u003e ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \";\n            \nDing()-\u003emarkdown($title,$markdown)-\u003esend();\n```\n发送消息@指定人员/所有人 同上\n\n\n## 发送链接类型的消息\n\n```php\n \n$title = \"自定义机器人协议\";\n$text = \"群机器人是钉钉群的高级扩展功能。群机器人可以将第三方服务的信息聚合到群聊中，实现自动化的信息同步。例如：通过聚合GitHub，GitLab等源码管理服务，实现源码更新同步；通过聚合Trello，JIRA等项目协调服务，实现项目信息同步。不仅如此，群机器人支持Webhook协议的自定义接入，支持更多可能性，例如：你可将运维报警提醒通过自定义机器人聚合到钉钉群。\";\n$picUrl = \"\";\n$messageUrl = \"https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.Rqyvqo\u0026treeId=257\u0026articleId=105735\u0026docType=1\";\n\nDing()-\u003elink($title,$text,$messageUrl,$picUrl)-\u003esend();\n```\n\n\n## 发送ActionCard类型的消息\n\n### 无跳转链接\n```php\n$title = \"乔布斯 20 年前想打造一间苹果咖啡厅，而它正是 Apple Store 的前身\";\n$text = \"![screenshot](@lADOpwk3K80C0M0FoA) \\n\".\n    \" #### 乔布斯 20 年前想打造的苹果咖啡厅 \\n\\n\".\n    \" Apple Store 的设计正从原来满满的科技感走向生活化，而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划\";\n\nDing()-\u003eactionCard($title,$text,1)-\u003esend();\n```\n\n\n### 整体跳转ActionCard类型(single)\n```php\n$title = \"乔布斯 20 年前想打造一间苹果咖啡厅，而它正是 Apple Store 的前身\";\n$text = \"![screenshot](@lADOpwk3K80C0M0FoA) \\n\".\n    \" #### 乔布斯 20 年前想打造的苹果咖啡厅 \\n\\n\".\n    \" Apple Store 的设计正从原来满满的科技感走向生活化，而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划\";\n\nDing()-\u003eactionCard($title,$text,1)\n    -\u003esingle(\"阅读全文\",\"https://www.dingtalk.com/\")\n    -\u003esend();\n```\n### 独立跳转ActionCard类型(btns)\n\n```php\n$title = \"乔布斯 20 年前想打造一间苹果咖啡厅，而它正是 Apple Store 的前身\";\n$text = \"![screenshot](@lADOpwk3K80C0M0FoA) \\n\".\n    \" #### 乔布斯 20 年前想打造的苹果咖啡厅 \\n\\n\".\n    \" Apple Store 的设计正从原来满满的科技感走向生活化，而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划\";\n\nDing()-\u003eactionCard($title,$text,1)\n    -\u003eaddButtons(\"内容不错\",\"https://www.dingtalk.com/\")\n    -\u003eaddButtons(\"不感兴趣\",\"https://www.dingtalk.com/\")\n    -\u003esend();\n```\n\n## 发送FeedCard类型的消息\n\n```php\n       $linksArray = [\n            [\n                \"title\"=\u003e \"时代的火车向前开1通知\",\n                \"messageURL\"=\u003e \"https://www.dingtalk.com/\",\n                \"picURL\"=\u003e \"https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png\"\n            ],\n            [\n                \"title\"=\u003e \"时代的火车向前开2\",\n                \"messageURL\"=\u003e \"https://www.dingtalk.com/\",\n                \"picURL\"=\u003e \"https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png\"\n            ],\n            [\n                \"title\"=\u003e \"时代的火车向前开3\",\n                \"messageURL\"=\u003e \"https://www.dingtalk.com/\",\n                \"picURL\"=\u003e \"https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png\"\n            ],\n            [\n                \"title\"=\u003e \"时代的火车向前开4\",\n                \"messageURL\"=\u003e \"https://www.dingtalk.com/\",\n                \"picURL\"=\u003e \"https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png\"\n            ]\n        ];\n        (new DingBot())-\u003efeedCard($linksArray)-\u003esend();\n        Ding()-\u003efeedCard($linksArray)-\u003esend();\n```\n## 多机器人消息发送\n\n```php\nDing('bot1')-\u003etext(\"服务器通知报警,请紧急处理\")-\u003esend();\n```\nor\n```php\n(new DingBot('bot1'))-\u003etext('服务器通知报警,请紧急处理')-\u003esend();\n```\n其他消息类型同上\n\nenjoy :)\n\n\n- 效果\n![file](https://lccdn.phphub.org/uploads/images/201805/23/6932/q3nLCOPbRj.png?imageView2/2/w/1240/h/0)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figaowei%2Flaravel-dingbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figaowei%2Flaravel-dingbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figaowei%2Flaravel-dingbot/lists"}