效果就是图上这样,博客有人发布留言之后就自动发送评论到站长的个人微信上面!而且有提示音,和普通发微信给你一样的效果!
快让你的博客活跃起来吧!
具体代码
add_action('comment_post', 'comment_WeChat_notify');
function comment_WeChat_notify($comment_id){
$comment = get_comment($comment_id);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
$spam_confirmed = $comment->comment_approved;
function send_post($url, $post_data) {
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
$url = get_option('home');
$description = "<div class='gray'>有人在《".get_the_title($comment->comment_post_ID)."》给您留言啦!<br>".trim($comment->comment_author)."说:".trim($comment->comment_content)."</div>";
$post_data = array(
'corpid'=>'****',
'corpsecret'=>'***',
'agentid'=>'***',
'title'=>'有人在你的博客上评论留言啦!',
'description'=>$description,
'url'=>$url
);
send_post('https://api.htm.fun/api/Wechat/text_card/',$post_data);
}
使用教程
请查看下面这篇文章,获取你的corpid、corpsecret、agentid
3 条评论
这段代码 是贴在那个php文件呢?是那个主题内的functions.php文件么
老哥,能分享一下,你的建站模板吗?