首先打开Server酱官网,按照要求去做好,获取SCKEY:Server酱官网
- 登入:用GitHub账号登入网站,就能获得一个SCKEY(在「发送消息」页面)
- 绑定:点击「微信推送」,扫码关注同时即可完成绑定
- 发消息:往 http://sc.ftqq.com/SCKEY.send 发GET请求,就可以在微信里收到消息啦
在WordPress中集成
把代码放入到functions.php
当中:
- /
- *WordPress评论微信推送
- http://www.wpxzt.com/
- */
- 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);
至此,结束。