/**
* 获取随机字符串
* @param int $randLength 长度
* @param int $addtime 是否加入时间戳
* @param int $format 0:只字符 1:字符和数字 2:只数字
* @return string
*/
function getRandStr($randLength=6, $addtime=1, $format=0)
{
switch ($format) {
case '0':
$chars='abcdefghijklmnopqrstuvwxyz';
break;
case '1':
$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQEST123456789';
break;
case '2':
$chars='0123456789';
break;
default:
$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQEST123456789';
break;
}
$len=strlen($chars);
$randStr='';
for ($i=0;$i<$randLength;$i++) {
$randStr.=$chars[rand(0, $len-1)];
}
$tokenvalue=$randStr;
if ($addtime) {
$tokenvalue=time().$randStr;
}
return $tokenvalue;
}