当前位置:
首页 >
微信群管理之全网黑名单的实现
发布时间:2023/12/8
41
豆豆
生活随笔
收集整理的这篇文章主要介绍了
微信群管理之全网黑名单的实现
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
为了方便引流,防止“坏人”进入我们的社群,因此能用大家收集起来的黑名单不是很爽嘛!
实现业务逻辑:通过PHP 接口API获取服务器黑名单。本地其他进群的功能过滤时,只要是黑名单里的用户就立即踢出群。实现隔离这些黑名单人群。
接口代码实现很简单:
<?php //根据指定完成功能//验证合法性 // $token = $_GET['token']; // if ($token!='123456') { // echo "no"; // exit(); // }$act = isset($_GET['act']) ? addslashes($_GET['act']) : 'read'; //获取列表 if ($act == 'act_getlist') {//读取文件直接返回 blackuser_data.php$file_path = 'blackuser_data.php';$myfile = fopen($file_path, "r") or die("Unable to open file!");$content = fread($myfile,filesize($file_path)); fclose($myfile);echo $content; } //新增 elseif ($act == 'act_add') {$new_wxid = $_GET['wxid']."\n";$file_path = 'blackuser_data.php';$myfile = fopen($file_path, "a+") or die("Unable to open file!");fwrite($myfile, $new_wxid);fclose($myfile);echo 'true'; } //删除 elseif ($act == 'act_delete') {$wxid = $_GET['wxid'];$file_path = 'blackuser_data.php';if(delTargetLine($file_path, $wxid))echo 'true';elseecho "false"; }function delTargetLine($filePath, $target) {$result = null;$fileCont = file_get_contents($filePath);$targetIndex = strpos($fileCont, $target); #查找目标字符串的坐标// print_r($targetIndex);if ($targetIndex !== false) {//找到target的前一个换行符$preChLineIndex = strrpos(substr($fileCont, 0, $targetIndex + 1), "\n");//找到target的后一个换行符$AfterChLineIndex = strpos(substr($fileCont, $targetIndex), "\n") + $targetIndex;if ($preChLineIndex !== false && $AfterChLineIndex !== false) {//重新写入删掉指定行后的内容$result = substr($fileCont, 0, $preChLineIndex + 1) . substr($fileCont, $AfterChLineIndex + 1);$fp = fopen($filePath, "w+");fwrite($fp, $result);fclose($fp);return true;}}return false; }?>
总结
以上是生活随笔为你收集整理的微信群管理之全网黑名单的实现的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 【maven本地打包脚本】Git/Svn
- 下一篇: 句子批量给单词加注释加音标并标红