Created
May 21, 2018 08:29
-
-
Save HavenShen/d1cece0193861fd42707442dbc08ea8c to your computer and use it in GitHub Desktop.
安全随机安字符串函数使用拓展生成订单号。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| 安全随机字符串 | |
|-------------------------------------------------------------------------- | |
| | |
| 安全随机安字符串函数使用。 | |
| | |
*/ | |
echo bin2hex(openssl_random_pseudo_bytes(128)); | |
// 拓展生成订单号 | |
function generateOrderId($lenght = 13) | |
{ | |
return date('ymd') . bin2hex(openssl_random_pseudo_bytes(ceil($lenght / 2))) . str_pad(rand(1, 9999), 5, 0, STR_PAD_LEFT); | |
} | |
echo generateOrderId(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment