input('user_key'); $user_id = data_get(Hashids::decode($user_key), '0'); if (!$user_id) { return error('无效的用户密钥'); } // 白名单 IP 列表 $whitelist = AgentApi::where('user_id', $user_id)->value('ip_whitelist'); $whitelistArr = array_map('trim', explode("\n", $whitelist)); // 获取客户端的 IP 地址 $clientIp = $request->getClientIp(); if (!in_array($clientIp, $whitelistArr)) { return error('IP未加入白名单'); } return $next($request); } }