API 参考
以编程方式生成 Code 128 和 GS1 条码。简洁的 REST API,支持 JSON 响应和图片下载。
Free:100 次请求/天
Business:50,000 次请求/月
快速入门
curl"https://www.barcode-code128.com/api/barcode/render?value=HELLO-WORLD&format=PNG&resolution=300"--outputbarcode.png
端点
GET
/api/barcode/render
下载条码图片
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| value | string | — | 必填。 要编码的条码内容。 |
| symbology | string | Code128Auto | Code128Auto, Code128A, Code128B, Code128C, GS1_128, GS1_DataMatrix, GS1_QR |
| format | string | PNG | PNG, SVG, PDF, EPS |
| resolution | int | 300 | DPI: 150, 300, 600, 1200 |
| xDimension | decimal | 0.33 | 条码模块宽度(mm) |
| barHeight | decimal | 25.4 | 条码高度(mm) |
| showText | bool | true | 在条码下方显示可读文本 |
| foregroundColor | string | #000000 | 条码颜色(hex) |
| backgroundColor | string | #FFFFFF | 背景颜色(hex) |
| barWidthReduction | decimal | 0 | 印刷修正量(mm) |
POST
/api/barcode/batch
生成多个条码并打包为 ZIP
发送包含值数组的 JSON 请求体。返回一个 ZIP 文件,其中每个值对应一个条码。
{
"values": ["SKU-001", "SKU-002", "SKU-003"],
"symbology": "Code128Auto",
"format": "PNG",
"resolution": 300
}
POST
/api/gs1/render
根据结构化数据生成 GS1 条码
发送 GS1 应用标识符字段。API 负责处理编码、FNC1 分隔符和校验位。
{
"fields": [
{ "ai": "01", "value": "05412345000013" },
{ "ai": "10", "value": "LOT-A23" },
{ "ai": "17", "value": "260731" }
],
"symbology": "GS1_128",
"format": "PNG",
"resolution": 300
}
GET
/api/barcode/quota
查看当前用量
{ "usedToday": 3, "dailyLimit": 5, "remaining": 2, "tier": "Free" }
试验场
在线试用 API — 无需注册。
progress_activity
api
发送请求后,结果将在此处显示。
代码示例
cURL
curl "https://www.barcode-code128.com\ /api/barcode/render\ ?value=SKU-4711\ &format=PNG\ &resolution=300" \ --output barcode.png
Python
import requests
resp = requests.get(
"https://www.barcode-code128.com"
"/api/barcode/render",
params={
"value": "SKU-4711",
"format": "PNG",
"resolution": 300
}
)
with open("barcode.png", "wb") as f:
f.write(resp.content)
Node.js
const fs = require('fs');
const url = new URL(
"https://www.barcode-code128.com"
+ "/api/barcode/render"
);
url.searchParams.set("value", "SKU-4711");
url.searchParams.set("format", "PNG");
url.searchParams.set("resolution", "300");
const resp = await fetch(url);
const buf = await resp.arrayBuffer();
fs.writeFileSync(
"barcode.png",
Buffer.from(buf)
);