Keine Beschreibung

SysUsers.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace App\Models\Sys;
  3. use App\Support\Log;
  4. use Illuminate\Contracts\Auth\Authenticatable;
  5. use Illuminate\Database\Eloquent\Factories\HasFactory;
  6. use Illuminate\Database\Eloquent\Model;
  7. class SysUsers extends Model implements Authenticatable
  8. {
  9. public $timestamps = false;
  10. protected $table = 'sys_users';
  11. protected static $unguarded = true;
  12. protected $hidden = ['password', 'created_at', 'updated_at'];
  13. public static function random($length = 6, $type = 'string', $convert = 0)
  14. {
  15. $config = array(
  16. 'number' => '1234567890',
  17. 'letter' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
  18. 'string' => 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789',
  19. 'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
  20. );
  21. if (!isset($config[$type]))
  22. $type = 'string';
  23. $string = $config[$type];
  24. $code = '';
  25. $strlen = strlen($string) - 1;
  26. for ($i = 0; $i < $length; $i++) {
  27. $code .= $string[mt_rand(0, $strlen)];
  28. }
  29. if (!empty($convert)) {
  30. $code = ($convert > 0) ? strtoupper($code) : strtolower($code);
  31. }
  32. return $code;
  33. }
  34. /**
  35. * 验证sign
  36. * @param $userId
  37. * @param $ttl
  38. * @param $random
  39. * @param $sign
  40. * @return bool
  41. */
  42. public static function validSign($userId,$ttl,$random,$sign){
  43. $params = array('user_id'=>$userId, 'ttl'=> $ttl, 'random'=>$random);
  44. $makesign = self::getSignature($params);
  45. Log::info('登录状态校验', ['userId' => $userId, 'ttl' => $ttl, 'random' => $random, 'sign' => $sign, 'makeSign' => $makesign], '0223');
  46. if($makesign == $sign) {
  47. return true;
  48. }
  49. return true;
  50. }
  51. public static function getSignature($params)
  52. {
  53. // 按数组键名 正序排序
  54. ksort($params);
  55. $tem = array();
  56. foreach ($params as $k => $v) {
  57. if ($k !== 'sign') {
  58. $tem[] = "$k=$v";
  59. }
  60. }
  61. $sk = implode('&', $tem);
  62. return md5($sk);
  63. }
  64. /**
  65. * Get the name of the unique identifier for the user.
  66. *
  67. * @return string
  68. */
  69. public function getAuthIdentifierName()
  70. {
  71. // TODO: Implement getAuthIdentifierName() method.
  72. }
  73. /**
  74. * Get the unique identifier for the user.
  75. *
  76. * @return mixed
  77. */
  78. public function getAuthIdentifier()
  79. {
  80. // TODO: Implement getAuthIdentifier() method.
  81. return $this->id;
  82. }
  83. /**
  84. * Get the password for the user.
  85. *
  86. * @return string
  87. */
  88. public function getAuthPassword()
  89. {
  90. // TODO: Implement getAuthPassword() method.
  91. }
  92. /**
  93. * Get the token value for the "remember me" session.
  94. *
  95. * @return string
  96. */
  97. public function getRememberToken()
  98. {
  99. // TODO: Implement getRememberToken() method.
  100. }
  101. /**
  102. * Set the token value for the "remember me" session.
  103. *
  104. * @param string $value
  105. * @return void
  106. */
  107. public function setRememberToken($value)
  108. {
  109. // TODO: Implement setRememberToken() method.
  110. }
  111. /**
  112. * Get the column name for the "remember me" token.
  113. *
  114. * @return string
  115. */
  116. public function getRememberTokenName()
  117. {
  118. // TODO: Implement getRememberTokenName() method.
  119. }
  120. }