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齸鴊髚黚

本书共69小节:

评论 (写第一个评论)