马上注册,免费下载更多dz插件网资源。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
在 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);
}
?>
哪里有错误啊?
就是不自动回复
©DZ插件网所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。 本站内容为站长个人技术研究记录或网络,不提供用户交互功能,所有内容版权归原作者所有。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,得到更好的正版服务。 您在本站任何的赞助购买、下载、查阅、回复等行为等均表示接受并同意签订《DZ插件网免责声明协议》。 如有侵权请邮件与我们联系处理: discuzaddons@vip.qq.com 并出示相关证明以便删除。敬请谅解!
|
|