首页 > 技术文章 > 生成16位随机订单号的两种方法

kangshuai 2016-12-07 17:43 原文

方法一
<?php 
     $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
     $orderSn = $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
?>



方法二
<?php
    function build_order_no(){
        return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    }
    echo build_order_no();
?>

按照日期生成9位(8位数字)订单号

  

<?php
$yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
$cc = $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5);
echo $cc;             ------------   例G71753391

 

 

 

推荐阅读