跳到正文

QrConfig 参考

这是你 POST 到 /api/qr/generate 的请求体(模板和 AI 端点会在其基础上覆盖)。未设置的字段都会回退到引擎默认值,除 content 外没有其他必填字段。

权威来源:.NET 后端中的 Models/QrModels.cs。下面的列表涵盖了所有公开字段;如需包含类型和可空性的完整 schema,请在前端仓库中运行 pnpm docs:schema,它会根据 C# 模型重新生成本页。

内容

字段类型默认值说明
contentstring必填要编码的 URL 或文本。最多 4296 个字符。
eccLevelenumM纠错。L 7% · M 15% · Q 25% · H 30%。添加 logo 时请提高到 H。

输出

字段类型默认值说明
fileFormatenumpngpng、jpg、svg、pdf、webp。
responseTypeenumbase64base64 返回 JSON;binary 返回原始文件。
outputWidthint800像素。最大 4096。
outputHeightint—默认等于 outputWidth。仅在需要非正方形时覆盖。
pixelsPerModuleint10每个二维码模块的分辨率。未设置时会相应提高 outputWidth。
qualityint90JPG/WebP 质量,1–100。
transparentBackgroundboolfalse仅限 PNG/SVG/WebP。

颜色

字段类型默认值说明
primaryColorhex#000000模块颜色。#RGB、#RRGGBB、#RRGGBBAA。
secondaryColorhex—用于渐变和连接模块。
backgroundColorhex#FFFFFF静区颜色。
foregroundStyleenumsolidsolid、linearGradient、radialGradient、sweepGradient。
gradientTypeenumlinear等同于 foregroundStyle 的简写。
gradientDirectionenumverticalvertical、horizontal、diagonal、diagonal-reverse。
gradientColorshex[]—2–6 个色标。
gradientStopsfloat[]均匀分布0–1 的位置。必须与 gradientColors.length 一致。
gradientAngleint0角度(度)。设置后会覆盖 gradientDirection。

模块(点)

字段类型默认值说明
qrShapeenumsquare画布外形:square、roundedsquare、circle。
qrShapeRadiusint0qrShape: roundedsquare 时的圆角半径。
moduleShapeenumsquare27 种之一。参见模式。
moduleScalefloat1.00.5–1.0。缩小每个模块,让外观更通透。
moduleRotationfloat0角度(度)。
moduleStyleenumsolidsolid、outline、striped。
modulePatternenumstandardstandard、checker、alternating。
moduleSizeVariationfloat00–0.3,为每个模块加入自然的大小变化。
connectedStyleenumnonenone、fluid、sharp、round。连接相邻模块。

定位图案(3 个大码眼)

字段类型默认值说明
finderOuterShapeenumsquaresquare、roundedsquare、circle、diamond、octagon、target、double。
finderInnerShapeenumsquaresquare、roundedsquare、circle、diamond、star、dot。
finderOuterColorhex—默认为 primaryColor。
finderInnerColorhex—默认为 primaryColor。
finderStyleenumstandardstandard、flat、embossed。
字段类型默认值说明
logoUrlurl—由服务器端获取的公开 URL。PNG/JPG/GIF/BMP/WebP,≤ 10 MB。
logoBase64string—替代方案:内联 data URI。
logoFilemultipart—使用 multipart/form-data 时的二进制部分。
logoShapeenumsquaresquare、circle、rounded。
logoSizePercentfloat185–30。≥ 20 时务必将 eccLevel 提高到 H。
logoBorderWidthint0边框粗细(像素)。
logoBorderColorhex#FFFFFF
logoShadowboolfalselogo 下方的投影。
logoBackgroundenumnonenone、solid、match-bg。
cleanBehindLogobooltrue清除 logo 下方的模块,避免与二维码相互干扰。

文字叠加

字段类型说明
centerTextobject横跨中心的横幅:{ text, color?, backgroundColor?, height?, fontSize?, bold?, fontFamily? }。
circularTextobject环绕二维码的弧形文字:{ text, color?, fontSize?, position? }。
ctaTextstring二维码下方的说明文字(例如“SCAN ME”)。
ctaTextStyleobject{ color?, fontSize?, fontFamily?, bold?, italic? }。

边框

字段类型说明
frameobject{ enabled, shape, color, width, padding, cornerRadius, fillColor? }。形状:rectangle、speech-bubble、badge、shield、circle。

背景图片

字段类型说明
backgroundImageUrl / backgroundImageBase64url/string渲染在二维码背后的柔和图片。
backgroundImageBlendModeenumnormal、multiply、screen、overlay。
backgroundImageOpacityfloat0–1。
backgroundImageBlurint像素。
backgroundImageFitenumcover、contain、stretch。

效果

字段类型说明
shadowobject{ color, blur, offsetX, offsetY }。
glowobject{ color, blur, intensity }。
embossobject{ depth, lightAngle, lightColor?, shadowColor? }。
noisefloat0–0.3,添加胶片颗粒感。
blurint像素。
edgeFadefloat0–0.5,让画布边缘渐隐。
colorFilterenumnone、sepia、bw、cool、warm。

AI 专用(仅限 /api/qr/ai/generate*)

字段类型说明
promptstring自然语言描述。
stylePresetenumminimal、artistic、corporate、playful、luxury、tech、nature。
creativityfloat0–1。控制 LLM 的 temperature 和大胆程度。
strictScannabilitybool为 true 时,引擎会自动修正 ECC/对比度。
llmProviderenum仅限市场:openai、anthropic、google、mistral、cohere、groq。
llmApiKeystring仅限市场。只转发一次,从不记录日志。
llmModelstring可选;默认使用该提供商的低价旗舰模型。

验证顺序

  1. JSON 格式是否正确 → 否则返回 INVALID_JSON。
  2. 字段类型和范围 → 返回带 details[] 的 VALIDATION_ERROR。
  3. 颜色对比度 → 低于 4:1 且 strictScannability: true 时返回 LOW_CONTRAST。
  4. logo 尺寸与 ECC 的关系 → 过于激进时返回 LOGO_TOO_LARGE。
  5. ISO 18004 解码往返测试 → 渲染结果无法被重新读取时返回 QR_GENERATION_FAILED。

完整的错误代码列表请参阅错误。

重新生成本页

cd frontend
pnpm docs:schema   # reads ../Models/QrModels.cs and rewrites this file

脚本是 tools/gen-docs-schema.ts。在 C# 模型中添加并带有 [Description] 特性的字段会自动出现在这里。