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齥鴖髩黉

本书共63小节:

评论 (写第一个评论)