diff --git a/server/api/tender/ocr/recognize.post.ts b/server/api/tender/ocr/recognize.post.ts index 3836b6b..2f85ee0 100644 --- a/server/api/tender/ocr/recognize.post.ts +++ b/server/api/tender/ocr/recognize.post.ts @@ -2,6 +2,7 @@ import { $fetch } from 'ofetch' import { createError, defineEventHandler, readBody } from 'h3' import { useRuntimeConfig } from '#imports' import { getTenantFromContext } from '../../../utils/tenant' +import { getRealClientIp } from '../../../utils/ip' /** * 证件 OCR 识别(身份证人像面 / 营业执照) @@ -15,11 +16,16 @@ export default defineEventHandler(async (event) => { const ctx = getTenantFromContext(event, config) const body = await readBody(event) + // 透传真实客户端 IP:后端按 IP 对匿名付费的 OCR 接口限流(注册页在登录前调用)。 + // 不透传时后端 IpUtil 只能拿到 Nuxt 服务器的出口 IP,限流会退化成「整个官网共用一份配额」, + // 正常用户反而被误限,而 H5 浏览器直连后端却能拿到真实 IP —— 同一策略两条链路行为相反。 + const clientIp = getRealClientIp(event) + try { const res = await $fetch('/hjc/ocr/recognize', { baseURL: config.public.modulesApiBase, method: 'POST', - headers: { TenantId: ctx.tenantId }, + headers: { TenantId: ctx.tenantId, 'X-Forwarded-For': clientIp }, query: { TenantId: ctx.tenantId }, body }) as any