<?phpdeclare (strict_types = 1);namespace app\index\middleware;class After{/** * 处理请求 * * @param \think\Request $request * @param \Closure $next * @return Response */public function handle($request, \Closure $next){$response = $next($request);// 添加中间件执行代码// 从header里判断是否是jsonif (method_exists($response, 'header') && in_array('application/json; charset=utf-8', $response->getHeader())) {$data = $response->getData();$data['extra'] = '后置中间件额外参数';$response = $response->data($data);}return $response;}}