Files
ProxyPanel/app/Channels/TgChatChannel.php
2021-09-07 22:55:12 +08:00

37 lines
1.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Channels;
use Helpers;
use Http;
use Illuminate\Notifications\Notification;
use Log;
class TgChatChannel
{
public function send($notifiable, Notification $notification)
{
$message = $notification->toCustom($notifiable);
$response = Http::timeout(15)->get('https://tgbot-red.vercel.app/api?token='.sysConfig('tg_chat_token').'&message='.$message['title'].PHP_EOL.'=========='.PHP_EOL.$message['content']);
// 发送成功
if ($response->ok()) {
$ret = $response->json();
if ($ret['code'] === 200) {
Helpers::addNotificationLog($message['title'], $message['content'], 6);
return $ret;
}
// 发送失败
Helpers::addNotificationLog($message['title'], $message['content'], 6, 'admin', -1, $ret ? $ret['message'] : '未知');
return false;
}
// 发送错误
Log::critical('TG酱消息推送异常'.var_export($response, true));
return false;
}
}