博主原来用的是Server酱的,今天下决心启用Qmsg酱。起因是看到一篇文章Server酱和Qmsg酱两个好用的推送服务。外加Server酱限定免费额度为5个,太少了,更甚的是两条消息后就不工作了。

有服务器的朋友也可自行搭建(超级简单)

Go语言全平台QQ机器人搭建 Go语言全平台QQ机器人搭建 go-cqhttp使用 mirai 以及 MiraiGo 开发的 cqhttp golang 原生实现。 [gitcard type="1" url="https://github.com/Mrs4s... 时间:2021/8/29 分类:网络技术 阅读:28

下面介绍如何配置Qmsg酱实现WordPress评论推送到个人QQ。

一、效果展示

左:原配置效果,右:修改后效果

开发者承诺永久免费:

二、配置过程

1、登录账号

QQ登录即可:https://qmsg.zendee.cn/me.html#/login

2、选择「Qmsg酱」

3、添加接收消息的QQ号

注意如果要推送到QQ群,要到 https://qmsg.zendee.cn/api.html 先申请

大概率是提示:工作繁忙,近期没时间审核,请谅解!

4、获取KEY

私聊消息推送接口
https://qmsg.zendee.cn/send/您的KEY

群消息推送接口
https://qmsg.zendee.cn/group/您的KEY

5、添加函数

functions.php文件内添加函数

参考:https://www.jxtxzzw.com/archives/5278

注意原帖有误:接口后加了.html,实际不要加

/**
 * 评论推送到 QQ,该函数会挂载到 WordPress 钩子,无需关心参数和返回值
 * @param $comment_id
 * @return false|string
 */
function push_qq($comment_id)
{
    // 通过 comment_id 获取 comment 全部信息
    $comment = get_comment($comment_id);

    //  根据自己需求,产生相关描述,可以包括文章内容、评论人、IP、评论内容等
    $text = '您的文章 《' . get_the_title($comment->comment_post_ID) . '》 有新评论';

    $desp = $text . "\n\n" . "作者: $comment->comment_author (IP地址: $comment->comment_author_IP ) \n\n 电子邮箱: $comment->comment_author_email \n\n 评论: $comment->comment_content \n\n 点击查看:https://www.jxtxzzw.com/?p=$comment->comment_post_ID#comment-$comment_id \n\n";

    // 封装一个 Object 对象,其 msg 字段是我们需要推送到 QQ 的消息内容
    $postdata = http_build_query(
        array(
            'msg' => $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://qmsg.zendee.cn:443/send/<KEY>', false, $context);

}
// 挂载 WordPress 评论提交的接口
add_action('comment_post', 'push_qq', 19, 2);

优化修改后的

/**
 * 评论推送到 QQ,该函数会挂载到 WordPress 钩子,无需关心参数和返回值
 * @param $comment_id
 * @return false|string
 */
function push_qq($comment_id)
{
    // 通过 comment_id 获取 comment 全部信息
    $comment = get_comment($comment_id);
    $siteurl = get_bloginfo('url');
    //  根据自己需求,产生相关描述,可以包括文章内容、评论人、IP、评论内容等
    $text = '文章 《' . get_the_title($comment->comment_post_ID) . '》 有新评论啦!';

    $desp = $text . "\n\n" . "作者: $comment->comment_author \n\n邮箱: $comment->comment_author_email \n\n 评论: $comment->comment_content \n\n 点击查看:$siteurl/?p=$comment->comment_post_ID#comments";

    // 封装一个 Object 对象,其 msg 字段是我们需要推送到 QQ 的消息内容
    $postdata = http_build_query(
        array(
            'msg' => $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://qmsg.zendee.cn:443/send/YOURKEY', false, $context);

}
// 挂载 WordPress 评论提交的接口
add_action('comment_post', 'push_qq', 19, 2);

站长自己的评论也会推送到QQ,如果不想可以加if判断

(注意:可能无效,甚至连访客也无法判断)

if($admin_email!=$comment_author_email){
   //code
}

6、测试上线

用站长和游客身份分别测试一下,OK就上线。

Invitation
QQ Group
1095632335

created:04/01/2020

Welcome to the Group

Use this card to join us and participate in a pleasant discussion together .

Welcome to JISHUSONGSHU Group,wish you a nice day .