Skip to content

Commit

Permalink
升级飞书通知版本
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsir committed Jul 16, 2021
1 parent a6ea65d commit 2eca760
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions src/FeishuHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,33 @@ protected function write(array $record): void
{
$title = $record['message'];
unset($record['message'], $record['formatted']);
$text = json_encode($record, JSON_PRETTY_PRINT + JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES);
(new Client())->post($this->webhook, [

$traces = $record['context']['exception']->getTrace();
$contents = [];
foreach ($traces as $item) {
$contents[] = [
'tag' => 'text',
'text' => json_encode($item, JSON_PRETTY_PRINT + JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES),
];
}
$data = [
'msg_type' => 'post',
'content' => [
'post' => [
'zh_cn' => [
'title' => $title,
'content' => [
$contents,
],
],
],
],
];

$res = (new Client())->post($this->webhook, [
'http_errors' => false,
'headers' => ['Content-Type: application/json'],
'body' => json_encode(['title' => $title, 'text' => $text]),
'body' => json_encode($data),
]);
}
}
2 changes: 1 addition & 1 deletion src/FeishuLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke(array $config): Logger
new NormalizerFormatter($dateFormat)
);
$token = $config['token'] ?? config('feishu-logger.token');
$feishuHandler->setWebhook('https://open.feishu.cn/open-apis/bot/hook/'.$token);
$feishuHandler->setWebhook('https://open.feishu.cn/open-apis/bot/v2/hook/'.$token);

return new Logger(config('app.name'),
[$feishuHandler]
Expand Down

0 comments on commit 2eca760

Please sign in to comment.