import { $fetch } from 'ofetch' import { createError, defineEventHandler, readBody } from 'h3' import { useRuntimeConfig } from '#imports' import { getTenantFromContext } from '../../../utils/tenant' /** * 证件 OCR 识别(身份证人像面 / 营业执照) * POST /api/tender/ocr/recognize { materialType: 'idcard_front' | 'license', fileUrl } * 代理到 mp-api /api/hjc/ocr/recognize(匿名放行,注册页在登录前调用)。 * * OCR 未配置 AK 时后端返回失败,前端提示「识别失败,请手动填写」,不阻断提交。 */ export default defineEventHandler(async (event) => { const config = useRuntimeConfig() const ctx = getTenantFromContext(event, config) const body = await readBody(event) try { const res = await $fetch('/hjc/ocr/recognize', { baseURL: config.public.modulesApiBase, method: 'POST', headers: { TenantId: ctx.tenantId }, query: { TenantId: ctx.tenantId }, body }) as any return res && res.data !== undefined ? res.data : res } catch (error: any) { throw createError({ statusCode: error?.statusCode || error?.response?.status || 502, statusMessage: error?.data?.message || error?.statusMessage || '识别失败' }) } })