微信群管理之全网黑名单的实现
生活随笔
收集整理的這篇文章主要介紹了
微信群管理之全网黑名单的实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為了方便引流,防止“壞人”進入我們的社群,因此能用大家收集起來的黑名單不是很爽嘛!
實現業務邏輯:通過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
- 下一篇: 句子批量给单词加注释加音标并标红