我需要创建一个令牌/密钥以将其用作数字顺序,因此这应该是唯一的,令牌必须类似于“6X990742MG185953R”,因此我们可以像条形码一样使用它,例如。http://barcodes4.me/barcode/c128b/6X990742MG185953R.png
我们不能使用 UUID 或 GUID,因为太长了,我们越接近是这样的:
function uuid64() {
$uuid = uuid(); // some UUID v4
$byteString = "";
$uuid = str_replace("-", "", $uuid);
for($i = 0; $i < strlen($uuid); $i += 2) {
$s = substr($uuid, $i, 2);
$d = hexdec($s);
$c = chr($d);
$byteString = $byteString.$c;
}
$b64uuid = base64_encode($byteString);
// Replace the "/" and "+" since they are reserved characters
$b64uuid = str_replace("/", "_", $b64uuid);
$b64uuid = str_replace("+", "-", $b64uuid);
// Remove the trailing "=="
$b64uuid = substr($b64uuid, 0, strlen($b64uuid) - 2);
return $b64uuid;
}