make($this->auth_key); } /** * 获取将存储在JWT主题声明中的标识符。 * * @return mixed */ public function getJWTIdentifier() { return $this->auth_key; } public function getAuthIdentifierName() { return 'auth_key'; } /** * 返回一个键值数组,其中包含要添加到JWT的任何自定义声明。 * * @return array */ public function getJWTCustomClaims() { $user = UserModel::find($this->uid); return [ 'nickname' => $user->nickname, 'headimgurl' => $user->headimgurl, 'phone' => $user->phone, 'uid' => $this->uid ]; } public function validateCredentials($auth_key) { $data = $this->where(['auth_key' => $auth_key])->first()->toArray(); if (empty($data)) { return false; } else { return true; } } /** * 获取某种登录方式的key * @param int $uid 用户id * @param string $auth_type 登陆方式 * @return string auth_key * @throws AlertException */ public function getKeyOfType(int $uid, string $auth_type) { $auth = $this->where(array(['uid', $uid], ['auth_type', $auth_type]))->first(); if (collect($auth)->isEmpty()) { throw new AlertException("未找到登录方式", 404); } else { return $auth->auth_key; } } /** * 获取用户uid * @param string $auth_type * @return array * @throws AlertException */ public function getUidByKey(string $auth_type) { $auth = $this->where('auth_key', $auth_type)->first(); if (collect($auth)->isEmpty()) { throw new AlertException("未绑定", 404); } else { return $auth->uid; } } }