小编ElA*_*ecs的帖子

如何在php上创建一个唯一的20个单字节令牌/密钥/ ID?

我需要创建一个令牌/密钥以将其用作数字顺序,因此这应该是唯一的,令牌必须类似于"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) …
Run Code Online (Sandbox Code Playgroud)

php uuid guid token

1
推荐指数
1
解决办法
5357
查看次数

标签 统计

guid ×1

php ×1

token ×1

uuid ×1