PHP高并发下生成唯一的不重复的订单id,以及生成不重复的用户token

生成不重复的订单id

    public function getOrderId($prefix = 'DD')
    {
        return $prefix . (strtotime(date('YmdHis', time()))) . substr(microtime(), 2, 6) . sprintf('%03d', rand(0, 999));
    }

生成app的用户token

    public function getToken()
    {
        //strtoupper转换成全大写的
        $charid = strtoupper(md5(uniqid(mt_rand(), true)));
        return substr($charid, 0, 8) . substr($charid, 8, 4) . substr($charid, 12, 4) . substr($charid, 16, 4) . substr($charid, 20, 12);
    }


你可能感兴趣的:(php)