PHP 生成永远唯一的密钥码、激活码自定义方法函数

/**
 * 生成永远唯一的密钥码
 * sha512(返回128位) sha384(返回96位) sha256(返回64位) md5(返回32位)
 * 还有很多Hash函数......
 * @author xiaochaun
 * @param int $type 返回格式:0大小写混合  1全大写  2全小写
 * @param string $func 启用算法:                
 * @return string
 */
function create_secret($type=0, $func='sha512')
{
    $uid = md5(uniqid(rand(),true).microtime());
    $hash = hash($func, $uid);
    $arr = str_split($hash);
    foreach($arr as $v){
        if($type==0){
            $newArr[]= empty(rand(0,1)) ? strtoupper($v) : $v;
        }
        if($type==1){
            $newArr[]= strtoupper($v);
        }
        if($type==2){
            $newArr[]= $v;
        }
    }
    return implode('', $newArr);
}
^_^ 亲爱的客官,如果您觉得本文对您有好处,请移动你的鼠标点点下面的关注我,一起学习,一起分享.~ ^_^
原文地址:https://www.cnblogs.com/blts/p/15070333.html