35. 通用唯一识别码UUID

龺龸龶龲龮龫龨龧龥龡龲龮龝龛龘龖龒龏龎龌龋龇龆龄龁齽龸齹齶齲齱齯齮齫齨齧齦齣齠龲龮id齗龒齓齫齨齶齐齏齍齋龲齇齅齄齧齂鼿鼼鼿鼸鼵鼱龮id鼮鼭鼩鼦鼢鼡鼝龋鼛鼙鼗齏鼓鼏鼎齦鼊齧鼉鼱鼿鼇鼄齮鼁黽黼黺黷黶鼭黳黰鼉齧黯黭齦鼊黬鼄黨黤黢黡點鼛齮齧龶龸黛龡黙默鼩鼦黕黑齐鼁黽黼黺黷黎黋黈鼉黇齫齨黅黄黂麿龘龖龆麻齧麺齐麸黺麷麴齧龌龋麳麰麯麬齋龲齇齅齧麩麥龲龮麸黺鼁麣齧麸黺麢麟麞鼱龮麸黺鼁麛麚麙鼩麟麞麕麓黤麏黽黼黺黷麻麍麊鼱龮麸黺麉鼱黇麆黤uuid龆麻齮麷麴黎

UUID龧鹻齶齋龲齅鹷鹳Universally Unique IDentifier齧鼉鹕黨鹔鹑鹏GUID麯麬齋龲齅鹷鹳Globally Unique IDentifier齧鹄鹁齶齐鹀鸿鸻龝龛黙鸷龘龖齧齍龸鸵鸳鸰鸬鸫鸨黂齶齐鸥鸤齣鸡鸠黙鸷鸞鸜鸙齧黨齶麻鸕鸰window鸑黽鸏齧齄黤龲龮齶齏鸌鸋麿鹕鸈齋龲鸆齇齅龫龨齮鸄鸃齧鷿鷽麿鹕鸈鷹鷶麻鼉鷵齮鹕鷴鷲鸈鷴鷱齧鼦鼙龇鷰鼸鼵齮id黤鷬龲鷩鷥齮齧鼱鷡龲龸麆鼦鸌鸋默鷞齱鷜齮龫龨齧鷚鼱鸏鼉龮麟鷘鷗鷓龇鷰鷐龌龋麞鷏齧鷋鷊鷉鼉鷇黅齮鸄鸃齧麢龋鷃鷀鶿鷋鶽齂鼿鶹鶵鶴齏鷓龇鷰鷐齧鼱黅齐麍鶰鶮齮鶪龸鶧鶴鼦黤龲鶣鶟鶝齧鷚鶚龶鶙UUID鶗鶔黂鶐鷜鶍鶊齧鶇鶃龸龶龲鶃UUID麥鶁鵽鷜鷃鷀鶿鷋鶽齧鷜鵼鼉鸤鶽黎

UUID鵹鵵龧

麟齐UUID齮鵲鵯麻rfc4122鸙鵢鵠齧鵜鵘鵖龧

http://www.rfc-editor.org/rfc/rfc4122.txt

麟齐鼱鴽RFC鼉龲龮鴸鴶齧黤麟齐鴴鴳鴲齮齧鵖龧

http://www.rfc-editor.org/errata_search.php?rfc=4122&eid=3546

UUID:

UUID黤龲龮鼉128麩鴞齮鴛鴗鴓16鴴鴳鴐齧齏龁鴏麳鶔鴴鴋齮鴇鸠龸鷹鷶齧鴆鸠鹏8-4-4-4-12

鴃鵯鵢鵠鹏龧'[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}'

麥龧34415db0-ed84-48e5-8aae-9d7e03bb45e9

鼱128麩鴞齮鴛鴗鳮鳪龲鳨齮鴆鸠齧黛鳦龲鴛鳥鴲鵢鵠麥鶃龧

time_low 龧4鴴鴳32鴛齧鷹鷶鹕鷴齮鶽鴴鳣

time_mid 龧2鴴鴳16鴛齧鷹鷶鹕鷴齮鸙鴴鳣

time_hi_and_version龧2鴴鴳16鴛齧麓4鴛鷹鷶uuid鳡鳞鳜鳙齮鳘麛鴓鵖齍鴐齧鷋鳔鴛鷹鷶鹕鷴齮鼎鴴鳣

clk_seq_hi_res龧1鴴鴳8鴛齧麓2鷜3鴛鷹鷶uuid鳘麛鳐鳏鴓鵖齍鴐齧鷋鳔鴛鷹鷶鹕龎鴲鳎鼎鴴鳣

clk_seq_low龧1鴴鴳8鴛齧鷹鷶鹕龎鴲鳎鶽鴴鳣

node龧6鴴鴳48鴛齧鷹鷶鸈鷴默齮齅鹷齇齅

uuid齮龡黙鳊齮黤鳈鸙鳇鳅齧鼩鳂鲾鲺默麏黽黙鸷鶗麻鲷鼿鹕鷴鼸鼵齮uuid龌黤齋龲齮鴓鷊鲴默黤鼢鼡鷃鷀鶿鷋鶽鴐齧黛默鲰鶴齏龶鷜鼉60鴛龸鷹鷶鹕鷴齧鲮鲬黤100鲫龏鲪鹷齧鳊麓黼黺黷鲨鴲鲦麰鲢鲬鼄鸤麻鲟龏鲪鹷齧麻鲝龲黽黙鸷鶗默鲝龲鲨鴲鶴齏龇鷰鼩鲛鼵鲙uuid黨黤鼩鲝齮鴓麻rfc4122鸏鲰黨鵢鵠鲖鲓鼎鲐鷀鲍鲌uuid齮鸌鸋鲉鲈鴐齧鷚鼱鸏鼉龲龮龫龨齧黙鸷鶗齮鹕鷴鶴鼦鼢鼡齧麩麥鼉黇龡鳪鲅鲃齍黂鲀鱼鹕鷴齧鼱鷡龲龸鼸鼵鱺鲝uuid齮鱶鷀麆鳐鼄鲖齧鷿齏鱵鱲鹕龎鴲鳎鴴鳣鱰黼鼱龮龫龨齧麻龘龖鹁鱭鳅鹕鹕龎鴲鳎鴴鳣鱩鱧黤龲龮黯鶗鱥齧鸌鸋鲖鹕鷴默鶴鼦鱺鲝齮龫龨齧鱤鸌鸋鸈鷴默鱺鲝齮龫龨齧node鼉48鴛齧鱢鳙齮齄鶴齏黤龝鱞齮MAC鱙鱗鱖IP鱙鱗鱖鱑鶗鱏鱖url鱎齧齋龲齇齅龲黽龡鳪齮齇齅齧齏黋鱊鱆鸈鷴默齮鼢鼡黎

鼉鹕鱃鸰鸬鼩鼦鲍鲌鷜鹕鷴鱀鰽龡鳪齇齅齧齂鼼鼿鲉鼮齧鶴齏鰻齶黯鶗龄齮鴇鸠齧齂鼿麥鶁齅鹷齏鶁鶣鴇鸠鳡鳞齮uuid鼭鼱麆黤麓鷞齱鷜齮uuid鳡鳞鳜鳙鳘麛鴴鳣齮鰸齶齧齄鼉4鴛齧鳊麓鳨鰴鲖5鶣鳡鳞鴇鸠齧龝默鰰鰭麥鶃龧

UUID Version 1龧鸫齐鹕鷴齮UUID

鸫齐鹕鷴齮UUID鹻鰥黙鸷麕麓鹕鷴鰣鱖黯鶗龄鷲鶗黷MAC鱙鱗鶐鷜黎麺齐麻鸷鲈鸙鰢齶鲖MAC鱙鱗齧鼱龮鳘麛齮UUID鶴齏龇鷰麻麯鰞鰝鰜齮齋龲鸆黎鷚鰚黋鲝鹕齧鰢齶MAC鱙鱗黂鰖龸鶍麯鸆龫龨齧鼱麆黤鼱龮鳘麛UUID鰔鷜鰓鰒齮鱙鴇黎麥鰑鱩齶麢黤麻麬鰏龝鸙鰢齶齧黨鶴齏鰢齶鰍鳅齮鸷鲈齧齏IP鱙鱗龸鰉鰈MAC鱙鱗--Java齮UUID鰂鰂黤鼱鷡鷊鯿齮鴓麕鯽黨鵵鯹鲖鲍鲌MAC齮黡鲬鴐黎

UUID Version 2龧DCE鶍麯齮UUID

DCE鴓Distributed Computing Environment鴐鶍麯齮UUID鷲鸫齐鹕鷴齮UUID鸷鲈鱺鲝齧鷚黂鯶鹕鷴鰣齮麓4鴛鯴鯱鹏POSIX齮UID鱀GID黎鼱龮鳘麛齮UUID麻鷊鲴鸙鯧鯥齶鷜黎

UUID Version 3龧鸫齐鱏鴴齮UUID鴓MD5鴐

鸫齐鱏鴴齮UUID鹻鰥黙鸷鱏鴴鷲鱏鴴鸈鷴齮MD5鯡鳎鱥鶐鷜黎鼱龮鳘麛齮UUID龇鷰鲖龧鱺鲝鱏鴴鸈鷴鸙鼩鲝鱏鴴鼵鲙齮UUID齮齋龲鸆麉鼩鲝鱏鴴鸈鷴鸙齮UUID齮齋龲鸆麉鱺鲝鱏鴴鸈鷴鸙鱺鲝鱏鴴齮UUID鼢鼡鼵鲙黤鱺鲝齮黎

UUID Version 4龧黯鶗UUID

鯝鯛黯鶗龄齧鱀鰽鯘黯鶗龄鼵鲙UUID齧鷊鲴鸙鰂鰂鰢齶鯕鹳鯒默齮鼇黯鶗龄鼵鲙黷黎

UUID Version 5龧鸫齐鱏鴴齮UUID鴓SHA1鴐

鷲鳘麛3齮UUID鸷鲈鳜鯌齧麢黤鯡鳎鱥黙鸷鰢齶SHA1鴓Secure Hash Algorithm 1鴐鸷鲈黎

麓鷞鯉齱鷜clk_seq_hi_res鸙鼉鯇鷜鯅鴛齮鳘麛鳐鳏Variant鴴鳣齧齄黤鲷鼿鷏鯂鼮鼭鶴齏麊鸌鹏uuid鴴鳣鸡麬齮鳘麛麣齧麻uuid鸙麯鯁鴴鳣鴛齮鮿鰴鮼黕黑齐鼱龮鴴鳣鱥齮龡鯴齧鱺麕齐黤uuid鶗鶔齮鳘麛麣齧齏默鸌鮻齮鴴鳣鮿鰴鳊麓鳨鹏10齧麢齶鲖鯇龮鴛麉Variant鴴鳣齮鷋鮸鱥鱀鹏鱩黅鮷龸鳐鳅麙龇鮵齧鱀鹏鮱鮮鸆鵵鯹黎

鹻鰥默鲰齮鮫鮩齧鮥鸵鳡鳞鳘麛齮4鴛鷲鳐鳏鴴鳣齮鯇鴛齧鯉鼉122鴛齧鼱黤龲龮黢鼄齮龄鴴鴓5齍鲰黬36龮鮤鴐齧龘龖鼸鼵鱺鲝uuid齮鷃鷀黤鮡鮝鮡鮝鮛齮齧鼱龮黤龲龮鲷鼿鷃鮘鼮齧鮔黄齮鶧龧

鸙鮑鮐鮎鮌齮鷃鷀黤鮋齽齣鮈龲鲪鹷齧龥龡龒龏鮆龲鮅鮑鮐齧龲鮁鮆10齮21魽鴇魻齧麯鮼鸙鮎鮌齧鶴鼦鼊鼵鼱鷡齮魸鵘黶鼭

鱀鰽1鮋魶黽黙鸷鶗齧龒黽龒龏鼸鼵1魶龮uuid齧龌龋龲魲鴏龁魶魻魯黂鼢鼡

鼱鷡齮鷃鷀麆黤uuid鼢鼡齮鷃鷀齧黤魭鼦魬麍鶰鶮齮鶪鶵鶍鳇齮魪鹏uuid鼦魦龇鼩鼢鼡鼮鼭

drupal鸙齮uuid龧

麻drupal鸙鷊鳏齶鷜鲖uuid齧麥鰑龝魤鵲魣鵽齮黢鼄鹕齧黂魢魞龄鯛魛齣鷹齣魛齧黋鹕uuid魗鰖龸魓魐齧龘龖鸙uuid麺齏齄魌鱏齮uuid黼黺齱魋齧麥鶃龧

鮮黷黼黺id龧uuid

鳜龧Drupal\Component\Uuid\Php

鰢齶鴇鸠龧echo \Drupal::service("uuid")->generate();

鲨鴲鰉鹳鸌鮻麥鶃龧

class Php implements UuidInterface {
  public function generate() {
    // 使用密码级别的随机数生成器产生高质量随机性,将二进制转为16进制,$hex有32个字符
    $hex = bin2hex(Crypt::randomBytes(16));
    // 一个字节有两个十六进制字符,提取8个十六进制字符,4字节32位比特,表示时间低字段
    $time_low = substr($hex, 0, 8);
    //两字节表示时间中字段
    $time_mid = substr($hex, 8, 4);
    //此处字符4(不是数字)表示uuid创建版本为4,意指使用随机数生成,占用4比特位
    $time_hi_and_version = '4' . substr($hex, 13, 3);
    // 提取8比特位,并转换为十进制整数
    $clock_seq_hi_and_reserved = base_convert(substr($hex, 16, 2), 16, 10);
    //将前两位设置为0
    $clock_seq_hi_and_reserved &= 0b00111111;
    //将前两位设置为10
    $clock_seq_hi_and_reserved |= 0b10000000;
    //提取1字节(8位)做时钟序列低位
    $clock_seq_low = substr($hex, 18, 2);
    //余下的6字节48位作为设备标识
    $node = substr($hex, 20);
    //格式化输出
    $uuid = sprintf('%s-%s-%s-%02x%s-%s',
      $time_low, $time_mid, $time_hi_and_version,
      $clock_seq_hi_and_reserved, $clock_seq_low,
      $node
    );
    return $uuid;
  }
}

鶴齏龶鬥uuid齮鳦鯅鳣齮鳦龲龮鴴鴋鱭鬢鹏4齧黤麴鹏drupal鰢齶黯鶗龄齮鴇鸠龸鼵鲙uuid齧鬡鷉鼉齶鷜鹕鷴黨鷉鼉齶鷜龡鳪齇齅齧鳦鬞鳣齮鳦龲龮鴴鴋鹏鷥麳鶔10**鷹鷶齮鱥齧齂鰉鷹鳊麓uuid齮鳘麛鳜鳙

麻drupal鸙uuid黤齏鬙鸬鴇鸠齱魋齧鲝鹕鯉齱魋鲖鷋鮸鱶鶣鼵鲙鴇鸠齧鷚龌龋鬕鬓鼓鼏

麥鰑龌龋鬐鷰龲龮uuid鶴鰢齶龧

Drupal\Component\Uuid\Uuid:: isValid($uuid);

鬏鬍bool鱥齧鷹鷶黤魭鴋鬊uuid齮鴞鬇黎

本书共74小节:

评论 (写第一个评论)