
下面介绍如何配置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文件内添加函数
/**
* 评论推送到 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);

评论(0)
暂无评论