改用Server酱Turbo版推送WordPress评论

 5666

这几天发现博客有评论Server酱推送微信消息了,上Server酱官网才发现旧版推送已经下线了,新的Turbo版启用企业微信应用消息通道,看了下新旧版本调用函数代码大同小异,新版修改如下,欢迎食用:

  1. //评论微信推送  
  2. function wpso_wechet_comment_notify($comment_id) {
  3.     $text = get_bloginfo('name'). '上有新的评论';
  4.     $comment = get_comment($comment_id);
  5.     $desp = $comment->comment_author.' 同学在文章《'.get_the_title($comment->comment_post_ID).'》中给您的留言为:'.$comment->comment_content;
  6.     $key = '你的SendKey';
  7.     $postdata = http_build_query( array( 'text' => $text, 'desp' => $desp ));
  8.     $opts = array(
  9.         http' => array(
  10.             'method'  => 'POST',
  11.             'header'  => 'Content-type: application/x-www-form-urlencoded',
  12.             'content' => $postdata
  13.         )
  14.     );
  15.     $context = stream_context_create($opts);
  16.     $admin_email = get_bloginfo ('admin_email');
  17.     $comment_author_email = trim($comment->comment_author_email);
  18.     if($admin_email!=$comment_author_email){
  19.         return $result = file_get_contents('https://sctapi.ftqq.com/'.$key.'.send', false, $context);
  20.     }
  21. }
  22. add_action('comment_post', 'wpso_wechet_comment_notify', 19, 2);

消息通道设置请移步Server酱Turbo版官网按说明操作即可,修改第6行SendKey为你所获取的值。


转载自:https://www.yxt521.com/network/1557.html

本文网址:https://www.zztuku.com/index.php/detail-8963.html
站长图库 - 改用Server酱Turbo版推送WordPress评论
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐