php 生成邀请码

/* phpalapi 接口  生成邀请码 */
public function createCode(){
$code = 'ABCDEFGHIJKLMNPQRSTUVWXYZ';
$rand = $code[rand(0,25)]
.strtoupper(dechex(date('m')))
.date('d').substr(time(),-5)
.substr(microtime(),2,5)
.sprintf('%02d',rand(0,99));
for(
$a = md5( $rand, true ),
$s = '123456789ABCDEFGHIJKLMNPQRSTUV',
$d = '',
$f = 0;
$f < 6;
$g = ord( $a[ $f ] ),
$d .= $s[ ( $g ^ ord( $a[ $f + 6 ] ) ) - $g & 0x1F ],
$f++
);

if(mb_strlen($d)==6){

//查询数据库是否存在邀请码

$oneinfo=DI()->notorm->users
->select("id")
->where('code=?',$d)
->fetchOne();
if(!$oneinfo){
return $d;
}
}
$d=$this->createCode();
return $d;

}


/* php代码 生成邀请码 */
function createCode(){
$code = 'ABCDEFGHIJKLMNPQRSTUVWXYZ';
$rand = $code[rand(0,25)]
.strtoupper(dechex(date('m')))
.date('d').substr(time(),-5)
.substr(microtime(),2,5)
.sprintf('%02d',rand(0,99));
for(
$a = md5( $rand, true ),
$s = '123456789ABCDEFGHIJKLMNPQRSTUV',
$d = '',
$f = 0;
$f < 6;
$g = ord( $a[ $f ] ),
$d .= $s[ ( $g ^ ord( $a[ $f + 6 ] ) ) - $g & 0x1F ],
$f++
);
if(mb_strlen($d)==6){
$oneinfo=M("users")->field("id")->where("code='{$d}'")->find();
if(!$oneinfo){
return $d;
}
}

   
        $d=createCode();
return $d;
}


猜你喜欢

转载自blog.csdn.net/u014724048/article/details/78166137
今日推荐