PHP code example of vinstone / dingtalk-notice
1. Go to this page and download the library: Download vinstone/dingtalk-notice 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/ */
vinstone / dingtalk-notice example snippets
composer
php artisan vendor:publish --provider="DingTalkNotice\Providers\DingTalkNoticeProvider"
$app->register(DingTalkNotice\Providers\DingTalkNoticeProvider::class);
return [
// 默认配置
'default' => [
// 机器人启用开关
'enabled' => env('DINGTALK_ENABLED',true),
// 创建机器人时获取的access_token
'access_token' => env('DINGTALK_ACCESS_TOKEN',''),
// 超时时间
'timeout' => env('DINGTALK_TIMEOUT',2.0),
// 是否启用SSL验证
'ssl_verify' => env('DINGTALK_SSL_VERIFY',true),
// 加签密钥
'secret' => env('DINGTALK_SECRET',''),
],
// 多机器人配置
'log' => [
// 机器人启用开关
'enabled' => env('LOG_DINGTALK_ENABLED',true),
// 创建机器人时获取的access_token
'access_token' => env('LOG_DINGTALK_ACCESS_TOKEN',''),
// 超时时间
'timeout' => env('LOG_DINGTALK_TIMEOUT',2.0),
// 是否启用SSL验证
'ssl_verify' => env('LOG_DINGTALK_SSL_VERIFY',true),
// 加签密钥
'secret' => env('LOG_DINGTALK_SECRET',''),
]
];
use DingTalkNotice\Messages\Text;
$message = new Text('我就是我, @XXX 是不一样的烟火');
use DingTalkNotice\Messages\Link;
$message = new Link('时代的火车向前开', '每当面临重大升级,产品经理们都会取一个应景的代号', 'https://open.dingtalk.com/document/group/custom-robot-access', 'https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png', true);
// 重点:点击消息跳转的URL,PC端默认在侧边栏打开,如需在浏览器打开,请设置第 5 个参数为 false
use DingTalkNotice\Messages\Markdown;
$message = new Markdown('杭州天气', '"#### 杭州天气 @150XXXXXXXX \n > 9度,西北风1级,空气良89,相对温度73%\n');
use DingTalkNotice\Messages\ActionCard;
$message = new ActionCard('乔布斯20年前想打造一间苹果咖啡厅', '
### 乔布斯 20 年前想打造的苹果咖啡厅');
$message->single('阅读全文', 'https://open.dingtalk.com/document/group/custom-robot-access', true);
// 重点:点击按钮触发的URL,PC端默认在侧边栏打开,如需在浏览器打开,请设置第 3 个参数为 false
$message->addButton('内容不错', 'https://www.dingtalk.com/', true);
// 重点:点击按钮触发的URL,PC端默认在侧边栏打开,如需在浏览器打开,请设置第 3 个参数为 false
use DingTalkNotice\Messages\FeedCard;
$message = new FeedCard();
$message->addLink('时代的火车向前开', 'https://www.dingtalk.com/', 'https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png', true);
// 重点:点击单条信息到跳转URL,PC端默认在侧边栏打开,如需在浏览器打开,请设置第 4 个参数为 false
$message->at(['138xxxxxxx']);
$message->at('138xxxxxxxx,139xxxxxxxx');
$message->at('138xxxxxxxx');
$message->atAll();
app(DingTalk::class)->setMessage($message)->send();
dingtalk()->setMessage($message)->send();
app(DingTalk::class)->other('log')->setMessage($message)->send();
dingtalk()->other('log')->setMessage($message)->send();