Server酱 | 网站小帮手
为网站新评论添加微信提醒功能!
前几天收到了一条评论,
我是在Wechat上看到提醒的,
感谢Server酱提供的提醒服务
查消息详情:
网站上查看评论:
注意看留言时间与评论提醒时间
在同一分钟内,可见消息同步之迅速
第一个外部评论,好激动!赶紧回复
功能实现思路方法参考了记磊博客
Server酱是什么?查看官网回答
网站评论,微信提醒实现方法如下:
一、登录账号,绑定Wechat
1、登录账号:首先需要一个 GitHub 账号来登入 Server酱网站
官网免费注册账号:https://github.com/
2、绑定Wechat:点击「微信推送」,扫码关注同时即可完成绑定。
二、测试消息,获取SCKEY
1、在 http://sc.ftqq.com/SCKEY.send 发送消息,看是否能在微信里收到;
2、复制保存 SCKEY,后面要用。
三、添加代码,保存测试
1、将 SCKEY 替换到下方代码中的“你的 SCKEY”,添加到当前主题的 function.php 文件保存,并刷新缓存。
2、在网站上留言,看是否能收到消息提醒,若不能则检查代码是否正确插入。
function sc_send($comment_id)
{
$text = '提醒主人,又有小伙伴来留言了';
$comment = get_comment($comment_id);
$desp = $comment->comment_content;
$key = '你的SCKEY';
$postdata = http_build_query(
array(
'text' => $text,
'desp' => $desp
)
);
$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://sc.ftqq.com/'.$key.'.send', false, $context);
}
add_action('comment_post', 'sc_send', 19, 2);
据说Server酱还有一些高级玩法
大家可以留言交流一下哦!
来源:https://www.jishusongshu.com/wordpress-site/serverchan-website-helper/
封面图:服务号【方糖】头像
扩展阅读
编辑于 2020-02-27 20:03