微信群管理之全网黑名单的实现

为了方便引流,防止“坏人”进入我们的社群,因此能用大家收集起来的黑名单不是很爽嘛!

实现业务逻辑:通过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;
}

?>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值