//生成密码
private function getCardPwd($num=0){$pwd = array();
for($i=0;
$i<$num;
$i++){
//生成基本随机数
$charid = substr(MD5(uniqid(mt_rand(), true)),8,16).$this->get_RandomString(4,'2');
$pwd[$i]=strtoupper($charid);
}
return $pwd;
}
#创建随机字符串
private function get_RandomString($len=4,$flag='1'){$chars= null;
if($flag=='1'){
$chars = array( "0", "1", "2","3", "4", "5", "6", "7", "8", "9" );
}else{
$chars = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "0", "1", "2",
"3", "4", "5", "6", "7", "8", "9" );
}$charsLen = count($chars) - 1;
shuffle($chars);
// 将数组打乱$output = "";
for ($i=0;
$i< $len;
$i++){$output .= $chars[mt_rand(0, $charsLen)];
}
return $output;
}
//生成卡号
private function getCardId($prifix,$num=0,$length=8){//输出数组
$card = array();
//填补字符串
$pad = '';
//日期
$temp = time();
$Y = date('Y',$temp);
$M = date('m',$temp);
$D = date('d',$temp);
$TD= date('YmdHis',$temp);
//长度
$LY = strlen((string)$Y);
$LM = strlen((string)$M);
$LD = strlen((string)$D);
$LTD = strlen((string)$TD);
//流水号长度
$W = 5;
//根据长度生成填补字串
if($length<=12){
$pad = $prifix.$this->get_RandomString($length - $W);
}else if($length>12&&$length<=16){
$pad = $prifix.(string)$Y.$this->get_RandomString($length - ($LY+$W));
}else if($length>16&&$length<=20){
$pad = $prifix.(string)$Y.(string)$M.$this->get_RandomString($length - ($LY+$LM+$W));
}else{
$pad = $prifix.(string)$TD.$this->get_RandomString($length - ($LTD+$W));
}//生成X位流水号
for($i=0;
$i<$num;
$i++){
$STR=$pad.str_pad((string)($i+1),$W,'0',STR_PAD_LEFT);
$card[$i] = $STR;
}return $card;
}
【随机生成密码,卡密】
推荐阅读
- 对GO切片的理解
- 小程序商城网站开发秒杀模块篇
- 盲盒购物网站系统开发建设 第三篇
- Netty核心概念之ChannelHandler&Pipeline&ChannelHandlerContext
- 简单的线程池实现多线程对大文件的读取
- SSH 端口转发与 SOCKS 代理
- Ubuntu16.04/Scala2.11.8安装教程
- 学习PHP中的高精度计时器HRTime扩展
- 使用OpenResty+Lua实现灰度测试(金丝雀)
- 使用源码编译安装PHP扩展