更新token解析

This commit is contained in:
yaooo 2023-11-13 15:18:31 +08:00
parent e5d9ee213c
commit 653bb99399
2 changed files with 8 additions and 5 deletions

View File

@ -93,13 +93,13 @@ class LoginLogic extends BaseLogic
{
try {
$where = ['phone' => $params['account']];
$user = User::field(['id', 'phone'])->where($where)->findOrEmpty();
$user = User::field(['id', 'phone', 'avatar', 'nick_name'])->where($where)->findOrEmpty();
//更新登录信息
$user->last_login_time = time();
$user->last_login_ip = request()->ip();
$user->save();
//设置token
$userInfo = JwtTokenService::createToken($user->id, $user->phone);
$userInfo = JwtTokenService::createToken($user->id, $user->toArray());
return [
'uid' => $userInfo['uid'],
'token' => $userInfo['token']
@ -150,6 +150,7 @@ class LoginLogic extends BaseLogic
{
try {
$userInfo = JwtTokenService::parseToken($params['token']);
return $userInfo;
return [
'uid' => $userInfo['uid'],
'phone' => $userInfo['phone']

View File

@ -33,7 +33,7 @@ class JwtTokenService
* @author xaboy
* @day 2020/10/13
*/
public static function createToken(int $id, string $phone, array $params = [])
public static function createToken(int $id, array $userinfo, array $params = [])
{
$time = time();
$host = app('request')->host();
@ -46,12 +46,14 @@ class JwtTokenService
];
$params['data'] = [
'uid' => $id,
'phone' => $phone
'phone' => $userinfo['phone'],
'avatar' => $userinfo['avatar'],
'nickname' => $userinfo['nick_name']
];
$token = JWT::encode($params, env('app.app_key', '123456'), 'HS256');
$tokenInfo = [
'uid' => $id,
'phone' => $phone,
'phone' => $userinfo['phone'],
'token' => $token
];
return $tokenInfo;