Files
ProxyPanel/app/Channels/BarkChannel.php
兔姬桑 cce0799350 Add 3 more notification methods
添加通知方式:
- 爱语飞飞;
- PushDear;
- 钉钉;

去除 PushBear;
2022-08-09 19:32:43 +08:00

50 lines
1.5 KiB
PHP

<?php
namespace App\Channels;
use Helpers;
use Http;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Arr;
use Log;
use Str;
class BarkChannel
{
public function send($notifiable, Notification $notification)
{
if (method_exists($notification, 'toBark')) {
$message = $notification->toBark($notifiable);
} else {
$message = $notification->toCustom($notifiable);
}
if (isset($message['url_type'])) { // 生成对公消息查询URL
$msgId = Str::uuid();
$message['url'] = route('message.show', ['type' => $message['url_type'], $msgId]);
unset($message['url_type']);
}
$response = Http::timeout(15)
->get('https://api.day.app/'.sysConfig('bark_key')."/{$message['title']}/{$message['content']}?".http_build_query(Arr::except($message, ['title', 'content'])));
if ($response->ok()) {
$ret = $response->json();
// 发送成功
if ($ret['code'] === 200) {
Helpers::addNotificationLog($message['title'], $message['content'], 3, 1, null, $msgId ?? null);
return $ret;
}
// 发送失败
Helpers::addNotificationLog($message['title'], $message['content'], 3, -1);
return false;
}
// 发送错误
Log::critical('[Bark] 消息推送异常:'.var_export($response, true));
return false;
}
}