Skip to content

Instantly share code, notes, and snippets.

@HavenShen
Created May 21, 2018 08:29
Show Gist options
  • Save HavenShen/d1cece0193861fd42707442dbc08ea8c to your computer and use it in GitHub Desktop.
Save HavenShen/d1cece0193861fd42707442dbc08ea8c to your computer and use it in GitHub Desktop.
安全随机安字符串函数使用拓展生成订单号。
<?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