Files
ProxyPanel/app/Channels/ServerChanChannel.php
兔姬桑 12d4365fe4 Bark & 企业微信 等显示调整优化
Apply fixes from StyleCI
2022-01-16 22:57:48 +08:00

53 lines
1.5 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 Cache;
use Helpers;
use Http;
use Illuminate\Notifications\Notification;
use Log;
class ServerChanChannel
{
public function send($notifiable, Notification $notification)
{
$message = $notification->toCustom($notifiable);
$cacheKey = 'serverChanCount'.date('d');
if (Cache::has($cacheKey)) {
Cache::increment($cacheKey);
} else {
Cache::put($cacheKey, 1, Day); // 24小时
}
// 一天仅可发送不超过500条
if (Cache::get($cacheKey) < 500) {
$response = Http::timeout(15)
->get('https://sctapi.ftqq.com/'.sysConfig('server_chan_key').'.send?title='.$message['title'].'&desp='.urlencode($message['content']));
} else {
Log::critical('ServerChan消息推送异常今日500条限额已耗尽');
return false;
}
// 发送成功
if ($response->ok()) {
$ret = $response->json();
if (! $ret['errno']) {
Helpers::addNotificationLog($message['title'], $message['content'], 2);
return $ret;
}
// 发送失败
Helpers::addNotificationLog($message['title'], $message['content'], 2, -1, $ret ? $ret['errmsg'] : '未知');
return false;
}
// 发送错误
Log::critical('ServerChan消息推送异常'.var_export($response, true));
return false;
}
}