123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2020/12/23
- * Time: 16:24
- */
- namespace App\Models;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Contracts\Auth\Authenticatable;
- use Illuminate\Database\Eloquent\Model;
- class Users extends Model implements Authenticatable
- {
- const LOGIN_TOKEN_REDIS_KEY_PRE = 'newMediaCa.loginToken:';
- protected $table = 'users';
- public $timestamps = false;
- protected $hidden = ['password', 'is_delete', 'created_at', 'updated_at'];
- protected static $unguarded = true;
- public function role()
- {
- return $this->hasOne(Roles::class, 'id', 'role_id');
- }
- public function scopeActive(Builder $query)
- {
- return $query->where('is_delete', 0);
- }
- public static function random($length = 6, $type = 'string', $convert = 0)
- {
- $config = array(
- 'number' => '1234567890',
- 'letter' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
- 'string' => 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789',
- 'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
- );
- if (!isset($config[$type]))
- $type = 'string';
- $string = $config[$type];
- $code = '';
- $strlen = strlen($string) - 1;
- for ($i = 0; $i < $length; $i++) {
- $code .= $string{mt_rand(0, $strlen)};
- }
- if (!empty($convert)) {
- $code = ($convert > 0) ? strtoupper($code) : strtolower($code);
- }
- return $code;
- }
- /**
- * 验证sign
- * @param $userId
- * @param $ttl
- * @param $random
- * @param $sign
- * @return bool
- */
- public static function validSign($userId,$ttl,$random,$sign){
- $params = array('user_id'=>$userId, 'ttl'=> $ttl, 'random'=>$random);
- $makesign = self::getSignature($params);
- if($makesign == $sign) {
- return true;
- }
- return false;
- }
- public static function getSignature($params)
- {
- // 按数组键名 正序排序
- ksort($params);
- $tem = array();
- foreach ($params as $k => $v) {
- if ($k !== 'sign') {
- $tem[] = "$k=$v";
- }
- }
- $sk = implode('&', $tem);
- return md5($sk);
- }
- /**
- * Get the name of the unique identifier for the user.
- *
- * @return string
- */
- public function getAuthIdentifierName()
- {
- // TODO: Implement getAuthIdentifierName() method.
- }
- /**
- * Get the unique identifier for the user.
- *
- * @return mixed
- */
- public function getAuthIdentifier()
- {
- // TODO: Implement getAuthIdentifier() method.
- return $this->id;
- }
- /**
- * Get the password for the user.
- *
- * @return string
- */
- public function getAuthPassword()
- {
- // TODO: Implement getAuthPassword() method.
- }
- /**
- * Get the token value for the "remember me" session.
- *
- * @return string
- */
- public function getRememberToken()
- {
- // TODO: Implement getRememberToken() method.
- }
- /**
- * Set the token value for the "remember me" session.
- *
- * @param string $value
- * @return void
- */
- public function setRememberToken($value)
- {
- // TODO: Implement setRememberToken() method.
- }
- /**
- * Get the column name for the "remember me" token.
- *
- * @return string
- */
- public function getRememberTokenName()
- {
- // TODO: Implement getRememberTokenName() method.
- }
- }
|