function generateUniqueString($username, $length = 20) {
// 使用uniqid()获取微秒级时间戳前缀
//$prefix = uniqid();
$time = time();
$prefix = substr(md5($username.microtime(true)), 0, 6);
$day = date("ymd", time());//6
$_stuff_time = substr($time, -4);
// 使用mt_rand()生成随机数补充剩余长度
$random = bin2hex(random_bytes(ceil(($length-14)/2)));
// 组合并截取到指定长度
$result = $prefix . $day . $_stuff_time . $random;
//echo $result."\n";
return substr($result, 0, $length);
}
// 示例使用
echo generateUniqueString(20);