<?php
header('Content-Type: application/json; charset=utf-8');

$totalCount = 0;

// 读取api目录下所有子目录的counter.dat文件
$apiDir = __DIR__ . '/api';
if (is_dir($apiDir)) {
    $subdirs = scandir($apiDir);
    foreach ($subdirs as $subdir) {
        $counterFile = $apiDir . '/' . $subdir . '/counter.dat';
        if (is_file($counterFile)) {
            $count = intval(file_get_contents($counterFile));
            $totalCount += $count;
        }
    }
}

// 返回JSON格式的调用次数
echo json_encode([
    'count' => $totalCount,
    'timestamp' => date('Y-m-d H:i:s')
]);
?>
