产生唯一序列值的例子

<?php

namespace App\Util;

class Unique
{
    /**
     * 根据干扰值,产生唯一值
     * 返回md5之后的32个字符
     * @param string $annoyance
     * @return string
     */
    public static function get($annoyance)
    {
        $str = $annoyance . microtime(true) . self::randStr();
        return md5($str);
    }

    /**
     * 随机产生字符串
     *       
     * @param int $length
     *
     * @return string
     */
    public static function randStr($length=6) {

        $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        return substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
    
    }
    
}

猜你喜欢

转载自blog.csdn.net/fish_study_csdn/article/details/80907000
今日推荐