增加token验证接口
This commit is contained in:
parent
ee78dc4a7d
commit
848061d20f
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
namespace app\api\controller;
|
namespace app\api\controller;
|
||||||
|
|
||||||
|
use app\common\cache\UserTokenCache;
|
||||||
|
use app\common\model\Company;
|
||||||
use app\api\validate\{LoginAccountValidate, RegisterValidate, WebScanLoginValidate, WechatLoginValidate};
|
use app\api\validate\{LoginAccountValidate, RegisterValidate, WebScanLoginValidate, WechatLoginValidate};
|
||||||
use app\api\logic\LoginLogic;
|
use app\api\logic\LoginLogic;
|
||||||
use app\api\logic\UserLogic;
|
use app\api\logic\UserLogic;
|
||||||
@ -23,6 +25,7 @@ use Firebase\JWT\JWT;
|
|||||||
use Firebase\JWT\Key;
|
use Firebase\JWT\Key;
|
||||||
use think\facade\{Db, Config};
|
use think\facade\{Db, Config};
|
||||||
use app\common\service\FileService;
|
use app\common\service\FileService;
|
||||||
|
use function Symfony\Component\String\s;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录注册
|
* 登录注册
|
||||||
@ -32,7 +35,7 @@ use app\common\service\FileService;
|
|||||||
class LoginController extends BaseApiController
|
class LoginController extends BaseApiController
|
||||||
{
|
{
|
||||||
|
|
||||||
public array $notNeedLogin = ['register', 'account', 'logout', 'codeUrl', 'oaLogin', 'mnpLogin', 'getScanCode', 'scanLogin', 'shop_account'];
|
public array $notNeedLogin = ['register', 'account', 'logout', 'codeUrl', 'oaLogin', 'mnpLogin', 'getScanCode', 'scanLogin', 'shop_account','checkToken'];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -255,4 +258,23 @@ class LoginController extends BaseApiController
|
|||||||
LoginLogic::updateUser($params, $this->userId);
|
LoginLogic::updateUser($params, $this->userId);
|
||||||
return $this->success('操作成功', [], 1, 1);
|
return $this->success('操作成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkToken(): \think\response\Json
|
||||||
|
{
|
||||||
|
$token = $this->request->post('token');
|
||||||
|
if(empty($token)){
|
||||||
|
return $this->fail('参数错误');
|
||||||
|
}
|
||||||
|
$userInfo = (new UserTokenCache())->getUserInfo($token);
|
||||||
|
if(!$userInfo){
|
||||||
|
return $this->fail('token无效');
|
||||||
|
}
|
||||||
|
//获取公司信息
|
||||||
|
$company = Company::field('company_name,company_type')->where('id',$userInfo['company_id'])->findOrEmpty();
|
||||||
|
if(!$company->isEmpty()){
|
||||||
|
$userInfo['company_name'] = $company['company_name'];
|
||||||
|
$userInfo['company_type'] = $company['company_type'];
|
||||||
|
}
|
||||||
|
return $this->success('请求成功',$userInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user