为了方便引流,防止“坏人”进入我们的社群,因此能用大家收集起来的黑名单不是很爽嘛!
实现业务逻辑:通过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'; else echo "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; } ?>