xiao9469 发表于 2025-6-9 08:51:00

有懂程序的 帮我看看 哪里有错 计划任务 自动回复哪里错了

在 Discuz! 根目录新建文件:
`source/include/cron/cron_auto_reply.php`
内容如下:

<?php
if(!defined('IN_DISCUZ')) exit('Access Denied');

// 配置参数
$reply_user = "admin";    // 执行自动回复的账号
$time_range = 10;         // 扫描N分钟内发布的新帖
$reply_contents = array(
    "欢迎发帖!",
    "您的资源真的很宝贵哦",
    "社区需要您的积极发言",
    "我们一起为更多的需求着服务",
    "非常感谢您的无私奉献"
);

// 获取用户信息
$user = C::t('common_member')->fetch_by_username($reply_user);
if(!$user) exit('用户不存在');

// 获取需回复的新帖 (优化查询)
$timestamp = TIMESTAMP - $time_range * 60;
$new_threads = C::t('forum_thread')->fetch_all_by_dateline($timestamp, 0, 50); // 限制50条

foreach($new_threads as $thread) {
    // 跳过已回复的帖子
    if(C::t('forum_post')->count_by_tid_authorid($thread['tid'], $user['uid'])) continue;

    // 使用 Discuz! 标准回复函数
    $postinfo = array(
      'fid' => $thread['fid'],
      'tid' => $thread['tid'],
      'author' => $user['username'],
      'authorid' => $user['uid'],
      'message' => $reply_content,
    );

    // 关键修复:使用标准回复接口
    $pid = replypost($postinfo);

    if($pid) {
      // 更新主题数据
      C::t('forum_thread')->update($thread['tid'], array(
            'lastpost' => TIMESTAMP,
            'lastposter' => $user['username'],
            'replies' => $thread['replies'] + 1
      ));

      // 记录日志
      writelog("自动回复 TID:".$thread['tid']." 成功");
    }
}

// 标准回复函数
function replypost($post) {
    require_once libfile('function/post');

    $param = array(
      'fid' => $post['fid'],
      'tid' => $post['tid'],
      'author' => $post['author'],
      'authorid' => $post['authorid'],
      'message' => $post['message'],
      'usesig' => 1,
    );

    return _post_autosave($param, false); // false表示不检查权限
}

// 简单日志记录
function writelog($msg) {
    $logfile = DISCUZ_ROOT.'./data/auto_reply.log';
    $content = date('Y-m-d H:i:s')." | ".$msg.PHP_EOL;
    @file_put_contents($logfile, $content, FILE_APPEND);
}
?>

哪里有错误啊?
就是不自动回复

Crystαl 发表于 2025-6-9 08:51:08

让Ai帮你看

独家记忆 发表于 2025-6-9 08:51:56

直接写个软件多方便

婷姐 发表于 2025-6-9 08:52:44

直接写个软件多方便

Crystαl 发表于 2025-6-9 08:53:36

能力有限看看如何成功啊

独家记忆 发表于 2025-6-9 08:53:44

直接写个软件多方便

独家记忆 发表于 2025-6-9 08:54:30

问问ai看看

Crystαl 发表于 2025-6-9 08:55:05

问问AI吧

IT618发布 发表于 2025-6-9 08:55:18

问问AI吧

婷姐 发表于 2025-6-9 08:56:10

牛啊牛
页: [1]
查看完整版本: 有懂程序的 帮我看看 哪里有错 计划任务 自动回复哪里错了