'; exit; } $msg = $_POST['msg']; $msg = htmlspecialchars($msg, ENT_QUOTES, 'UTF-8'); $msg_c = mb_strlen($msg, 'UTF-8'); if ($msg_c > 512 or $msg_c <= 1) { echo "数据不规范!"; exit; } // 获取当前时间并格式化 $time = date('Y-m-d H:i:s'); $data = json_decode($active_ticket, true); // 判断条件 if ($data['ticket']['status'] === '客服回复' && end($data['ticket']['conversation'])['role'] === 'admin') { $ww = 1; // 满足条件返回 1 } else { $ww = 0; // 不满足条件返回 0 } if ($ww == 0) { echo "客服回复之前无法回复!"; exit; } $lt = $data['ticket']['last_reply_time']; // 指定的时间字符串 $specifiedTimeStr = $lt; // 将指定时间字符串转换为 DateTime 对象 $specifiedTime = new DateTime($specifiedTimeStr); // 获取当前时间 $currentTime = new DateTime(); // 计算时间差 $interval = $currentTime->diff($specifiedTime); // 判断差值是否大于 1 分钟 if ($interval->i >= 1 || $interval->d > 0 || $interval->m > 0 || $interval->y > 0) { echo "202:"; $filename = './admin.txt'; if (file_exists($filename)) { $file = fopen($filename, 'r'); if ($file) { while (($line = fgets($file)) !== false) { $qq = trim($line); // 去除行末的换行符和空格 if (!empty($qq)) { sendMail($qq . '@qq.com', '#Fuxsto Admin 工单提醒!', "

尊敬的管理员


有工单等待处理!"); } } fclose($file); } else { //echo "无法打开文件."; } } else { //echo "文件不存在."; } } else { echo "201:"; } $data['ticket']['last_reply_time'] = $time; $data['ticket']['status'] = "客户回复"; // 添加新的对话到尾部 $new_conversation_tail = [ "responder" => $user, "role" => "user", "reply_time" => $time, "reply_content" => $msg ]; array_push($data['ticket']['conversation'], $new_conversation_tail); // 编码为 JSON 字符串 $main = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); // 定义要检查的文件路径 $filename = './me/' . $user . '/' . $pass . '/ticket.json'; // 目录路径 @file_put_contents($filename, $main); echo '回复成功!'; ?>