利用go-cqhttp搭建的qq机器人,我们可以通过api接口,达到WordPress网站有人评论时,机器人QQ消息通知你

盒子萌boxmoe.com

go-cqhttp qq机器人搭建请参考博客另外一篇搭建教程

盒子萌地图为你导航

WordPress评论QQ推送代码

这段代码只要放在function.php文件里即可完成了,下面需要修改你的机器人http地址

function boxmoe_msg_qq($comment_id)
{
    $comment = get_comment($comment_id);
    $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('http://api网址或者ip:5700/send_private_msg?user_id=接收qq号', false, $context);
}
add_action('comment_post', 'boxmoe_msg_qq', 19, 2);