PHP code example of martialbe / laravel-dingtalk
1. Go to this page and download the library: Download martialbe/laravel-dingtalk 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/ */
martialbe / laravel-dingtalk example snippets
'aliases' => [
// ...
'Dingtalk' => Martialbe\LaravelDingtalk\Facade::class,
],
\Dingtalk::CustomBot()
->setMessage(\Martialbe\LaravelDingtalk\BasicService\Message::text(["content" => "你好"])->toArray())->send();
\Dingtalk::CustomBot('other');
$config = [
'app_key' => 'sdfsdfrgert',
'app_secret' => 'ertefdrgdfgdgtryrt',
];
$app = \Dingtalk::WorkBot($config);
// OR
$app = \Dingtalk::WorkBot('default');
use Martialbe\LaravelDingtalk\BasicService\Message;
$app = \Dingtalk::WorkBot();
$app->messages->batchSend("userId", Message::text(['content' => "这是文本测试"], 'api')->toArray());
//OR
$app->messages->batchSend(["userId 1", "userId 2"], Message::text(['content' => "这是文本测试"], 'api')->toArray());
$app = \Dingtalk::WorkBot();
$app->messages->batchRecall("processQueryKey");
//OR
$app->messages->batchRecall(["processQueryKey 1", "processQueryKey 2"]);
$app = \Dingtalk::WorkBot();
$app->messages->readStatus("processQueryKey");
use Martialbe\LaravelDingtalk\BasicService\Message;
$app = \Dingtalk::WorkBot();
$app->messages->groupMessagesSend("openConversationId", Message::text(['content' => "这是文本测试"], 'api')->toArray());
$app = \Dingtalk::WorkBot();
$app->messages->groupMessagesRecall("openConversationId", "processQueryKey");
$app = \Dingtalk::WorkBot();
$app->messages->groupMessagesQuery("openConversationId", "processQueryKey", $maxResults = 200, $nextToken = "");
$app = \Dingtalk::WorkBot();
$app->interactiveCards->personSend("cardTemplateId", "usersId", $params);
$outTrackId = $app->interactiveCards->getOutTrackId();
$app = \Dingtalk::WorkBot();
$app->interactiveCards->register($params);
use Martialbe\LaravelDingtalk\BasicService\InteractiveCard;
$params = (new InteractiveCard())
->setHeader(function ($header)
{
$header->setText("公告:测试TuWenCard01")
->setIco("https://static.dingtalk.com/media/lALPDe7syH8nG_wcHA_28_28.png")
->setColor("#00B853");
})
->setContents(function ($content)
{
$content->setType("DESCRIPTION")
->setText("大家按照这个格式填写下,每周我会做一个统计和公布哈,和大家同步下我们的进展");
})
->setContents(function ($content)
{
$content->setType("IMAGE")
->setText("@lALPDeREVttTpCrNA6rNA6o");
})
->setContents(function ($content)
{
$content->setType("MARKDOWN")
->setText("#测试无序列表\n* ✅预览区域代码高亮\n* ✅所有选项自动记忆\n开始**加粗**结束\n开始*斜体*结束\n开始***加粗与斜体***结束\n<font color=#00B042 size=15>测试:【正向文字:用于表达上涨上升、正向反馈文字,禁止大面积使用。】【15号字体】**【加粗】**</font>\n<font color=#FF5219 size=12>测试:【报错:用户内容报错、警示内容,禁止大面积使用。】【12号字体】*【斜体】*</font>");
})
->setActions(function ($action)
{
$action->setId(1)
->setText("同意")
->setAfterClickText("已同意")
->setIco("@lALPDeREVttTpCrNA6rNA6o")
->setStatus("NORMAL")
->setActionType("LWP");
})
->setActions(function ($action)
{
$action->setId(2)
->setText("不同意")
->setAfterClickText("已拒绝")
->setIco("@lALPDeREVttTpCrNA6rNA6o")
->setStatus("NORMAL")
->setActionType("LWP");
})
->setActionDirection("HORIZONTAL")
->toArray();
$app = \Dingtalk::WorkBot();
$app->interactiveCards->personSend("cardTemplateId", "usersId", $params);
$outTrackId = $app->interactiveCards->getOutTrackId();
$app = \Dingtalk::WorkBot();
$app->interactiveCards->groupSend("cardTemplateId", "openConversationId", $params);
$outTrackId = $app->interactiveCards->getOutTrackId();
$app = \Dingtalk::WorkBot();
$data = [
"outTrackId" => "VWQKWfWD7aIltxEZp6eIvhytdCsyzo1L",
"cardData" => [
"cardParamMap" => [
"title" => "更新",
"type" => "审核成功了吧",
"status" => "成功了😄",
"reason" => "# 嗯嗯",
]
]
];
$app->interactiveCards->update($data);
$app = \Dingtalk::WorkBot();
$app->interactiveCards->personSendTemplates("TuWenCard02", "userId", [ "cardData" => json_encode( $msg ), "callbackUrl" => "you callback"])
$outTrackId = $app->interactiveCards->getOutTrackId();
$app = \Dingtalk::WorkBot();
$app->interactiveCards->groupSendTemplates("TuWenCard02", "openConversationId", [ "cardData" => json_encode( $msg ), "callbackUrl" => "you callback"])
$outTrackId = $app->interactiveCards->getOutTrackId();
use Martialbe\LaravelDingtalk\BasicService\Message;
\Dingtalk::CustomBot()
->setMessage(Message::text(["content" => "这是通过wehook发送的消息"])->toArray())->send();
use Martialbe\LaravelDingtalk\BasicService\Message;
// 内部机器人
$sendMessage = Message::text(["content" => "这是通过wehook发送的消息"], 'api')->toArray();
// webhook机器人 默认
$sendMessage = Message::text(["content" => "这是通过wehook发送的消息"])->toArray();
use Martialbe\LaravelDingtalk\BasicService\Message;
// 内部机器人
$sendMessage = Message::markdown(['title' => "我会发送markdown了~~", 'text' => "# 我会发送markdown了\n > 😸🤣"], 'api')->toArray();
// webhook机器人 默认
$sendMessage = Message::markdown(['title' => "我会发送markdown了~~", 'text' => "# 我会发送markdown了\n > 😸🤣"], 'api')->toArray();
use Martialbe\LaravelDingtalk\BasicService\Message;
// 内部机器人
$sendMessage = Message::link(['title' => "sampleLink消息测试", "text" => "消息内容测试", "picUrl" => "http://img", "messageUrl" => "https://google.com"], 'api')->toArray();
// webhook机器人 默认
$sendMessage = Message::link(['title' => "sampleLink消息测试", "text" => "消息内容测试", "picUrl" => "http://img", "messageUrl" => "https://google.com"])->toArray();
use Martialbe\LaravelDingtalk\BasicService\Message;
// 内部机器人
$sendMessage = Message::singleAction(['title' => "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", "text" => "![screenshot](https://img)\n#### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", "singleTitle" => "查看详情", "singleURL" => "https://google.com"], 'api')->toArray();
// webhook机器人 默认
$sendMessage = Message::singleAction(['title' => "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", "text" => "![screenshot](https://img)\n#### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", "singleTitle" => "查看详情", "singleURL" => "https://google.com"])->toArray();
use Martialbe\LaravelDingtalk\BasicService\Message;
// 内部机器人
$sendMessage = Message::btnsAction(["btnOrientation" => 0, 'title' => "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", "text" => "![screenshot](https://img)\n#### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", "btns" => [['title' => "查看详情", "actionURL" => "https://google.com"], ['title' => "不感兴趣", "actionURL" => "https://google.com"]]], 'api')->toArray();
// webhook机器人 默认
$sendMessage = Message::btnsAction(["btnOrientation" => 0, 'title' => "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", "text" => "![screenshot](https://img)\n#### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", "btns" => [['title' => "查看详情", "actionURL" => "https://google.com"], ['title' => "不感兴趣", "actionURL" => "https://google.com"]]])->toArray();
use Martialbe\LaravelDingtalk\BasicService\Message;
// 内部机器人
$sendMessage = Message::image(['photoURL' => "https://img"], 'api')->toArray();
// webhook机器人 不支持该类型
use Martialbe\LaravelDingtalk\BasicService\Message;
// 内部机器人 不支持该类型
// webhook机器人 默认
$sendMessage = Message::feed(["links" => [ "title" => "时代的火车向前开", "messageURL" => "https://www.dingtalk.com/", "picURL" => "https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png"] ])->toArray();
$app = \Dingtalk::WorkBot();
$server = $bot->server;
// 直接返回 Illuminate\Http\Request
$response = $server->server();
$app = \Dingtalk::WorkBot();
$server = $bot->server;
$server->with(function($message, \Closure $next) {
// 你的自定义逻辑
return $next($message);
});
$response = $server->server();
$app = \Dingtalk::WorkBot();
$server = $bot->server;
$server
->with(function($message, \Closure $next) {
// 你的自定义逻辑1
return $next($message);
})
->with(function($message, \Closure $next) {
// 你的自定义逻辑2
return $next($message);
})
->with(function($message, \Closure $next) {
// 回复消息
return json_encode(\Martialbe\LaravelDingtalk\BasicService\Message::text(['content' => "这是文本测试"], 'api')->toArray());
});
$response = $server->server();
use Martialbe\LaravelDingtalk\Kernel\Support\Handler;
class MyHandler extends Handler
{
public function __invoke($message, \Closure $next)
{
// 你的自定义逻辑
return $next($message);
}
}
$app = \Dingtalk::WorkBot();
$server = $bot->server;
$server->with(MyHandler::class);
//OR
$server->with(new MyHandler());
bash
php artisan vendor:publish --provider="Martialbe\LaravelDingtalk\DingtalkServiceProvider"