boxmoe_header_banner_img

Hello! 欢迎来到盒子萌!

加载中

文章导读

利用go-cqhttp搭建的qq机器人接入WordPress主题评论的时QQ消息通知


avatar
专收爆米花 2021年10月13日 6.41k


利用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);


评论(9)

查看评论列表
评论头像
咕咕 2021年11月03日
:razz: :razz: :razz: :razz: 博主,我按照你网站的设计,用vue复刻了一套 @^_^@ 想看看不?,要源码不?
评论头像
专收爆米花 博主 2021年11月03日
好哇,一直想学习vue.就是听说影响收录,就没去折腾
评论头像
蔡徐坤 2021年11月30日
块给我也瞅瞅
评论头像
咕咕 2021年12月03日
tingyuzhe.cn :oops: 这个地址
评论头像
cigar 2022年04月25日
大佬!可以给我看看源码吗!
评论头像
专收爆米花 博主 2022年04月25日
源码不是在文章里么
评论头像
叶开楗 2021年11月04日
可以,很强!
评论头像
沐深 2022年06月06日
大佬,请问如何实现发到QQ群呀?萌新求指教
评论头像
专收爆米花 博主 2022年06月08日
http://api网址或者ip:5700/send_private_msg?user_id=接收qq号 改为 http://api网址或者ip:5700/send_group_msg?group_id=接收qq群号

发表评论

表情 颜文字
插入代码