凌的博客

您现在的位置是: 首页 > 学无止境 > PHP > 

PHP

QQ手机号规则

2022-08-01 PHP 1822
<?php
class QQNumbers {

    //创建12个为一个批次列表
    protected $listCount = 12;

    public function gNumCheck($str)
    {
            //注意正则规则必须不是 双引号
        //5个及以上重复的数字 eg AAAAA
        $pattern='/([\d])\1{4,}/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }
        //两组及以上四个相同数字 AAAABBBB
        $pattern='/([\d])\1{3,}([\d])\2{3,}/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }
        //三组及以上三个相同数字 AAACCCFFF
        $pattern='/([\d])\1{2,}([\d])\2{2,}([\d])\3{2,}/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }
        //三位连对 AABBCC
        $pattern='/(?:22(?=33)|33(?=44)|44(?=55)|55(?=66)|66(?=77)|77(?=88)|88(?=99)){3}\d/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }
        //两组以上AACC的对子 AACCAACC
        $pattern='/(([\d]){1,}([\d]){1,})\1{1,}/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }
        //五位以上顺子 ABCDE
        $pattern='/(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){4,}\d/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }
        //五位以上逆顺 EDCBA
        $pattern = '/(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){4,}\d/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }
        //两组以上三位顺子ABCABC
        $pattern = '/((?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){2,}\d)\1/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }
        //两组以上三位逆顺子CBACBA
        $pattern = '/((?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2,}\d)\1/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }
        //对称性 ABC(D)CBA
        $pattern = '/(\d)(\d)(\d)(\d)\4?\3\2\1/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }
        //爱情号
        $pattern = '/^5201314/';
        preg_match($pattern,$str,$arr);
        if ($arr[0]??false){
            return false;
        }

        return true;
    }

    //递归批量创建qq号
    public function creatBatchNumbers(array $gNumbers)
    {
        while (count($gNumbers) < $this->listCount) {
            $gNumber = mt_rand(10000000, 99999999);
            if ($this->gNumCheck($gNumber)) {
                $gNumbers[] = $gNumber;
            }
        }
        //TODO 去除已占用QQ号码
        //TODO 去除预占用列表
       
        return count($gNumbers) == $this->listCount ? $gNumbers : $this->creatGNumbers($gNumbers);
    }

    //获取可选的QQ号码
    public function getBatchQQNums()
    {
        //todo 限定获取次数
        //生成可用QQ号码列表
        $numArr = [];
        $numArr = $this->creatBatchNumbers($numArr);

        //TODO 失效该用户预占用qq号码
        //TODO记录可用QQ号码列表 作为该用户的预占用
    
        return ['qq_nums' => $numArr];
    }

}

$qqNums = (new QQNumbers())->getBatchQQNums();
var_dump($qqNums);

// array(1) {
//     ["qq_nums"]=>
//     array(12) {
//       [0]=>
//       int(71843795)
//       [1]=>
//       int(69223632)
//       [2]=>
//       int(84505498)
//       [3]=>
//       int(16698823)
//       [4]=>
//       int(37498613)
//       [5]=>
//       int(82087251)
//       [6]=>
//       int(80695814)
//       [7]=>
//       int(22823504)
//       [8]=>
//       int(79333762)
//       [9]=>
//       int(99749277)
//       [10]=>
//       int(18317311)
//       [11]=>
//       int(57864377)
//     }
//   }
  
?>


文章评论

0条评论