Commit 903e38c9 authored by 王源's avatar 王源 🎧

添加通用判断token是否存在中间件

parent 7432bfdd
......@@ -12,9 +12,10 @@
"require": {
"ext-json": "*",
"ext-redis": "*",
"hyperf/db-connection": "^1.1@dev",
"hyperf/validation": "^1.1@dev",
"hyperf/command": "^1.1@dev"
"hyperf/framework": "~1.1.0",
"hyperf/db-connection": "~1.1.0",
"hyperf/validation": "~1.1.0",
"hyperf/command": "~1.1.0"
},
"minimum-stability": "dev",
"autoload": {
......
<?php
/**
* Created by PhpStorm.
* User: Zero
* Date: 2020/4/3
* Time: 10:17
*/
declare(strict_types=1);
namespace Meibuyu\Micro\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
class TokenExistMiddleware implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (token()) {
return $handler->handle($request);
} else {
return response()->json([
'code' => 403,
'msg' => 'token不存在'
]);
}
}
}
......@@ -71,10 +71,11 @@ if (!function_exists('request')) {
}
}
/**
* 响应实例
*/
if (!function_exists('response')) {
/**
* 响应实例
* @return mixed|ResponseInterface
*/
function response()
{
return container(ResponseInterface::class);
......
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