Commit c95fbab9 by 杨昕

优化获取token接口

parent bb2f471b
Pipeline #14732 passed with stages
in 52 seconds
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use App\Model\LogModel;
use Closure; use Closure;
use Carbon\Carbon; use Carbon\Carbon;
use App\Exceptions\ControllerException; use App\Exceptions\ControllerException;
...@@ -30,31 +31,32 @@ class Apprialisal ...@@ -30,31 +31,32 @@ class Apprialisal
} }
$token = substr($headers['authorization'][0],7); $token = substr($headers['authorization'][0],7);
$user = DB::connection('mongodb')->collection("users")->where("token",$token)->first();
if (empty($user)){
return error("请求异常:Authorization不存在",1014);
}
try { try {
$params = decrypt($token); decrypt($token);
} catch (DecryptException $e) { } catch (DecryptException $e) {
return error('token非法'); return error('token非法');
} }
$user = DB::connection('mongodb')->collection("users")->where("token",$token)->first();
if (empty($user)){
return error("请求异常:Authorization不存在",1014);
}
try{
$idArr = ($user['_id'])->jsonSerialize(); $idArr = ($user['_id'])->jsonSerialize();
$_id = $idArr['$oid']; }catch (\Exception $e){
LogModel::addlog(['获取用户数据异常'=>$request->all()]);
return error("获取用户数据异常,请重新登录再试!",1015);
}
$request->replace(array_merge($request->all(), [ $request->replace(array_merge($request->all(), [
'access_token' => substr($headers['authorization'][0], 7), 'access_token' => substr($headers['authorization'][0], 7),
'token_username' => $user['name'], 'token_username' => $user['name'],
'token_user_id' => $_id, 'token_user_id' => $idArr['$oid'],
'mis_uid' => $user['mis_uid'] 'mis_uid' => $user['mis_uid']
])); ]));
return $next($request); return $next($request);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment