mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-11 23:19:05 +00:00
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
||
|
||
namespace App\Channels;
|
||
|
||
use Helpers;
|
||
use Http;
|
||
use Illuminate\Notifications\Notification;
|
||
use Log;
|
||
|
||
class BarkChannel
|
||
{
|
||
public function send($notifiable, Notification $notification)
|
||
{
|
||
if (method_exists($notification, 'toBark')) {
|
||
$message = $notification->toBark($notifiable);
|
||
} else {
|
||
$message = $notification->toCustom($notifiable);
|
||
}
|
||
|
||
$response = Http::timeout(15)->get('https://api.day.app/'.sysConfig('bark_key').'/'.$message['title'].'/'.$message['content']);
|
||
|
||
if ($response->ok()) {
|
||
$ret = $response->json();
|
||
// 发送成功
|
||
if ($ret['code'] === 200) {
|
||
Helpers::addNotificationLog($message['title'], $message['content'], 3);
|
||
|
||
return $ret;
|
||
}
|
||
// 发送失败
|
||
Helpers::addNotificationLog($message['title'], $message['content'], 3, 'admin', -1, $message);
|
||
|
||
return false;
|
||
}
|
||
// 发送错误
|
||
Log::error('Bark消息推送异常:'.var_export($response, true));
|
||
|
||
return false;
|
||
}
|
||
}
|