【31】网站有新评论时推送给站长
1、注册号企业微信并创建应用(获取应用的AgentId 和 Secret),并将网站域名添加到应用白名单
2、在服务器中新建一个文件夹,例如(WeChat)然后创建一个 index.php 文件将下面代码复制进去(你只需要填写文件中的 13 行 14 行和 77 行,把刚才企业 ID 和应用 AgentId 及 secret 填写进去即可)
<?php
//wordpress 企业微信通知插件觅知核心代码,不懂请勿修改,以免报错
$url = $_POST['url'];
$title = $_POST['title'];
$description = $_POST['description'];
// 声明页面 header
header("Content-type:text/html;charset=utf-8");
// 获取 access_token
function getToken(){
// 定义 id 和 secret
$corpid='xxxxxxx';//这里填写你的企业 ID
$corpsecret='xxxxxxx';//这里填写你刚创建的应用 secret
// 读取 access_token
include './access_token.php';
// 判断是否过期
if (time() > $access_token['expires']){
// 如果已经过期就得重新获取并缓存
$access_token = array();
$access_token['access_token'] = getNewToken($corpid,$corpsecret);
$access_token['expires']=time()+7000;
// 将数组写入 php 文件
$arr = '<?php'.PHP_EOL.'$access_token = '.var_export($access_token,true).';'.PHP_EOL.'?>';
$arrfile = fopen("./access_token.php","w");
fwrite($arrfile,$arr);
fclose($arrfile);
// 返回当前的 access_token
return $access_token['access_token'];
}else{
// 如果没有过期就直接读取缓存文件
return $access_token['access_token'];
}
}
// 获取新的 access_token
function getNewToken($corpid,$corpsecret){
$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$corpid}&corpsecret={$corpsecret}";
$access_token_Arr = https_request($url);
return $access_token_Arr['access_token'];
}
// curl 请求函数
function https_request ($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$out = curl_exec($ch);
curl_close($ch);
return json_decode($out,true);
}
// 发送应用消息函数
function send($data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='.getToken());
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}
// 文本卡片消息体
$postdata = array(
'touser' => '@all',
'msgtype' => 'textcard',
'agentid' => 'xxxxxx',//这里填写你刚创建的应用 AgentId
'textcard' => array(
'title' => $title,
'description' => $description,
'url' => $url,
'btntxt' => '阅读全文',
),
'enable_id_trans' => 0,
'enable_duplicate_check' => 0,
'duplicate_check_interval' => 1800
);
// 调用发送函数
echo send(json_encode($postdata));
?>
3、将下面代码添加到你的主题目录中的 functions.php 文件最后即可,注意修改代码中的 29 行把刚才的文件地址放进去就可以,不懂的话看下图
//觅知博客企业微信推送消息功能代码开始
function push_weixin($comment_id)
{
// 通过 comment_id 获取 comment 全部信息
$comment = get_comment($comment_id);
$siteurl = get_bloginfo('url');
// 根据自己需求,产生相关描述,可以包括文章内容、评论人、IP、评论内容等
$title = '文章 《' . get_the_title($comment->comment_post_ID) . '》 有新评论啦!';
$desp = "作者: $comment->comment_author \n 邮箱: $comment->comment_author_email \n 评论: $comment->comment_content";
$url = "$siteurl/?p=$comment->comment_post_ID#comments";
// 封装一个 Object 对象,其 msg 字段是我们需要推送到 QQ 的消息内容
$postdata = http_build_query(
array(
'title' => $title,
'description' => $desp,
'url' => $url
)
);
// 一个 POST 请求
$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('你创建的接口地址/index.php', false, $context);
}
// 挂载 WordPress 评论提交的接口
add_action('comment_post', 'push_weixin', 19, 2);
4、最后关注一下企业微信这个应用,接收一下通知即可。
【32】给网站添加联系站长侧边按钮
1、后台主题设置—>自定义代码—>自定义 CSS 样式代码把下面的代码添加到里面
/*左边联系站长 css 开始*/
.contact-help{position: fixed; z-index: 101; left: 0; top: calc(50% - 30px); margin-top: -36px; width: 28px; height: 72px; transition: all .3s; font-size: 12px;background: var(--main-bg-color);border-radius: 0 5px 5px 0; padding: 8px 7px; line-height: 14px;}@media screen and (max-width: 768px){.contact-help{display:none;}}
/*左边联系站长 css 开始*/
2、在主题目录下 themes/zibll/footer.php 下,添加下面的 PHP 代码:
<!--左侧联系站长-->
<a href="https://lvye.fun/MyWebsite/huoma/index.php?hmid=44854" target="_blank" class="contact-help main-shadow" style="font-weight:700;" />联系站长</a>
【33】自动给网站图片增加alt和title信息
只需要在主题目录下functions.php文件里面最下面,然后下面的代码复制进去即可。
/** 图自动加 alt 和 title 标签属性 */
function image_alt_tag($content){
global $post;preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images)) {foreach($images[1] as $index => $value)
{$new_img = str_replace('<img', '<img alt="'.get_the_title().'-'.get_bloginfo('name').'" title="'.get_the_title().'-'.get_bloginfo('name').'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);}}
return $content;
}
add_filter('the_content', 'image_alt_tag', 99999);
/** 自动给图片添加 alt 和 title 标签 www.98dou.cn */
【34】禁用网站F12并提醒
在主题目录下的header.php文件中粘贴如下代码
<!--禁用F12即复制提醒开始-->
<!-- 引入VUE -->
<script src="https://你的资源链接/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://你的资源链接/index.js"></script>
<!-- 引入样式 -->
<link rel="stylesheet" href="https://你的资源链接/index.css">
<script src="https://你的资源链接/fobidden.js"></script>
<!--禁用F12即复制提醒结束-->
温馨提示:本文最后更新于
2024-08-08 22:04:13
,部分文章具有时效性,若有已失效,请在下方留言感谢您的来访,获取更多精品内容请收藏本站。
© 版权声明
THE END
暂无评论内容