mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-12 23:48:53 +00:00
1. 修复原版本中节点/用户每日流量日志记录错误; 原版:在30号看到的29号的总流量,其实是28号当天产生的流量;依次类推全部流量都错位1天; 现:日流量表精确到当天,天流量表精确到当前; 2. 修复原流量折线图的日期-流量配对错误; 原版:并不是按照记录日期,而是按照有的记录; 现:按照记录日期排序; ----- 以上皆为SSRPanel中遗留的问题代码----- 3. 简化,规范化日期转换 4. 清理多余代码;
75 lines
2.0 KiB
PHP
75 lines
2.0 KiB
PHP
<?php
|
||
|
||
|
||
namespace App\Components;
|
||
|
||
use GuzzleHttp\Client;
|
||
use Log;
|
||
|
||
class PushNotification {
|
||
public static function send($title, $content) {
|
||
switch(Helpers::systemConfig()['is_notification']){
|
||
case 'serverChan':
|
||
return self::ServerChan($title, $content);
|
||
case 'bark':
|
||
return self::Bark($title, $content);
|
||
default:
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* ServerChan推送消息
|
||
*
|
||
* @param string $title 消息标题
|
||
* @param string $content 消息内容
|
||
*
|
||
* @return mixed
|
||
*/
|
||
private static function ServerChan($title, $content) {
|
||
// TODO:一天仅可发送不超过500条
|
||
$request = (new Client(['timeout' => 15]))->get('https://sc.ftqq.com/'.Helpers::systemConfig()['server_chan_key'].'.send?text='.$title.'&desp='.urlencode($content));
|
||
$message = json_decode($request->getBody(), true);
|
||
// 发送成功
|
||
if($request->getStatusCode() == 200){
|
||
if(!$message['errno']){
|
||
Helpers::addNotificationLog($title, $content, 2);
|
||
return $message;
|
||
}
|
||
// 发送失败
|
||
Helpers::addNotificationLog($title, $content, 2, 'admin', -1, $message? $message['errmsg'] : '未知');
|
||
return false;
|
||
}
|
||
// 发送错误
|
||
Log::debug('ServerChan消息推送异常:'.var_export($request, true));
|
||
return false;
|
||
}
|
||
|
||
/**
|
||
* Bark推送消息
|
||
*
|
||
* @param string $title 消息标题
|
||
* @param string $content 消息内容
|
||
*
|
||
* @return mixed
|
||
*/
|
||
private static function Bark($title, $content) {
|
||
$request = (new Client(['timeout' => 15]))->get('https://api.day.app/'.Helpers::systemConfig()['bark_key'].'/'.$title.'/'.$content);
|
||
$message = json_decode($request->getBody(), true);
|
||
|
||
if($request->getStatusCode() == 200){
|
||
// 发送成功
|
||
if($message['code'] == 200){
|
||
Helpers::addNotificationLog($title, $content, 3);
|
||
return $message;
|
||
}
|
||
// 发送失败
|
||
Helpers::addNotificationLog($title, $content, 3, 'admin', -1, $message);
|
||
return false;
|
||
}
|
||
// 发送错误
|
||
Log::debug('Bark消息推送异常:'.var_export($request, true));
|
||
return false;
|
||
}
|
||
}
|