首先打开Server酱官网,按照要求去做好,获取SCKEY:Server酱官网

在WordPress中集成

把代码放入到functions.php当中:

  1. /
  2. *WordPress评论微信推送
  3. http://www.wpxzt.com/
  4. */
  5. function sc_send($comment_id)
  6. {
  7. $text = '有大佬来评论啦!!!';
  8. $comment = get_comment($comment_id);
  9. $desp = $comment->comment_content;
  10. $key = '这里填写你刚刚获取到的SCKEY';
  11. $postdata = http_build_query(
  12. array(
  13. 'text' => $text,
  14. 'desp' => $desp
  15. )
  16. );
  17. $opts = array('http' =>
  18. array(
  19. 'method' => 'POST',
  20. 'header' => 'Content-type: application/x-www-form-urlencoded',
  21. 'content' => $postdata
  22. )
  23. );
  24. $context = stream_context_create($opts);
  25. return $result = file_get_contents('https://sc.ftqq.com/'.$key.'.send', false, $context);
  26. }
  27. add_action('comment_post', 'sc_send', 19, 2);

至此,结束。

参与评论