初始提交:识流 AI 助手项目
微信自动回复机器人,基于截图+OCR识别消息,支持关键词规则和 AI(OpenAI/DeepSeek/Dify)自动回复。 技术栈:PySide6 + Flask + Vue3 + RapidOCR + SQLite 注:OCR大模型文件(.onnx / .pdiparams)不纳入版本控制,需单独下载。 🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
99
legacy/api_rules.php
Normal file
99
legacy/api_rules.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
// 简单规则配置接口:被 Web 后台用 Ajax 调用
|
||||
require_once __DIR__ . '/config.php';
|
||||
require_once __DIR__ . '/db.php';
|
||||
require_once __DIR__ . '/ai_helper.php';
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$action = $_GET['action'] ?? $_POST['action'] ?? 'list';
|
||||
$pdo = get_pdo();
|
||||
|
||||
try {
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
$stmt = $pdo->query("SELECT * FROM auto_reply_rules ORDER BY id DESC");
|
||||
$rules = $stmt->fetchAll();
|
||||
json_response(['success' => true, 'data' => $rules]);
|
||||
break;
|
||||
|
||||
case 'create':
|
||||
$keyword = trim((string)($_POST['keyword'] ?? ''));
|
||||
$matchType = $_POST['match_type'] ?? 'contain';
|
||||
$replyText = trim((string)($_POST['reply_text'] ?? ''));
|
||||
$isActive = (int)($_POST['is_active'] ?? 1);
|
||||
|
||||
if ($keyword === '' || $replyText === '') {
|
||||
json_response(['success' => false, 'message' => '关键词和回复内容不能为空']);
|
||||
}
|
||||
|
||||
if (!in_array($matchType, ['contain', 'equal'], true)) {
|
||||
$matchType = 'contain';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO auto_reply_rules(keyword, match_type, reply_text, is_active, created_at, updated_at)
|
||||
VALUES(:kw, :mt, :rt, :act, NOW(), NOW())
|
||||
");
|
||||
$stmt->execute([
|
||||
':kw' => $keyword,
|
||||
':mt' => $matchType,
|
||||
':rt' => $replyText,
|
||||
':act' => $isActive,
|
||||
]);
|
||||
json_response(['success' => true]);
|
||||
break;
|
||||
|
||||
case 'toggle':
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$isActive = (int)($_POST['is_active'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
json_response(['success' => false, 'message' => '参数错误']);
|
||||
}
|
||||
$stmt = $pdo->prepare("UPDATE auto_reply_rules SET is_active = :act, updated_at = NOW() WHERE id = :id");
|
||||
$stmt->execute([':act' => $isActive, ':id' => $id]);
|
||||
json_response(['success' => true]);
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
json_response(['success' => false, 'message' => '参数错误']);
|
||||
}
|
||||
$stmt = $pdo->prepare("DELETE FROM auto_reply_rules WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
json_response(['success' => true]);
|
||||
break;
|
||||
|
||||
case 'settings_get':
|
||||
$autoOn = get_setting('auto_reply_enabled', '1');
|
||||
json_response(['success' => true, 'auto_reply_enabled' => $autoOn === '1']);
|
||||
break;
|
||||
|
||||
case 'settings_set':
|
||||
$autoOn = ($_POST['auto_reply_enabled'] ?? '1') === '1' ? '1' : '0';
|
||||
set_setting('auto_reply_enabled', $autoOn);
|
||||
json_response(['success' => true]);
|
||||
break;
|
||||
|
||||
case 'messages_recent':
|
||||
$limit = max(1, min(100, (int)($_GET['limit'] ?? 50)));
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT * FROM messages
|
||||
ORDER BY id DESC
|
||||
LIMIT :lim
|
||||
");
|
||||
$stmt->bindValue(':lim', $limit, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$rows = $stmt->fetchAll();
|
||||
json_response(['success' => true, 'data' => $rows]);
|
||||
break;
|
||||
|
||||
default:
|
||||
json_response(['success' => false, 'message' => '未知操作']);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
json_response(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user