From 46666d1c2f87eeeec96e158b73f605d9bc8ba5ac Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 3 Mar 2026 16:08:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=BE=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/SystemController.php | 24 ++++++++++++++++------ app/common/utils/SystemAuth.php | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/common/controller/SystemController.php b/app/common/controller/SystemController.php index 73f84d2..a845fad 100644 --- a/app/common/controller/SystemController.php +++ b/app/common/controller/SystemController.php @@ -117,12 +117,24 @@ class SystemController */ private function buildJwtPayload(User $user, ?Systems $system): array { + $now = time(); + $exp = $now + config('jwt.jwt_expiration'); + $system_ids = $user->systems ? $user->systems->pluck('id')->toArray() : []; + $role_ids = $user->roles ? $user->roles->pluck('id')->toArray() : []; $payload = [ - 'user_id' => $user->id, - 'sn' => $user->sn ?? '', - 'name' => $user->name ?? '', - 'iat' => time(), - 'exp' => time() + config('jwt.jwt_expiration'), + 'sub' => 'user_' . $user->id, + 'aud' => $system->code, + 'iat' => $now, + 'exp' => $exp, + 'nbf' => $now, + 'typ' => 'access', + 'uid' => $user->id, + 'uname' => $user->name, + 'role_ids' => $role_ids, + 'system_ids' => $system_ids, +// 'user_id' => $user->id, +// 'sn' => $user->sn ?? '', +// 'name' => $user->name ?? '', ]; if ($system) { @@ -193,7 +205,7 @@ class SystemController 'system_code' => $systemCode, 'login_ip' => $ip, 'user_agent' => $ua, - 'expired_at' => date('Y-m-d H:i:s', $expireAt), + 'expired_at' => $expireAt, ]); } } diff --git a/app/common/utils/SystemAuth.php b/app/common/utils/SystemAuth.php index cbef538..6977fa8 100644 --- a/app/common/utils/SystemAuth.php +++ b/app/common/utils/SystemAuth.php @@ -14,7 +14,7 @@ class SystemAuth public static function generateSignature(string $userId, int $timestamp, string $secret): string { $data = $userId . $timestamp; - return hash_hmac('sha256', $data, $secret); + return hash_hmac('md5', $data, $secret); } /**