更新token解析
This commit is contained in:
parent
e5d9ee213c
commit
653bb99399
|
@ -93,13 +93,13 @@ class LoginLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$where = ['phone' => $params['account']];
|
$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_time = time();
|
||||||
$user->last_login_ip = request()->ip();
|
$user->last_login_ip = request()->ip();
|
||||||
$user->save();
|
$user->save();
|
||||||
//设置token
|
//设置token
|
||||||
$userInfo = JwtTokenService::createToken($user->id, $user->phone);
|
$userInfo = JwtTokenService::createToken($user->id, $user->toArray());
|
||||||
return [
|
return [
|
||||||
'uid' => $userInfo['uid'],
|
'uid' => $userInfo['uid'],
|
||||||
'token' => $userInfo['token']
|
'token' => $userInfo['token']
|
||||||
|
@ -150,6 +150,7 @@ class LoginLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$userInfo = JwtTokenService::parseToken($params['token']);
|
$userInfo = JwtTokenService::parseToken($params['token']);
|
||||||
|
return $userInfo;
|
||||||
return [
|
return [
|
||||||
'uid' => $userInfo['uid'],
|
'uid' => $userInfo['uid'],
|
||||||
'phone' => $userInfo['phone']
|
'phone' => $userInfo['phone']
|
||||||
|
|
|
@ -33,7 +33,7 @@ class JwtTokenService
|
||||||
* @author xaboy
|
* @author xaboy
|
||||||
* @day 2020/10/13
|
* @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();
|
$time = time();
|
||||||
$host = app('request')->host();
|
$host = app('request')->host();
|
||||||
|
@ -46,12 +46,14 @@ class JwtTokenService
|
||||||
];
|
];
|
||||||
$params['data'] = [
|
$params['data'] = [
|
||||||
'uid' => $id,
|
'uid' => $id,
|
||||||
'phone' => $phone
|
'phone' => $userinfo['phone'],
|
||||||
|
'avatar' => $userinfo['avatar'],
|
||||||
|
'nickname' => $userinfo['nick_name']
|
||||||
];
|
];
|
||||||
$token = JWT::encode($params, env('app.app_key', '123456'), 'HS256');
|
$token = JWT::encode($params, env('app.app_key', '123456'), 'HS256');
|
||||||
$tokenInfo = [
|
$tokenInfo = [
|
||||||
'uid' => $id,
|
'uid' => $id,
|
||||||
'phone' => $phone,
|
'phone' => $userinfo['phone'],
|
||||||
'token' => $token
|
'token' => $token
|
||||||
];
|
];
|
||||||
return $tokenInfo;
|
return $tokenInfo;
|
||||||
|
|
Loading…
Reference in New Issue