效果图如图:
在模板的 function.php文件中增加代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | //评论微信推送-小灰灰 function hui_send($comment_id){ $comment = get_comment($comment_id); //获取评论内容 $desp = $comment->comment_content; //获取评论时间 $dataTime = $comment->comment_date; //获取评论人昵称 $author = $comment->comment_author; //获取网站标题 $web_name = get_bloginfo('name'); //获取当前文章标题 $title = get_the_title($comment->comment_post_ID); //获取当前文章的url地址 $url = "https://xiaohuihui.net.cn/archives/".$comment->comment_post_ID.".html"; //你的推送url地址【这里是企业微信群机器人api地址】 $post_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=**********"; $post_data = '{"msgtype": "markdown","markdown": {"content": "## <font color=\"red\" >【'.$web_name.'】有新评论啦<\/font>\n ><font color=\"warning\">标题:</font>'.$title.'\n ><font color=\"warning\">时间:</font>'.$dataTime.'\n ><font color=\"warning\">昵称:</font>'.$author.'\n ><font color=\"warning\">网址:</font>['.$url.']('.$url.')\n ><font color=\"warning\">评论内容:</font>\n <font color=\"info\" >'.$desp.'</font> "}}'; return $res = curl_post($post_url, $post_data); } add_action('comment_post', 'hui_send', 19, 2); //使用curl-post发送消息 if (!function_exists('curl_post')){ function curl_post($post_url, $post_data) { $ch = curl_init(); $header[] = ""; curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_URL, $post_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $output = curl_exec($ch); curl_close($ch); return $output; } } |