项目

icon

https://github.com/Mrs4s/go-cqhttp

效果

使用

在主题文件夹中的function.php添加以下代码

代码中有部分无法正确渲染的内容请查看置顶评论

function bot_msg_qq($comment_id)
{
$comment = get_comment($comment_id);
//如果评论作者是管理员,直接返回不处理
if( user_can($comment->user_id, 'administrator') )
{
return;
}
$siteurl = get_bloginfo('url');
$text = '文章《' . get_the_title($comment->comment_post_ID) . '》有新的评论!';
$desp = $text . "\n" . "作者: $comment->comment_author \n邮箱: $comment->comment_author_email \n评论: $comment->comment_content \n点击查看:$siteurl/?p=$comment->comment_post_ID#comments";
// 封装Object,message是我们需要推送到 QQ 的消息内容
$postdata = http_build_query(
array(
'message' => $desp
)
);
// 执行POST请求
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
return $result = file_get_contents('https://bot.asbid.cn/send_private_msg?user_id=接收qq号', false, $context);
}
add_action('comment_post', 'bot_msg_qq', 19, 2);
  • 修改QQ机器人的API或者保持默认
  • 修改接收通知的QQ号码
  • QQ机器人与接收通知的QQ号码必须为好友

我的QQ机器人号码 2280858259 API: https://bot.asbid.cn 务必添加QQ2280858259为好友,不然无法接收消息

相关插件

https://www.imsun.org/archives/346.html

引用

https://www.boxmoe.com/534.html

本文作者:浪子 @ 提剑追梦

本文链接:https://blog.imsun.org/blog/利用qq机器人在有wordpress评论时qq消息通知/

本文标题:利用QQ机器人在有WordPress评论时QQ消息通知

本文版权:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!