**/ namespace app\api\middleware; class Allow { public function handle($request, \Closure $next) { // 处理跨域 header('Access-Control-Allow-Origin: *'); header('Access-Control-Max-Age: 1800'); header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE'); header('Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With,access-token,token,adid,clickid,client'); // 第一次预请求不管 if (strtoupper($request->method()) == "OPTIONS") { exit; } // 处理跨域 // 后置中间件 $response = $next($request); return $response; } /** * 中间件结束调度 * @param \think\Response $response * @return void */ public function end(\think\Response $response) { } }