如果我们在使用WordPress程序建站的时候,和网友进行互动一般是通过评论。能在第一时间给网友评论确实可以提高交互及时性。常见的我们有直接在每天看看是否有人评论,或者是用邮件提醒。但是有些时候由于服务器的问题,设置邮件提醒可能比较麻烦。这里我们可以使用微信提醒。

这里我们是使用的Server酱接口进行提醒的。

第一、申请接口

> 申请账号:http://sc.ftqq.com/3.version

这里我们需要申请接口。

第二、添加脚本

> //评论微信推送
> 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('http://sc.ftqq.com/'.$key.'.send', false, $context);
> }
> add_action('comment_post', 'sc_send', 19, 2);

在脚本中修改我们的KEY文件,然后贴到当前WP主题的Functions.php文件中。

就这么简单。