UUIDs.php 819 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace app\common\library;
  8. class UUIDs {
  9. /**
  10. * 生成一个UUID
  11. * @return type
  12. */
  13. public static function uuid(){
  14. $str = md5(uniqid(mt_rand(), true));
  15. $uuid = substr($str,0,8) ;
  16. $uuid .= substr($str,8,4) ;
  17. $uuid .= substr($str,12,4) ;
  18. $uuid .= substr($str,16,4) ;
  19. $uuid .= substr($str,20,12);
  20. return $uuid;
  21. }
  22. /**
  23. * 生成一个16位UUID
  24. * @return type
  25. */
  26. public static function uuid16(){
  27. return substr(md5(uniqid(rand(),1)), 8, 16);;
  28. }
  29. }