@Jwt()
注解,主要用于校验Jwt-Token是否有效。
场景:校验Jwt-Token是否有效。
支持:HTTP
注解:@Jwt()
参数:
type=""
get
、post
、raw
、header
post
name=""
csrf
tips=""
false
否、true
是一个完整的案例如下:
<?php
namespace app\http;
use x\controller\Http;
class Index extends Http
{
/**
* @RequestMapping(route="/index", method="get", title="主页")
* @Jwt(type="header", name="Bearer token", tips="JWT校验错误")
*/
public function index() {
return $this->fetch('校验通过了');
}
/**
* @RequestMapping(route="/test", method="get", title="主页")
*/
public function test() {
// 这里生成token到视图,然后放到headers里提交到index路由测试
return $this->fetch(jwt());
}
}
当校验不通过时,会回调到生命周期\box\lifecycle\jwt_error
类中进行处理。