<p><img src="https://qrcode.api.yangzihome.space/qr?text={{.URL}}&cellSize=4&margin=0&errorCorrectionLevel=H&typeNumber=5" width="120" /></p>
增加引用API 生成二维码图片
使用说明
二维码生成服务的基础 URL:
https://qrcode.api.yangzihome.space/qr
查询参数
响应
成功: 返回
image/gif
类型的 GIF 格式二维码图片。失败: 返回
application/json
类型的错误信息。
成功响应示例 (HTTP 200 OK)
请求:
GET https://qrcode.api.yangzihome.space/qr?text=Hello%20API!
响应:
Content-Type: image/gif
(Binary GIF image data)
上图为使用参数 text=Hello%20API!&cellSize=4&margin=4&errorCorrectionLevel=M
生成的示例。
错误响应示例 (HTTP 400 Bad Request)
请求:
GET https://qrcode.api.yangzihome.space/qr
响应:
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"error": "Missing `text` or `url` parameter"
}
错误响应示例 (HTTP 500 Internal Server Error)
如果二维码生成过程中发生内部错误 (例如,尝试编码的数据过大导致超出二维码容量),可能会返回 500 错误:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"error": "Failed to generate QR code",
"details": "code length overflow. (too much data)"
}
缓存
成功的二维码图片响应会包含 Cache-Control: public, max-age=604800
头,表示图片将在浏览器和 CDN 边缘缓存 7 天(604800 秒),以提高性能并减少 Workers 的调用次数。