//生成密码
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;
}