dingtalk chatbot
1.0.3
Adopt object-oriented development methods
git clone [email protected]:baiyutang/dingtalk-robot.git
orcomposer require baiyutang/dingtalk-robot
- In the
$groups
array in thesrc/config.php
file, modify the DingTalk group robot to push the target group token.- Refer to the sample assembly code
Config.php
file, configure array('group_name'=>'...your token...')
, and then $client = new ChatBot('group_name')
;$client = new ChatBot('param')
, when the parameter received by the constructor is not among the keys of the $groups
array in Config.php
, it will be recognized as a token. // 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 ());
MIT license