no message

This commit is contained in:
hellcat 2026-08-13 16:30:49 +08:00
parent addd2662d8
commit 5f6ea8c194
5 changed files with 63 additions and 32 deletions

View File

@ -31,8 +31,10 @@ class SakaiController
// echo 111; // echo 111;
// exit; // exit;
$oReportUmami = new ReportUmami(); // $oReportUmami = new ReportUmami();
$oReportUmami->handle(); // $oReportUmami->handle();
(new ReportUmami())->handle();
exit; exit;

View File

@ -20,6 +20,7 @@ use App\Services\Cron\FnSitePublish as CronFnSitePublish;
use App\Services\Cron\NasaTestFnSubfile; use App\Services\Cron\NasaTestFnSubfile;
use App\Services\Cron\ShadowRocketCrawl; use App\Services\Cron\ShadowRocketCrawl;
use App\Services\Cron\ShadowRocketPublish; use App\Services\Cron\ShadowRocketPublish;
use App\Services\Cron\ReportUmami;
final class Cron final class Cron
{ {
@ -44,8 +45,13 @@ final class Cron
echo "cron开始执行 \n"; echo "cron开始执行 \n";
if ($h === 8 && $i === 3) {
(new ReportUmami())->handle();
}
if ($h % 8 === 0 && $i === 3) { if ($h % 8 === 0 && $i === 3) {
CronBook::randbox_notify(); // note提醒 CronBook::randbox_notify(); // note提醒
(new ReportUmami())->handle();
} }
if ($h % 4 === 0 && $i === 3) { if ($h % 4 === 0 && $i === 3) {

View File

@ -12,12 +12,14 @@ use App\Services\TomTool\Telegram\Slave as TeleSlave;
final class ReportUmami final class ReportUmami
{ {
private string $baseUrl; private string $baseUrl;
private string $username = 'admin'; private string $username;
private string $password = 'taonihouzi#'; private string $password;
public function __construct() public function __construct()
{ {
$this->baseUrl = (string) config('path.url_umami_base'); $this->baseUrl = (string) "https://".config('path.url_umami_base');
$this->username = (string) config('key.umami_user');
$this->password = (string) config('key.umami_pass');
} }
/** /**
@ -28,55 +30,59 @@ final class ReportUmami
try { try {
// 1. 获取 API 认证 Token // 1. 获取 API 认证 Token
$token = $this->getAuthToken(); $token = $this->getAuthToken();
if (!$token) { if (!$token) {
TeleSlave::log()->send("⚠️ [Umami 报表失败]: 无法获取 Auth Token请检查账号密码。"); TeleSlave::log()->enableDetail(false)->send("⚠️ [Umami 报表失败]: 无法获取 Auth Token请检查账号密码。");
return; return;
} }
// 2. 获取网站列表 // 2. 获取网站列表
$websites = $this->getWebsites($token); $websites = $this->getWebsites($token);
if (empty($websites)) { if (empty($websites)) {
TeleSlave::log()->send(" [Umami 报表]: 数据库中未找到任何网站。"); TeleSlave::log()->enableDetail(false)->send(" [Umami 报表]: 数据库中未找到任何网站。");
return; return;
} }
// 3. 统计过去 24 小时的数据 // 3. 统计过去 24 小时的数据
$endAt = microtime(true) * 1000; // 当前时间戳 (毫秒) $endAt = (int) (microtime(true) * 1000); // 当前时间戳 (毫秒)
$startAt = $endAt - (24 * 3600 * 1000); // 24小时前的时间戳 (毫秒) $startAt = $endAt - (24 * 3600 * 1000); // 24小时前的时间戳 (毫秒)
$msg = "<b>📊 Umami 每日站点数据日报</b>\n";
$msg .= "----------------------------\n";
foreach ($websites as $site) { foreach ($websites as $site) {
$siteId = $site['id'];
$siteName = $site['name']; $siteId = $site['id'] ?? '';
$domain = $site['domain'] ?? ''; $siteName = $site['name'] ?? '未命名站点';
$domain = $site['domain'] ?? '';
if (!$siteId) {
continue;
}
// 获取单个网站的统计指标 // 获取单个网站的统计指标
$stats = $this->getWebsiteStats($token, $siteId, (int)$startAt, (int)$endAt); $stats = $this->getWebsiteStats($token, $siteId, $startAt, $endAt);
if ($stats) { if ($stats) {
$pageviews = $stats['pageviews']['value'] ?? 0; // 对齐结构:直接获取 int 值
$visitors = $stats['visitors']['value'] ?? 0; $pageviews = $stats['pageviews'] ?? 0;
$visits = $stats['visits']['value'] ?? 0; $pageviewsPrev = $stats['comparison']['pageviews'] ?? 0;
$bounces = $stats['bounces']['value'] ?? 0; $visitors = $stats['visitors'] ?? 0;
$visits = $stats['visits'] ?? 0;
$bounces = $stats['bounces'] ?? 0;
// 计算跳出率 // 计算跳出率
$bounceRate = $visits > 0 ? round(($bounces / $visits) * 100, 1) : 0; $bounceRate = $visits > 0 ? round(($bounces / $visits) * 100, 1) : 0;
$msg .= "🌐 <b>{$siteName}</b> ({$domain})\n"; $msg = "\n\n======= 📊 访客统计:{$domain} ===================";
$msg .= "├ 👁️ 页面浏览 (PV): <b>{$pageviews}</b>\n"; $msg .= "\n- 今日:{$pageviews}";
$msg .= "├ 👤 独立访客 (UV): <b>{$visitors}</b>\n"; $msg .= "\n- 昨日:{$pageviewsPrev}";
$msg .= "├ 🔄 会话次数: <b>{$visits}</b>\n";
$msg .= "└ 📉 跳出率: <b>{$bounceRate}%</b>\n\n";
} }
} }
// 4. 发送日志至 Telegram // 4. 发送日志至 Telegram
TeleSlave::log()->send($msg); TeleSlave::log()->enableDetail(false)->send($msg);
} catch (\Throwable $e) { } catch (\Throwable $e) {
TeleSlave::log()->send("❌ [Umami 报表异常]: " . $e->getMessage()); TeleSlave::log()->enableDetail(false)->send("❌ [Umami 报表异常]: " . $e->getMessage());
} }
} }
@ -99,7 +105,13 @@ final class ReportUmami
private function getWebsites(string $token): array private function getWebsites(string $token): array
{ {
$response = $this->curlRequest('GET', '/api/websites', [], $token); $response = $this->curlRequest('GET', '/api/websites', [], $token);
return $response['data'] ?? $response ?? [];
// Umami 2.x API 网站列表格式通常包含在 data 字段中
if (isset($response['data']) && is_array($response['data'])) {
return $response['data'];
}
return is_array($response) ? $response : [];
} }
/** /**
@ -115,8 +127,8 @@ final class ReportUmami
* 通用 cURL 请求工具方法 * 通用 cURL 请求工具方法
*/ */
private function curlRequest(string $method, string $path, array $data = [], ?string $token = null): ?array private function curlRequest(string $method, string $path, array $data = [], ?string $token = null): ?array
{ organize: {
$ch = curl_init($this->baseUrl . $path); $ch = curl_init(rtrim($this->baseUrl, '/') . $path);
$headers = [ $headers = [
'Content-Type: application/json', 'Content-Type: application/json',

View File

@ -285,7 +285,12 @@ class Slave
throw new \Exception("未设置env的url_master_base"); throw new \Exception("未设置env的url_master_base");
} }
$sUrlMasterPost = "https://".$sUrlMaSterBase."/api/telegram/post"; $h = "https://";
if ($sUrlMaSterBase == "dd.loc") {
$h = "http://";
}
$sUrlMasterPost = $h.$sUrlMaSterBase."/api/telegram/post";
try { try {

6
config/key.php Executable file
View File

@ -0,0 +1,6 @@
<?php
return [
"umami_user" => 'admin',
"umami_pass" => 'taonihouzi#'
];