Files
huangjingfen/pro_v3.5.1/app/http/middleware/supplier/AuthTokenMiddleware.php

42 lines
1.2 KiB
PHP
Raw Normal View History

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace app\http\middleware\supplier;
use app\Request;
use app\services\supplier\LoginServices;
use crmeb\interfaces\MiddlewareInterface;
use think\facade\Config;
/**
* Class AuthTokenMiddleware
* @package app\http\middleware\supplier
*/
class AuthTokenMiddleware implements MiddlewareInterface
{
/**
* @param Request $request
* @param \Closure $next
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function handle(Request $request, \Closure $next)
{
$token = trim(ltrim($request->header(Config::get('cookie.token_name', 'Authori-zation')), 'Bearer'));
/** @var LoginServices $services */
$services = app()->make(LoginServices::class);
$outInfo = $services->parseToken($token);
$request->supplierId = (int)$outInfo['id'];
$request->supplierInfo = $outInfo;
return $next($request);
}
}