where('merchant_id', $loginInfo['merchant_id']) ->find(); if (!$user) { return json([ 'state' => 0, 'code' => 401, 'message' => '用户信息不存在', 'data' => [] ]); } // 获取客户端IP $clientIp = IpWhiteListService::getRealIp(); // 检查IP白名单 if (!IpWhiteListService::checkIpWhiteList($clientIp, $user->white_list_ip)) { // 记录IP限制访问日志 trace("用户 {$user->user_name} 尝试从IP {$clientIp} 访问 {$request->pathinfo()},但不在白名单 {$user->white_list_ip} 中", 'warning'); return json([ 'state' => 0, 'code' => 403, 'message' => 'IP地址不在白名单中,禁止访问', 'data' => [ 'client_ip' => $clientIp, 'white_list_ip' => $user->white_list_ip, 'requested_url' => $request->pathinfo() ] ]); } // IP检查通过,继续执行 return $next($request); } }