通过 API 接口,您可以在自己的系统中集成条码生成能力。接口需要签名鉴权,请先在 账户管理 → API 密钥 中创建密钥。
https://mantianxing.cc/api/v1/generate| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| appid | string | 是 | API 密钥 AppKey |
| data | string | 是 | 请求数据,JSON 格式 |
| time | int | 是 | 当前时间戳(秒),时差不能超过 30 秒 |
| nostr | string | 是 | 随机字符串 |
| sign | string | 是 | 签名,生成规则见下方 |
sign = md5(appid + "#" + data + "#" + time + "#" + appkey + "#" + nostr)
appkey 为密钥私钥,仅参与签名,不参与请求传输。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | string | 是 | 码制类型,如 GS1_128、GS1_DATAMATRIX、QRCODE 等 |
| data | string | 是 | 条码数据 |
| scale | int | 否 | 缩放比例 1-10,默认 2 |
| notext | int | 否 | 隐藏文字:1=隐藏 0=显示,默认 1 |
| border | int | 否 | 边框宽度,默认 0 |
| format | string | 否 | 返回格式:image(图片流,默认)/ url / base64 |
返回 PNG 图片二进制数据,Content-Type: image/png,可直接用于 <img src="..."> 或保存为文件。
{
"code": 1,
"info": "请求响应成功!",
"data": {
"code": 1,
"info": "生成成功",
"data": {
"url": "/safefile/barcode/abc123.png"
}
}
}{
"code": 1,
"info": "请求响应成功!",
"data": {
"code": 1,
"info": "生成成功",
"data": {
"base64": "data:image/png;base64,iVBORw0KGgo..."
}
}
}{
"code": 1,
"info": "请求响应成功!",
"data": {
"code": 0,
"info": "配额已用完,请升级套餐"
}
}$appKey = 'BCxxxxxxxxxxxxxxxx';
$appSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$time = time();
$nostr = substr(md5(uniqid()), 0, 16);
$data = json_encode([
'type' => 'GS1_128',
'data' => '(01)06959385782633(10)202601012A',
'scale' => 2,
'format' => 'url',
]);
$sign = md5($appKey . '#' . $data . '#' . $time . '#' . $appSecret . '#' . $nostr);
$result = file_get_contents('https://mantianxing.cc/api/v1/generate', false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => http_build_query([
'appid' => $appKey, 'data' => $data, 'time' => $time, 'nostr' => $nostr, 'sign' => $sign,
]),
],
]));
$res = json_decode($result, true);
// $res['data']['url'] 即图片地址const appKey = 'BCxxxxxxxxxxxxxxxx';
const appSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const time = Math.ceil(Date.now() / 1000);
const nostr = Math.random().toString(36).substr(2, 15);
const data = JSON.stringify({ type: 'GS1_128', data: '(01)06959385782633(10)202601012A' });
const sign = md5(appKey + '#' + data + '#' + time + '#' + appSecret + '#' + nostr);
fetch('https://mantianxing.cc/api/v1/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ appid: appKey, data, time, nostr, sign }),
})
.then(res => res.blob())
.then(blob => {
const img = document.createElement('img');
img.src = URL.createObjectURL(blob);
document.body.appendChild(img);
});import hashlib, time, requests, random, string, json
app_key = 'BCxxxxxxxxxxxxxxxx'
app_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
timestamp = int(time.time())
nostr = ''.join(random.choices(string.ascii_lowercase + string.digits, k=16))
data = json.dumps({'type': 'GS1_128', 'data': '(01)06959385782633(10)202601012A'})
sign_str = f"{app_key}#{data}#{timestamp}#{app_secret}#{nostr}"
sign = hashlib.md5(sign_str.encode()).hexdigest()
resp = requests.post('https://mantianxing.cc/api/v1/generate', data={
'appid': app_key, 'data': data, 'time': timestamp, 'nostr': nostr, 'sign': sign,
})
with open('barcode.png', 'wb') as f:
f.write(resp.content)import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.*;
public class BarcodeApi {
public static void main(String[] args) throws Exception {
String appKey = "BCxxxxxxxxxxxxxxxx";
String appSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
long time = System.currentTimeMillis() / 1000;
String nostr = UUID.randomUUID().toString().replace("-", "").substring(0, 16);
String data = "{\"type\":\"GS1_128\",\"data\":\"(01)06959385782633(10)202601012A\"}";
String signStr = appKey + "#" + data + "#" + time + "#" + appSecret + "#" + nostr;
String sign = md5(signStr);
URL url = new URL("https://mantianxing.cc/api/v1/generate");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
String params = String.format("appid=%s&data=%s&time=%d&nostr=%s&sign=%s",
URLEncoder.encode(appKey, "UTF-8"),
URLEncoder.encode(data, "UTF-8"),
time,
URLEncoder.encode(nostr, "UTF-8"),
URLEncoder.encode(sign, "UTF-8")
);
try (OutputStream os = conn.getOutputStream()) {
os.write(params.getBytes(StandardCharsets.UTF_8));
}
try (InputStream is = conn.getInputStream();
FileOutputStream fos = new FileOutputStream("barcode.png")) {
byte[] buf = new byte[4096];
int len;
while ((len = is.read(buf)) > 0) fos.write(buf, 0, len);
}
}
static String md5(String input) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(input.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte b : digest) sb.append(String.format("%02x", b));
return sb.toString();
}
}package main
import (
"crypto/md5"
"fmt"
"io"
"net/http"
"net/url"
"os"
"time"
"math/rand"
)
func main() {
appKey := "BCxxxxxxxxxxxxxxxx"
appSecret := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
timestamp := time.Now().Unix()
nostr := fmt.Sprintf("%x", rand.Int63())[:16]
data := `{"type":"GS1_128","data":"(01)06959385782633(10)202601012A"}`
signStr := fmt.Sprintf("%s#%s#%d#%s#%s", appKey, data, timestamp, appSecret, nostr)
sign := fmt.Sprintf("%x", md5.Sum([]byte(signStr)))
resp, _ := http.PostForm("https://mantianxing.cc/api/v1/generate", url.Values{
"appid": {appKey},
"data": {data},
"time": {fmt.Sprintf("%d", timestamp)},
"nostr": {nostr},
"sign": {sign},
})
defer resp.Body.Close()
file, _ := os.Create("barcode.png")
defer file.Close()
io.Copy(file, resp.Body)
}# 生成签名
appKey="BCxxxxxxxxxxxxxxxx"
appSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
time=$(date +%s)
nostr=$(openssl rand -hex 8)
data='{"type":"GS1_128","data":"(01)06959385782633(10)202601012A"}'
sign=$(echo -n "$appKey#$data#$time#$appSecret#$nostr" | md5sum | cut -d' ' -f1)
# 请求生成条码
curl -X POST https://mantianxing.cc/api/v1/generate \
-d "appid=$appKey" \
-d "data=$data" \
-d "time=$time" \
-d "nostr=$nostr" \
-d "sign=$sign" \
-o barcode.png| 分类 | 码制名称 | type 值 | 示例数据 |
|---|---|---|---|
| 物流工业 | Code 128 | CODE128 | ABC123456 |
| 物流工业 | Code 128B | CODE128B | abcABC123 |
| 物流工业 | Code 39 | CODE39 | CODE39 |
| 物流工业 | 扩展 Code 39 | EXCODE39 | code39!@# |
| 物流工业 | Code 93 | CODE93 | CODE-93 |
| 物流工业 | Code 11 | CODE11 | 1234567890 |
| 物流工业 | Codabar | CODABAR | A12345B |
| 物流工业 | ITF-14 | ITF14 | 1234567890123 |
| 物流工业 | VIN | VIN | 1HGBH41JXMN109186 |
| 零售 | EAN-13 | EANX | 6907031121121 |
| 零售 | EAN-13 + 校验码 | EANX_CHK | 690703112112 |
| 零售 | EAN-13 复合码 | EANX_CC | 0123456789012|[17]251231 |
| 零售 | UPC-A | UPCA | 725272730706 |
| 零售 | UPC-A + 校验码 | UPCA_CHK | 725272730706 |
| 零售 | UPC-A 复合码 | UPCA_CC | 012345678905|[17]251231 |
| 零售 | UPC-E | UPCE | 0123456 |
| 零售 | UPC-E + 校验码 | UPCE_CHK | 0123457 |
| 零售 | UPC-E 复合码 | UPCE_CC | 01234565|[17]251231 |
| 零售 | EAN-14 | EAN14 | 1234567890123 |
| 零售 | ISBN | ISBNX | 9787121123450 |
| GS1 体系 | GS1-128 | GS1_128 | (01)06959385782633(10)202601012A |
| GS1 体系 | GS1-128 复合码 | GS1_128_CC | [01]01234567890128|[17]251231 |
| GS1 体系 | GS1 DataMatrix | GS1_DATAMATRIX | (01)06959385782633(10)202601012A(21)000001 |
| GS1 体系 | GS1 DataBar 全向 | DBAR_OMN | 0123456789012 |
| GS1 体系 | GS1 DataBar 有限 | DBAR_LTD | 0123456789012 |
| GS1 体系 | GS1 DataBar 扩展 | DBAR_EXP | [01]01234567890128 |
| GS1 体系 | GS1 DataBar 堆叠 | DBAR_STK | 0123456789012 |
| GS1 体系 | GS1 DataBar 全向堆叠 | DBAR_OMNSTK | 0123456789012 |
| GS1 体系 | GS1 DataBar 扩展堆叠 | DBAR_EXPSTK | [01]01234567890128 |
| 复合码 | GS1 DataBar 全向复合 | DBAR_OMN_CC | 01234567890128|[17]251231 |
| 复合码 | GS1 DataBar 有限复合 | DBAR_LTD_CC | 01234567890128|[17]251231 |
| 复合码 | GS1 DataBar 扩展复合 | DBAR_EXP_CC | [01]01234567890128|[17]251231 |
| 复合码 | GS1 DataBar 堆叠复合 | DBAR_STK_CC | 01234567890128|[17]251231 |
| 复合码 | GS1 DataBar 全向堆叠复合 | DBAR_OMNSTK_CC | 01234567890128|[17]251231 |
| 复合码 | GS1 DataBar 扩展堆叠复合 | DBAR_EXPSTK_CC | [01]01234567890128|[17]251231 |
| 二维码 | QR Code | QRCODE | https://example.com |
| 二维码 | Micro QR | MICROQR | 12345 |
| 二维码 | Data Matrix | DATAMATRIX | ABC123 |
| 二维码 | Aztec | AZTEC | Hello World |
| 二维码 | 汉信码 | HANXIN | 汉字测试 |
| 二维码 | Grid Matrix | GRIDMATRIX | Grid Test |
| 二维码 | Code One | CODEONE | 1234567890 |
| 二维码 | UPN QR | UPNQR | 1234567890 |
| 二维码 | 矩形 Micro QR | RMQR | 12345 |
| 二维码 | Ultracode | ULTRA | 123456 |
| 二维码 | Aztec Runes | AZRUNE | 12 |
| 二维码 | DotCode | DOTCODE | 12345678 |
| 堆叠码 | PDF417 | PDF417 | 条码生成器 |
| 堆叠码 | 紧凑 PDF417 | PDF417COMP | COMPACT |
| 堆叠码 | Micro PDF417 | MICROPDF417 | MICRO |
| 堆叠码 | MaxiCode | MAXICODE | 123456789012345678 |
| 堆叠码 | Codablock-F | CODABLOCKF | 123456 |
| 堆叠码 | Code 16K | CODE16K | 1234567890 |
| 堆叠码 | Code 49 | CODE49 | 1234567890 |
| 医疗 | HIBC Code 128 | HIBC_128 | +H12345678901 |
| 医疗 | HIBC Code 39 | HIBC_39 | +H12345 |
| 医疗 | HIBC Data Matrix | HIBC_DM | +H12345678901 |
| 医疗 | HIBC QR Code | HIBC_QR | +H12345678901 |
| 医疗 | HIBC PDF417 | HIBC_PDF | +H12345678901 |
| 医疗 | HIBC MicroPDF417 | HIBC_MICPDF | +H12345678901 |
| 医疗 | HIBC Codablock-F | HIBC_BLOCKF | +H12345678901 |
| 医疗 | HIBC Aztec | HIBC_AZTEC | +H12345678901 |
| 邮政 | USPS POSTNET | POSTNET | 123456789 |
| 邮政 | USPS PLANET | PLANET | 12345678901 |
| 邮政 | 英国皇家邮政 4SCC | RM4SCC | AB12CD |
| 邮政 | 日本邮政 | JAPANPOST | 123-4567 |
| 邮政 | 韩国邮政 | KOREAPOST | 123456 |
| 邮政 | 澳大利亚邮政 | AUSPOST | 12345678 |
| 邮政 | 澳大利亚邮政回执 | AUSREPLY | 12345678 |
| 邮政 | 澳大利亚邮政路由 | AUSROUTE | 12345678 |
| 邮政 | 澳大利亚邮政重定向 | AUSREDIRECT | 12345678 |
| 邮政 | 荷兰 KIX 邮政 | KIX | 1234AB |
| 邮政 | 德国邮政 Leitcode | DPLEIT | 1234567890123 |
| 邮政 | 德国邮政 Identcode | DPIDENT | 12345678901 |
| 邮政 | USPS 智能邮件 | USPS_IMAIL | 12345678901234567890 |
| 邮政 | Royal Mail Mailmark | MAILMARK | 12345678 |
| 工业/其他 | MSI Plessey | MSI_PLESSEY | 1234567 |
| 工业/其他 | UK Plessey | PLESSEY | 123456 |
| 工业/其他 | Telepen Alpha | TELEPEN | ABC123 |
| 工业/其他 | Telepen Numeric | TELEPEN_NUM | 123456 |
| 工业/其他 | Pharmacode 单轨 | PHARMA | 12345 |
| 工业/其他 | PZN 德国药品码 | PZN | 1234567 |
| 工业/其他 | Pharmacode 双轨 | PHARMA_TWO | 123456 |
| 工业/其他 | FIM 码 | FIM | A |
| 工业/其他 | Flattermarken | FLAT | 12345 |
| 工业/其他 | NVE-18 | NVE18 | 12345678901234567 |
| 工业/其他 | DAFT 码 | DAFT | DDAFFTTD |
| 工业/其他 | DPD 包裹码 | DPD | 0123456789012345678901234567 |
| 工业/其他 | Channel Code | CHANNEL | 12345 |
| 工业/其他 | 标准 2 of 5 | C25STANDARD | 1234567890 |
| 工业/其他 | 交叉 2 of 5 | C25INTER | 1234567890 |
| 工业/其他 | IATA 2 of 5 | C25IATA | 1234567890 |
| 工业/其他 | Data Logic 2 of 5 | C25LOGIC | 1234567890 |
| 工业/其他 | 工业 2 of 5 | C25IND | 1234567890 |
| 工业/其他 | Code 32 意大利药品码 | CODE32 | 1234567890 |
使用中遇到问题请联系qiannao@qq.com。