PHP code example of baiyutang / dingtalk-chatbot

1. Go to this page and download the library: Download baiyutang/dingtalk-chatbot 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/ */

    

baiyutang / dingtalk-chatbot example snippets


// text 类型
use DingTalkRobot\At;
use DingTalkRobot\GroupChat;
use DingTalkRobot\Messages\TextMessage;
use DingTalkRobot\ChatBot;

// 链式调用设置 @ 多个手机号
$at = new At();
$at->setMobile('181****3753')
    ->setMobile('181****3751');

// 链式调用设置消息内容
$message = new TextMessage();
$message->setContent('我就是我, 是不一样的烟火')
    ->setAt($at);

$client = new ChatBot();
// 可以指定群,若不设置则发送默认的群
$client->send($message, new GroupChat('other'));

// markdown 类型
use DingTalkRobot\GroupChat;
use DingTalkRobot\Messages\MarkdownMessage;
use DingTalkRobot\ChatBot;

$markdown = new MarkdownMessage();
$markdown->setTitle('杭州天气')
    ->setText("#### 杭州天气\n" .
        "> 9度,西北风1级,空气良89,相对温度73%\n" .
        "> ![screenshot](http://tinyurl.com/y4lbucte)\n" .
        "> 10点20分发布 [天气](http://www.thinkpage.cn/)");

$client = new ChatBot();

$client->send($markdown, new GroupChat());