初始化版本

This commit is contained in:
LL
2025-11-18 14:18:28 +08:00
commit 3c348195b7
23 changed files with 2837 additions and 0 deletions

56
api/head.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
// 头像代理:转发 https://api.iyuns.com/api/head 并返回 { url }
header('Content-Type: application/json; charset=utf-8');
$endpoint = 'https://api.iyuns.com/api/head';
function fetch_json($url) {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 8,
CURLOPT_TIMEOUT => 12,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERAGENT => 'DiscussionProxy/1.0',
]);
$body = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) { return null; }
$json = json_decode($body, true);
return is_array($json) ? $json : null;
}
$resp = fetch_json($endpoint);
$url = '';
if ($resp && ($resp['code'] ?? 0) == 200) {
$url = preg_replace('/[`\s]/', '', (string)($resp['data'] ?? ''));
}
if (!$url) {
// 远程失败时,回退到本地随机头像(遍历 avatars 下所有日期目录)
$root = __DIR__ . '/../avatars';
$candidates = [];
if (is_dir($root)) {
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root));
foreach ($rii as $file) {
if ($file->isFile()) {
$ext = strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
if (in_array($ext, ['jpg','jpeg','png','gif','webp'])) {
$rel = str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $file->getPathname()));
$candidates[] = $rel;
}
}
}
if (!empty($candidates)) {
shuffle($candidates);
$url = $candidates[0];
}
}
// 如果本地也没有,则后备一个 Unsplash 头像
if (!$url) {
$url = 'https://images.unsplash.com/photo-1547425260-76bcadfb4f9b?w=200&h=200&fit=crop';
}
}
echo json_encode(['url' => $url], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

70
api/picture.php Normal file
View File

@@ -0,0 +1,70 @@
<?php
// 图片代理随机或指定来源heisi/wapmeinvpic/baisi/meinvpic返回 { url, source }
header('Content-Type: application/json; charset=utf-8');
$type = strtolower($_GET['type'] ?? '');
$map = [
'heisi' => 'https://api.iyuns.com/api/heisi',
'wapmeinvpic' => 'https://api.iyuns.com/api/wapmeinvpic',
'baisi' => 'https://api.iyuns.com/api/baisi',
'meinvpic' => 'https://api.iyuns.com/api/meinvpic',
'random4kPic' => 'https://api.iyuns.com/api/random4kPic',
'jk' => 'https://api.iyuns.com/api/jk',
];
if (!$type || !isset($map[$type])) {
$keys = array_keys($map);
$type = $keys[array_rand($keys)];
}
$endpoint = $map[$type];
function fetch_json($url) {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 8,
CURLOPT_TIMEOUT => 12,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERAGENT => 'PictureProxy/1.0',
]);
$body = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) { return null; }
$json = json_decode($body, true);
return is_array($json) ? $json : null;
}
$resp = fetch_json($endpoint);
$url = '';
if ($resp && ($resp['code'] ?? 0) == 200) {
$url = preg_replace('/[`\s]/', '', (string)($resp['data'] ?? ''));
}
if (!$url) {
// 远程失败时,回退到本地随机图片(遍历 pictures/images 下的所有图片)
$root = __DIR__ . '/../pictures/images';
$candidates = [];
if (is_dir($root)) {
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root));
foreach ($rii as $file) {
if ($file->isFile()) {
$ext = strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
if (in_array($ext, ['jpg','jpeg','png','gif','webp'])) {
$rel = str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $file->getPathname()));
$candidates[] = $rel;
}
}
}
if (!empty($candidates)) {
shuffle($candidates);
$url = $candidates[0];
$type = 'local';
}
}
// 如果本地也没有,则后备一张 Unsplash 图片
if (!$url) {
$url = 'https://images.unsplash.com/photo-1523206489230-c012c4783a90?w=1200&h=800&fit=crop';
}
}
echo json_encode(['url' => $url, 'source' => $type], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

71
api/review_action.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
// 审核接口approve 或 reject 待审核视频
// 需要管理员密码my123123或已登录的会话
header('Content-Type: application/json; charset=utf-8');
session_start();
$ADMIN_PASSWORD = 'my123123';
$pendingDir = __DIR__ . '/../videos_pending';
$videosDirRoot = __DIR__ . '/../videos';
function jsonOut($ok, $msg, $extra = []) {
echo json_encode(array_merge(['ok' => $ok, 'msg' => $msg], $extra), JSON_UNESCAPED_UNICODE);
exit;
}
$action = isset($_POST['action']) ? $_POST['action'] : '';
$file = isset($_POST['file']) ? $_POST['file'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
// 会话已登录或提供了正确密码之一即可
if (empty($_SESSION['admin_ok']) && $password !== $ADMIN_PASSWORD) {
jsonOut(false, '管理员密码错误或未登录');
}
if (!$action || !$file) {
jsonOut(false, '缺少必要参数');
}
// 基础安全处理,禁止路径穿越
$basename = basename($file);
$pendingPath = $pendingDir . '/' . $basename;
if (!is_file($pendingPath)) {
jsonOut(false, '待审核文件不存在');
}
if ($action === 'reject') {
$ok = @unlink($pendingPath);
@unlink($pendingPath . '.json');
jsonOut(!!$ok, $ok ? '已拒绝并删除' : '删除失败');
}
if ($action === 'approve') {
// 生成日期目录
$dateDir = date('Y-m-d');
$dstDir = $videosDirRoot . '/' . $dateDir;
if (!is_dir($dstDir)) {
@mkdir($dstDir, 0777, true);
}
// 根据扩展名生成唯一文件名
$ext = strtolower(pathinfo($basename, PATHINFO_EXTENSION));
if (!in_array($ext, ['mp4','webm','mov'])) {
// 不支持的扩展也允许,但统一改成 mp4
$ext = 'mp4';
}
$newName = 'video_' . date('Ymd_His') . '_' . mt_rand(1000,9999) . '.' . $ext;
$dstPath = $dstDir . '/' . $newName;
$ok = @rename($pendingPath, $dstPath);
@rename($pendingPath . '.json', $dstPath . '.json');
if (!$ok) {
jsonOut(false, '转存失败');
}
// 返回相对路径,便于前端显示
$rel = 'videos/' . $dateDir . '/' . $newName;
jsonOut(true, '审核通过,已入库', ['path' => $rel]);
}
jsonOut(false, '未知操作');
?>

View File

@@ -0,0 +1,56 @@
<?php
// 图片审核 API通过/拒绝 pictures_pending 中的图片
session_start();
header('Content-Type: application/json; charset=utf-8');
$ADMIN_PASSWORD = 'my123123';
$pendingDir = __DIR__ . '/../pictures_pending';
$picturesRoot = __DIR__ . '/../pictures/images/user';
function out($ok, $msg, $extra = []) {
echo json_encode(array_merge(['ok'=>$ok,'msg'=>$msg], $extra), JSON_UNESCAPED_UNICODE);
exit;
}
$authed = !empty($_SESSION['admin_ok']);
if (!$authed) {
$pwd = trim($_POST['password'] ?? '');
if ($pwd === $ADMIN_PASSWORD) $authed = true;
}
if (!$authed) out(false, '未授权或密码错误');
$action = $_POST['action'] ?? '';
$file = basename($_POST['file'] ?? '');
if (!$action || !$file) out(false, '缺少必要参数');
$pendingPath = $pendingDir . '/' . $file;
if (!is_file($pendingPath)) out(false, '待审核文件不存在');
if ($action === 'reject') {
$ok = @unlink($pendingPath);
@unlink($pendingPath . '.json');
out(!!$ok, $ok ? '已拒绝并删除' : '删除失败');
}
if ($action === 'approve') {
$dateDir = date('Y-m-d');
$dstDir = $picturesRoot . '/' . $dateDir;
if (!is_dir($dstDir)) @mkdir($dstDir, 0777, true);
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (!in_array($ext, ['jpg','jpeg','png','gif','webp'])) $ext = 'jpg';
$newName = 'image_' . date('Ymd_His') . '_' . mt_rand(1000,9999) . '.' . $ext;
$dstPath = $dstDir . '/' . $newName;
$ok = @rename($pendingPath, $dstPath);
@rename($pendingPath . '.json', $dstPath . '.json');
if (!$ok) out(false, '转存失败');
// 相对路径(供前端或日志显示)
$rel = 'pictures/images/user/' . $dateDir . '/' . $newName;
out(true, '审核通过,已入库', ['path' => $rel]);
}
out(false, '未知操作');
?>

View File

@@ -0,0 +1,61 @@
<?php
// 文案审核 API通过/拒绝 texts_pending 中的 JSON 文案
session_start();
header('Content-Type: application/json; charset=utf-8');
$ADMIN_PASSWORD = 'my123123';
function resp($ok, $msg) {
echo json_encode(['ok' => $ok, 'msg' => $msg], JSON_UNESCAPED_UNICODE);
exit;
}
$authed = !empty($_SESSION['admin_ok']);
if (!$authed) {
$pwd = trim($_POST['password'] ?? '');
if ($pwd === $ADMIN_PASSWORD) $authed = true;
}
if (!$authed) resp(false, '未授权或密码错误');
$action = $_POST['action'] ?? '';
$file = basename($_POST['file'] ?? '');
$pendingDir = __DIR__ . '/../texts_pending';
$path = $pendingDir . '/' . $file;
if ($file === '' || !is_file($path)) resp(false, '待处理文件不存在');
if ($action === 'approve') {
$data = json_decode(@file_get_contents($path), true);
if (!is_array($data) || empty($data['content'])) {
resp(false, '文案数据无效');
}
$title = trim($data['title'] ?? '');
$content = trim($data['content'] ?? '');
$text = $title !== '' ? ('【' . $title . '】 ' . $content) : $content;
// 追加到 texts/DATE/all.json
$dateDir = __DIR__ . '/../texts/' . date('Y-m-d');
if (!is_dir($dateDir)) @mkdir($dateDir, 0777, true);
$allPath = $dateDir . '/all.json';
$arr = [];
if (is_file($allPath)) {
$arr = json_decode(@file_get_contents($allPath), true);
if (!is_array($arr)) $arr = [];
}
$arr[] = [
'text' => $text,
'source' => 'user',
'created_at' => date('c'),
];
@file_put_contents($allPath, json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
@unlink($path);
resp(true, '已通过并入库');
} else if ($action === 'reject') {
@unlink($path);
resp(true, '已拒绝并删除');
} else {
resp(false, '未知操作');
}
?>

61
api/save_avatar.php Normal file
View File

@@ -0,0 +1,61 @@
<?php
// 保存头像到本地(避免重复),不进行过期清理
header('Content-Type: application/json; charset=utf-8');
function respond($ok, $message = '', $path = '') {
echo json_encode(['success' => $ok, 'message' => $message, 'path' => $path], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
$raw = file_get_contents('php://input');
$data = json_decode($raw, true);
$url = $data['url'] ?? '';
if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) {
respond(false, 'URL无效');
}
$scheme = parse_url($url, PHP_URL_SCHEME);
if (!in_array(strtolower($scheme), ['http','https'])) {
respond(false, '仅支持http/https图片地址');
}
$avatarsRoot = __DIR__ . '/../avatars';
if (!is_dir($avatarsRoot)) { @mkdir($avatarsRoot, 0777, true); }
$today = (new DateTime('now'))->format('Y-m-d');
$targetDir = $avatarsRoot . '/' . $today;
if (!is_dir($targetDir)) { @mkdir($targetDir, 0777, true); }
// 推断扩展名
$pathExt = strtolower(pathinfo(parse_url($url, PHP_URL_PATH) ?? '', PATHINFO_EXTENSION));
$allowed = ['jpg','jpeg','png','gif','webp'];
if (!$pathExt || !in_array($pathExt, $allowed)) { $pathExt = 'jpg'; }
// 使用URL的basename作为文件名若没有则用hash
$basename = basename(parse_url($url, PHP_URL_PATH) ?: '');
if (!$basename || $basename === '/' || $basename === '\\') {
$basename = md5($url) . '.' . $pathExt;
}
if (strpos($basename, '.') === false) { $basename .= '.' . $pathExt; }
$safeName = preg_replace('/[^\w\.-]+/u', '_', $basename);
$targetPath = $targetDir . '/' . $safeName;
// 如果已存在,跳过下载
if (file_exists($targetPath)) {
respond(true, '文件已存在,跳过下载', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
}
// 下载保存
try {
$read = @fopen($url, 'rb');
if (!$read) { respond(false, '无法读取远程图片'); }
$write = @fopen($targetPath, 'wb');
if (!$write) { respond(false, '无法写入文件'); }
stream_copy_to_stream($read, $write);
fclose($read);
fclose($write);
} catch (Throwable $e) {
respond(false, '保存失败: ' . $e->getMessage());
}
respond(true, '保存成功', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));

66
api/save_picture.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
// 保存图片到本地不做清理保存目录按照远程URL的路径结构组织
header('Content-Type: application/json; charset=utf-8');
function respond($ok, $message = '', $path = '') {
echo json_encode(['success' => $ok, 'message' => $message, 'path' => $path], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
// 读取JSON输入
$raw = file_get_contents('php://input');
$data = json_decode($raw, true);
$url = $data['url'] ?? '';
if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) {
respond(false, 'URL无效');
}
// 只允许 http/https
$scheme = parse_url($url, PHP_URL_SCHEME);
if (!in_array(strtolower($scheme), ['http','https'])) {
respond(false, '仅支持http/https图片地址');
}
$root = __DIR__ . '/../pictures';
if (!is_dir($root)) { @mkdir($root, 0777, true); }
// 解析远程路径:按照域名后的路径作为保存文件夹结构
$path = parse_url($url, PHP_URL_PATH) ?: '';
if (!$path) { respond(false, '无法解析远程路径'); }
// 将路径拆分并进行安全过滤,避免非法字符与上级目录
$segments = array_values(array_filter(explode('/', $path), function($s){ return $s !== ''; }));
if (!count($segments)) { respond(false, '路径为空'); }
$filename = array_pop($segments);
$safeSegs = array_map(function($seg){
$seg = preg_replace('/[^A-Za-z0-9._-]+/u', '_', $seg);
return trim($seg, '._-') ?: 'unk';
}, $segments);
$safeName = preg_replace('/[^A-Za-z0-9._-]+/u', '_', $filename);
if (!$safeName) { $safeName = 'image_' . time() . '.jpg'; }
$targetDir = $root;
foreach ($safeSegs as $seg) { $targetDir .= DIRECTORY_SEPARATOR . $seg; if (!is_dir($targetDir)) { @mkdir($targetDir, 0777, true); } }
$targetPath = $targetDir . DIRECTORY_SEPARATOR . $safeName;
// 如果文件已存在则跳过下载
if (file_exists($targetPath)) {
respond(true, '文件已存在,跳过下载', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
}
// 下载保存
try {
$read = @fopen($url, 'rb');
if (!$read) { respond(false, '无法读取远程图片'); }
$write = @fopen($targetPath, 'wb');
if (!$write) { respond(false, '无法写入文件'); }
stream_copy_to_stream($read, $write);
fclose($read);
fclose($write);
} catch (Throwable $e) {
respond(false, '保存失败: ' . $e->getMessage());
}
respond(true, '保存成功', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));

63
api/save_text.php Normal file
View File

@@ -0,0 +1,63 @@
<?php
// 保存讨论区文案到本地(避免重复),不进行过期清理
header('Content-Type: application/json; charset=utf-8');
function respond($ok, $message = '', $path = '') {
echo json_encode(['success' => $ok, 'message' => $message, 'path' => $path], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
$raw = file_get_contents('php://input');
$data = json_decode($raw, true);
$text = trim($data['text'] ?? '');
$source = trim($data['source'] ?? '');
if ($text === '') { respond(false, '文本为空'); }
// 根目录
$textsRoot = __DIR__ . '/../texts';
if (!is_dir($textsRoot)) { @mkdir($textsRoot, 0777, true); }
// 按来源(/后缀,即 yiyan/dujitang/renjian 等)创建子目录
$safeSource = preg_replace('/[^A-Za-z0-9._-]+/u', '_', $source ?: 'unknown');
$safeSource = trim($safeSource, '._-');
if ($safeSource === '') { $safeSource = 'unknown'; }
// 日期目录
$today = (new DateTime('now'))->format('Y-m-d');
$targetDir = $textsRoot . '/' . $safeSource . '/' . $today;
if (!is_dir($targetDir)) { @mkdir($targetDir, 0777, true); }
// 改为保存到同一天的单个文件 all.json
$targetPath = $targetDir . '/all.json';
// 读取已有数据
$entries = [];
if (file_exists($targetPath)) {
$rawJson = @file_get_contents($targetPath);
$decoded = json_decode($rawJson, true);
if (is_array($decoded)) { $entries = $decoded; }
}
// 重复检查:文本完全相同则认为重复
foreach ($entries as $e) {
if (isset($e['text']) && trim((string)$e['text']) === $text) {
respond(true, '文本已存在,跳过保存', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
}
}
$entries[] = [
'text' => $text,
'source' => $source,
'created_at' => (new DateTime('now'))->format(DateTime::ATOM),
];
try {
$json = json_encode($entries, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
if (@file_put_contents($targetPath, $json, LOCK_EX) === false) {
respond(false, '无法写入文件');
}
} catch (Throwable $e) {
respond(false, '保存失败: ' . $e->getMessage());
}
respond(true, '保存成功', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));

107
api/save_video.php Normal file
View File

@@ -0,0 +1,107 @@
<?php
// 保存视频到本地并清理超过2天的旧视频第三天自动清除第一天的视频
header('Content-Type: application/json; charset=utf-8');
function respond($ok, $message = '', $path = '') {
echo json_encode(['success' => $ok, 'message' => $message, 'path' => $path], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
// 递归删除目录及其内容(用于清理旧视频)
function rrmdir($dir) {
if (!is_dir($dir)) return;
$items = @scandir($dir);
if ($items === false) return;
foreach ($items as $item) {
if ($item === '.' || $item === '..') continue;
$full = $dir . DIRECTORY_SEPARATOR . $item;
if (is_dir($full)) {
rrmdir($full);
} else {
@unlink($full);
}
}
@rmdir($dir);
}
// 读取JSON输入
$raw = file_get_contents('php://input');
$data = json_decode($raw, true);
$url = $data['url'] ?? '';
$title = $data['title'] ?? '';
if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) {
respond(false, 'URL无效');
}
// 只允许 http/https
$scheme = parse_url($url, PHP_URL_SCHEME);
if (!in_array(strtolower($scheme), ['http','https'])) {
respond(false, '仅支持http/https视频地址');
}
$videosRoot = __DIR__ . '/../videos';
if (!is_dir($videosRoot)) {
@mkdir($videosRoot, 0777, true);
}
$today = (new DateTime('now'))->format('Y-m-d');
$targetDir = $videosRoot . '/' . $today;
if (!is_dir($targetDir)) {
@mkdir($targetDir, 0777, true);
}
// 生成文件名
$basename = basename(parse_url($url, PHP_URL_PATH) ?: 'video_' . time() . '.mp4');
if (strpos($basename, '.') === false) { $basename .= '.mp4'; }
$safeName = preg_replace('/[^\w\.-]+/u', '_', $basename);
$targetPath = $targetDir . '/' . $safeName;
// 如果文件已存在则跳过下载
$skipDownload = file_exists($targetPath);
$msg = '保存成功';
if ($skipDownload) {
$msg = '文件已存在,跳过下载';
} else {
// 下载保存
try {
$read = @fopen($url, 'rb');
if (!$read) { respond(false, '无法读取远程视频'); }
$write = @fopen($targetPath, 'wb');
if (!$write) { respond(false, '无法写入文件'); }
stream_copy_to_stream($read, $write);
fclose($read);
fclose($write);
} catch (Throwable $e) {
respond(false, '保存失败: ' . $e->getMessage());
}
}
// 恢复清理逻辑:仅保留最近两天的视频目录,删除更早的目录
try {
$dirs = @scandir($videosRoot);
if (is_array($dirs)) {
// 仅筛选形如 YYYY-MM-DD 的目录
$dateDirs = [];
foreach ($dirs as $d) {
if ($d === '.' || $d === '..') continue;
$path = $videosRoot . DIRECTORY_SEPARATOR . $d;
if (is_dir($path) && preg_match('/^\d{4}-\d{2}-\d{2}$/', $d)) {
$dateDirs[] = $d;
}
}
// 按日期升序排序
sort($dateDirs);
// 保留最近两天(末尾两项),其它全部删除
if (count($dateDirs) > 30) {
$toDelete = array_slice($dateDirs, 0, count($dateDirs) - 2);
foreach ($toDelete as $del) {
rrmdir($videosRoot . DIRECTORY_SEPARATOR . $del);
}
}
}
} catch (Throwable $e) {
// 清理失败不影响主流程
}
respond(true, $msg, str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));

83
api/text.php Normal file
View File

@@ -0,0 +1,83 @@
<?php
// 文案代理随机或指定来源yiyan/dujitang/renjian返回 { text }
header('Content-Type: application/json; charset=utf-8');
$type = strtolower($_GET['type'] ?? '');
$map = [
'dujitang'=> 'https://api.iyuns.com/api/dujitang',
'renjian' => 'https://api.iyuns.com/api/renjian',
'ktff'=> 'https://v.api.aa1.cn/api/api-wenan-ktff/index.php?type=5', // 新增文艺文案
'yiyan'=> 'https://v.api.aa1.cn/api/yiyan/index.php?type=json', // 新增纯文本一言
'wenan_anwei'=> 'https://v.api.aa1.cn/api/api-wenan-anwei/index.php?type=json', // 新增文艺文案
'wenan_gaoxiao'=> 'https://v.api.aa1.cn/api/api-wenan-gaoxiao/index.php?aa1=json', // 新增文艺文案
'wenan_shenhuifu'=> 'https://v.api.aa1.cn/api/api-wenan-shenhuifu/index.php?aa1=json', // 新增文艺文案
];
if (!$type || !isset($map[$type])) {
$keys = array_keys($map);
$type = $keys[array_rand($keys)];
}
$endpoint = $map[$type];
function fetch_json($url) {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 8,
CURLOPT_TIMEOUT => 12,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERAGENT => 'DiscussionProxy/1.0',
]);
$body = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) { return null; }
$json = json_decode($body, true);
return is_array($json) ? $json : null;
}
$resp = fetch_json($endpoint);
$text = '';
if ($resp && ($resp['code'] ?? 0) == 200) {
$fields = ['yiyan','data','text','anwei','gaoxiao','shenhuifu'];
foreach ($fields as $k) {
$t = trim((string)($resp[$k] ?? ''));
if ($t !== '') { $text = $t; break; }
if (is_array($resp['data'] ?? null)) {
$t = trim((string)($resp['data'][$k] ?? ''));
if ($t !== '') { $text = $t; break; }
}
}
$text = preg_replace('/[`]/', '', $text);
}
if (!$text) {
// 远程失败时,回退到本地随机文案
$root = __DIR__ . '/../texts';
$pool = [];
if (is_dir($root)) {
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root));
foreach ($rii as $file) {
if ($file->isFile() && strtolower($file->getFilename()) === 'all.json') {
$json = @file_get_contents($file->getPathname());
if ($json) {
$arr = json_decode($json, true);
if (is_array($arr)) {
foreach ($arr as $it) {
$t = trim((string)($it['text'] ?? ''));
if ($t !== '') { $pool[] = $t; }
}
}
}
}
}
}
if (!empty($pool)) {
$text = $pool[array_rand($pool)];
$type = 'local';
} else {
// 如果本地也没有,则使用一个默认文案
$text = '今天也要元气满满!';
}
}
echo json_encode(['text' => $text, 'source' => $type], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

92
api/upload_picture.php Normal file
View File

@@ -0,0 +1,92 @@
<?php
// 接收用户投稿的图片,保存到待审核目录 pictures_pending
// 不直接进入 pictures/images/,待管理员在 review_pictures.php 审核后再转存并自动重命名
header('Content-Type: text/html; charset=utf-8');
$pendingDir = __DIR__ . '/../pictures_pending';
if (!is_dir($pendingDir)) {
@mkdir($pendingDir, 0777, true);
}
function sanitizeFileName($name) {
$name = preg_replace('/[^A-Za-z0-9_\-\.\(\)\[\]\s]/u', '_', $name);
if (strlen($name) > 120) {
$ext = pathinfo($name, PATHINFO_EXTENSION);
$base = pathinfo($name, PATHINFO_FILENAME);
$base = substr($base, 0, 100);
$name = $base . ($ext ? ('.' . $ext) : '');
}
return $name;
}
function html($s) { return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
$allowed = ['jpg','jpeg','png','gif','webp'];
$maxSize = 10 * 1024 * 1024; // 10MB
$title = isset($_POST['title']) ? trim($_POST['title']) : '';
if (!isset($_FILES['picture'])) {
echo '<p>未接收到文件。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
exit;
}
// 上传错误处理
if (!empty($_FILES['picture']['error'])) {
$err = (int)$_FILES['picture']['error'];
if ($err === UPLOAD_ERR_INI_SIZE || $err === UPLOAD_ERR_FORM_SIZE) {
echo '<p>上传失败:文件大小超过服务器限制。请确保图片不超过 10MB。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
exit;
}
echo '<p>上传失败,错误码:' . $err . '。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
exit;
}
if (!is_uploaded_file($_FILES['picture']['tmp_name'])) {
echo '<p>文件上传失败。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
exit;
}
$file = $_FILES['picture'];
$origName = $file['name'] ?? 'uploaded_image';
$safeName = sanitizeFileName($origName);
$ext = strtolower(pathinfo($safeName, PATHINFO_EXTENSION));
if (!in_array($ext, $allowed)) {
echo '<p>仅支持文件类型jpg / jpeg / png / gif / webp。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
exit;
}
// 大小限制 10MB
$size = (int)($_FILES['picture']['size'] ?? 0);
if ($size > $maxSize) {
echo '<p>图片大小超过 10MB 限制,投稿失败。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
exit;
}
$unique = date('Ymd_His') . '_' . mt_rand(1000,9999) . '.' . $ext;
$target = $pendingDir . '/' . $unique;
if (!move_uploaded_file($file['tmp_name'], $target)) {
echo '<p>保存文件失败,请稍后重试。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
exit;
}
$meta = [
'original_name' => $origName,
'saved_name' => basename($target),
'title' => $title,
'uploaded_at' => date('c'),
'size' => $file['size'] ?? 0,
'type' => $file['type'] ?? '',
];
@file_put_contents($pendingDir . '/' . basename($target) . '.json', json_encode($meta, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
echo '<div style="padding:16px;border:1px solid #e33;border-radius:8px;max-width:640px;margin:24px auto;">';
echo '<p>投稿成功!图片已进入待审核队列。</p>';
if (!empty($title)) {
echo '<p>标题:' . html($title) . '</p>';
}
echo '<p>管理员可前往 <a href="../review_pictures.php">图片审核页面</a> 进行审批。</p>';
echo '<p><a href="../upload_picture.php">继续投稿</a> 或 <a href="../index.php">返回首页</a></p>';
echo '</div>';
?>

36
api/upload_text.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
// 接收用户提交的文案,保存到 texts_pending 目录JSON文件
header('Content-Type: text/html; charset=utf-8');
$pendingDir = __DIR__ . '/../texts_pending';
if (!is_dir($pendingDir)) {
@mkdir($pendingDir, 0777, true);
}
function html($s){ return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
$title = isset($_POST['title']) ? trim($_POST['title']) : '';
$content = isset($_POST['content']) ? trim($_POST['content']) : '';
if ($content === '') {
echo '<div style="padding:16px;border:1px solid #e33;border-radius:8px;max-width:640px;margin:24px auto;">';
echo '<p>文案内容不能为空。</p><p><a href="../upload_text.php">返回文案投稿页</a></p>';
echo '</div>';
exit;
}
$name = 'text_' . date('Ymd_His') . '_' . mt_rand(1000,9999) . '.json';
$data = [
'title' => $title,
'content' => $content,
'uploaded_at' => date('c'),
];
@file_put_contents($pendingDir . '/' . $name, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
echo '<div style="padding:16px;border:1px solid #e33;border-radius:8px;max-width:640px;margin:24px auto;">';
echo '<p>提交成功!文案已保存到待处理目录。</p>';
if ($title !== '') echo '<p>标题:' . html($title) . '</p>';
echo '<p>内容:</p><pre style="white-space:pre-wrap;">' . html($content) . '</pre>';
echo '<p><a href="../upload_text.php">继续提交</a> 或 <a href="../index.php">返回首页</a></p>';
echo '</div>';
?>

95
api/upload_video.php Normal file
View File

@@ -0,0 +1,95 @@
<?php
// 接收用户投稿的视频,保存到待审核目录 videos_pending
// 不直接进入 videos/,待管理员在 review.php 审核后再转存并自动重命名
header('Content-Type: text/html; charset=utf-8');
$pendingDir = __DIR__ . '/../videos_pending';
if (!is_dir($pendingDir)) {
@mkdir($pendingDir, 0777, true);
}
function sanitizeFileName($name) {
$name = preg_replace('/[^A-Za-z0-9_\-\.\(\)\[\]\s]/u', '_', $name);
// 避免过长
if (strlen($name) > 120) {
$ext = pathinfo($name, PATHINFO_EXTENSION);
$base = pathinfo($name, PATHINFO_FILENAME);
$base = substr($base, 0, 100);
$name = $base . ($ext ? ('.' . $ext) : '');
}
return $name;
}
function html($s) { return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
$allowed = ['mp4','webm','mov'];
$maxSize = 50 * 1024 * 1024; // 50MB
$title = isset($_POST['title']) ? trim($_POST['title']) : '';
if (!isset($_FILES['video'])) {
echo '<p>未接收到文件。</p><p><a href="../upload.php">返回投稿页</a></p>';
exit;
}
// 上传错误处理
if (!empty($_FILES['video']['error'])) {
$err = (int)$_FILES['video']['error'];
if ($err === UPLOAD_ERR_INI_SIZE || $err === UPLOAD_ERR_FORM_SIZE) {
echo '<p>上传失败:文件大小超过服务器限制。请确保视频不超过 50MB。</p><p><a href="../upload.php">返回投稿页</a></p>';
exit;
}
echo '<p>上传失败,错误码:' . $err . '。</p><p><a href="../upload.php">返回投稿页</a></p>';
exit;
}
if (!is_uploaded_file($_FILES['video']['tmp_name'])) {
echo '<p>文件上传失败。</p><p><a href="../upload.php">返回投稿页</a></p>';
exit;
}
$file = $_FILES['video'];
$origName = $file['name'] ?? 'uploaded_video';
$safeName = sanitizeFileName($origName);
$ext = strtolower(pathinfo($safeName, PATHINFO_EXTENSION));
if (!in_array($ext, $allowed)) {
echo '<p>仅支持文件类型mp4 / webm / mov。</p><p><a href="../upload.php">返回投稿页</a></p>';
exit;
}
// 大小限制 50MB
$size = (int)($_FILES['video']['size'] ?? 0);
if ($size > $maxSize) {
echo '<p>视频大小超过 50MB 限制,投稿失败。</p><p><a href="../upload.php">返回投稿页</a></p>';
exit;
}
// 生成不重复的文件名(保留原名作为前缀,防止覆盖)
$unique = date('Ymd_His') . '_' . mt_rand(1000,9999) . '.' . $ext;
$target = $pendingDir . '/' . $unique;
if (!move_uploaded_file($file['tmp_name'], $target)) {
echo '<p>保存文件失败,请稍后重试。</p><p><a href="../upload.php">返回投稿页</a></p>';
exit;
}
// 可选:记录一个简单的元信息文件
$meta = [
'original_name' => $origName,
'saved_name' => basename($target),
'title' => $title,
'uploaded_at' => date('c'),
'size' => $file['size'] ?? 0,
'type' => $file['type'] ?? '',
];
@file_put_contents($pendingDir . '/' . basename($target) . '.json', json_encode($meta, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
echo '<div style="padding:16px;border:1px solid #e33;border-radius:8px;max-width:640px;margin:24px auto;">';
echo '<p>投稿成功!文件已进入待审核队列。</p>';
if (!empty($title)) {
echo '<p>标题:' . html($title) . '</p>';
}
echo '<p>管理员可前往 <a href="../review.php">审核页面</a> 进行审批。</p>';
echo '<p><a href="../upload.php">继续投稿</a> 或 <a href="../index.php">返回首页</a></p>';
echo '</div>';
?>

133
api/videos.php Normal file
View File

@@ -0,0 +1,133 @@
<?php
// 代理获取视频地址的接口:从多个来源“随机/顺序”获取 1~N 条视频地址,并返回统一格式
header('Content-Type: application/json; charset=utf-8');
// 指定来源功能已取消:统一按优先级尝试全部来源;如需随机请使用 ?random=1
// 支持的远程来源(按优先级尝试,默认启用全部并按优先级依次尝试)
$endpoints = [
'https://api.kuleu.com/api/MP4_xiaojiejie?type=json', // 新增来源纯视频URL或JSON
'https://v2.xxapi.cn/api/meinv', // 新来源JSON: {code,data}
'https://api.iyuns.com/api/meinv', // 旧来源JSON: {code,data}
'https://api.kuleu.com/api/xjj?type=json', // 新增来源JSON: {code,data}
'https://api.dwo.cc/api/ksvideo?type=json', // 新增来源JSON: {code,data}
'https://v2.api-m.com/api/meinv?type=json', // 新增来源JSON: {code,data}
'https://api.mhimg.cn/api/Sj_girls_video?type=json', // 新增来源JSON: {code,data}
];
// 随机获取:默认开启;如需关闭可用 ?random=0
$randomParam = $_GET['random'] ?? null;
$random = !isset($randomParam) ? true : (intval($randomParam) === 1);
$count = intval($_GET['count'] ?? 1);
if ($count < 1) $count = 1; if ($count > 5) $count = 5; // 限制最多5条
// 是否包含本地视频的开关
$includeLocal = intval($_GET['include_local'] ?? 0) === 1;
// 本地视频条数上限(当开启包含本地时生效,默认与远程条数相同)
$localCount = intval($_GET['local_count'] ?? $count);
if ($localCount < 0) $localCount = 0; if ($localCount > 10) $localCount = 10; // 限制一次最多10条本地视频
function fetch_remote_url($endpoint) {
// 使用 curl 更稳妥地请求第三方接口
$ch = curl_init($endpoint);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 8,
CURLOPT_TIMEOUT => 12,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERAGENT => 'VideoFetcher/1.0',
]);
$body = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) { return null; }
$json = json_decode($body, true);
$candidate = '';
if (is_array($json)) {
// 某些接口包含 code 字段,若存在则需为 200
if (array_key_exists('code', $json) && intval($json['code']) !== 200) {
return null;
}
// 兼容不同字段名mp4_video、data、url、mp4、video
foreach (['mp4_video','data','url','mp4','video','pic'] as $key) {
if (!empty($json[$key]) && is_string($json[$key])) { $candidate = $json[$key]; break; }
}
} else {
// 非JSON可能直接返回URL
$candidate = trim((string)$body);
}
// 清理反引号和空白
$candidate = preg_replace('/[`\s]/', '', (string)$candidate);
// 简单校验:必须是 http/https且 URL 中包含常见视频扩展(允许出现在路径或查询字符串中)
if (!$candidate || !preg_match('/^https?:\/\//i', $candidate)) { return null; }
if (!preg_match('/\.(mp4|webm|mov)(?![A-Za-z])/i', $candidate)) { return null; }
return $candidate;
}
// 远程接口视频列表
$remote = [];
for ($i = 0; $i < $count; $i++) {
$u = null;
// 依次尝试多个来源,取第一个成功的(随机模式下,每次尝试顺序打乱)
$epOrder = $endpoints;
if ($random && count($epOrder) > 1) { shuffle($epOrder); }
foreach ($epOrder as $ep) {
$u = fetch_remote_url($ep);
if ($u) { break; }
}
if ($u) {
$remote[] = [
'url' => $u,
'title' => '接口视频 ' . ($i + 1),
];
}
}
// 随机模式下,对远程列表打乱顺序
if ($random && count($remote) > 1) { shuffle($remote); }
// 同时把本地已保存的视频加入列表(可选)
$videosRoot = __DIR__ . '/../videos';
$local = [];
// 构建本地视频列表,用于开关合并或远程失败时的回退
if (is_dir($videosRoot)) {
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($videosRoot));
foreach ($rii as $file) {
if ($file->isFile()) {
$ext = strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
if (in_array($ext, ['mp4','webm','mov'])) {
// 构造相对URL供前端播放
$rel = str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $file->getPathname()));
$local[] = [
'url' => $rel,
'title' => '本地:' . $file->getFilename()
];
}
}
}
// 本地视频顺序随机并裁剪到指定数量
if (count($local) > 1) { shuffle($local); }
if ($localCount > 0 && count($local) > $localCount) {
$local = array_slice($local, 0, $localCount);
}
}
// 合并/回退策略:
// 1) 远程成功:
// - 如果开启本地,则远程+本地合并并整体随机
// - 如果未开启本地,则仅远程
// 2) 远程失败:
// - 若本地有内容,则仅返回本地随机列表(忽略开关)
$list = [];
if (!empty($remote)) {
$list = $includeLocal ? array_merge($remote, $local) : $remote;
if (count($list) > 1 && ($includeLocal || $random)) { shuffle($list); }
} else if (!empty($local)) {
$list = $local; // 远程不可用时,回退到全部本地随机
}
// 如果仍为空,提供一个后备示例
if (empty($list)) {
$list[] = [
'url' => 'https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4',
'title' => '示例视频'
];
}
echo json_encode(['list' => $list], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);