request->method(); // 接收参数 if ($method == 'GET') { $params = request()->get(); } else { $params = request()->post(); } // 合并验证参数 $params = array_merge($params, $validate_data); // 获取允许的参数列表 $allowedParams = $this->getAllowedParams($scene); // 检查多余参数 if (!empty($allowedParams)) { $extraParams = array_diff(array_keys($params), $allowedParams); if (!empty($extraParams)) { JsonService::throw('不允许的参数: ' . implode(', ', $extraParams)); } } // 执行常规验证 return $this->goCheck($scene, $params); } /** * 获取允许的参数列表 * @param string|null $scene * @return array */ protected function getAllowedParams($scene = null): array { $allowedParams = []; // 获取验证规则中的参数 if (property_exists($this, 'rule')) { $allowedParams = array_keys($this->rule); } // 如果有场景验证,获取场景对应的参数 if (!empty($scene) && property_exists($this, 'scene')) { $scenes = $this->scene ?? []; if (isset($scenes[$scene])) { $allowedParams = $scenes[$scene]; } } return $allowedParams; } }