getClientIp(); if ($this->isClientIPPermitted($ip) == false) { return new JsonResponse("$ip is forbidden", 403); } return $next($request); } /** * 内网ip判断 * @param $ip * @return bool */ private function isClientIPPermitted($ip) { if (!app()->environment('production', 'staging')) { return true; } if (Str::startsWith($ip, [ '127.0.0.1', //局域网 '192.168.', //vpc '10.0.', //pod network '172.20.', //北京办公区 '172.16.' ])) { return true; } return false; } }