PrintBase
  • Product
  • Pricing
  • Docs
  • Resources
PrintBase/专题/平台打印接入

微信小程序如何自动打印标签

小程序订单需要标签时,在服务端生成 PDF 或 ZPL/TSPL,再发给门店标签机。没有小程序打印插件。调用 POST /v1/print-jobs,API Key 只放在服务端。

面向 要在门店标签机上出货的小程序团队

说明

标签和小票不是同一台机器,也不是同一种字节。小程序里展示的商品页不能推动标签机。订单在你的服务器上变成一张标签文件之后,才调用打印接口。本产品不提供微信插件。打印机由门店电脑上的 Agent 主动连出,不需要公网 IP,也不需要把 9100 端口映射到互联网。

斑马一类机型发送 ZPL(content_type raw)。佳博等很多国产标签机实际指令是 TSPL,是否支持 ZPL 仿真要以该机型手册为准。吃不准时,生成 标签尺寸正确的 PDF,用 content_type pdf 走系统驱动,避免把 PDF 误标成 raw。

printer_code 按门店标签机填写。Idempotency-Key 用订单号加标签序号。一单多张标签是多个任务或多个 copies,不要在重试时换新的随机 key。

创建任务使用 POST /v1/print-jobs,请求头 Authorization: Bearer,正文包含 printer_code、content_type(pdf 或 raw)以及 content 或 content_url 二者之一。免费套餐是一台电脑每月 100 个任务。

创建任务使用 POST /v1/print-jobs,请求头 Authorization: Bearer,正文包含 printer_code、content_type(pdf 或 raw)以及 content 或 content_url 二者之一。免费套餐是一台电脑每月 100 个任务。

接入步骤

  1. 01

    确认标签机指令

    先在本机用厂商工具打一张。能直接发 ZPL 或 TSPL 就走 raw。只有驱动能打,就走 PDF。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

  2. 02

    在服务端生成标签

    条码内容、品名、规格放进指令或 PDF。不要把这步放在小程序前端。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

  3. 03

    按门店选择 printer_code

    从 GET /v1/printers 的 code 字段取值,存在门店配置里。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

  4. 04

    POST 任务

    raw 或 pdf 二选一。PDF 字节不能标成 raw,否则 INVALID_CONTENT。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

  5. 05

    记录任务号

    店员补打时使用新的 Idempotency-Key。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

Node.js

// 云函数:一张 ZPL 商品标签
const res = await fetch('https://api.printbase.cloud/v1/print-jobs', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.PRINTBASE_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': `label:${order.id}:1`,
  },
  body: JSON.stringify({
    printer_code: Number(process.env.PRINTER_CODE),
    content_type: 'raw',
    content: Buffer.from(zpl, 'utf8').toString('base64'),
    copies: 1,
  }),
});
if (!res.ok) throw new Error(`PrintBase ${res.status}: ${await res.text()}`);
const job = await res.json();
// { id: "job_abc", status: "queued" }

这一套的细节

尺寸写进文件里

4×6 英寸在 203 dpi 下大约是 812×1218 点。PDF 也要按标签纸尺寸生成。接口不会帮你裁切。Agent 只打印你提交的内容,不会替你向平台拉取单据。

怎样确认已经打出来

创建接口返回 id 和 status queued。之后是 queued、dispatched、printing、completed。失败原因包括 AGENT_OFFLINE、PRINTER_OFFLINE、DOWNLOAD_FAILED、PRINT_ERROR、INVALID_CONTENT。用 GET /v1/print-jobs/{id} 查询。Webhook 只在付费套餐提供,且只有 print_job.completed 和 print_job.failed。

常见问题

小程序能不能直接连标签机的网口?

顾客手机通常和标签机不在一个可控网络里。由门店 Agent 出纸。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

有官方插件吗?(详见本页)

没有。服务端调用 API。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

一单打三张一样的标签?(详见本页)

copies 大于 1 即可。单段 ZPL 且没有现成 ^PQ 时,Agent 会插入 ^PQ,让打印机自己重复。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

条码扫不出来?(详见本页)

优先让打印机指令画条码。PDF 栅格化后的细条码在热敏头上容易发糊。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

相关页面

  • 微信小程序如何自动打印小票

    小程序不能直接驱动店里的 USB 小票机。订单落到你的云函数或服务器后,再调用打印接口。没有官方小程序插件。调用 POST /v1/print-jobs,API Key 只放在服务端。

  • WMS 或 OMS 如何自动打印 SKU 条码标签

    在 WMS 复核或上架动作里把 SKU 标签打到工位打印机。没有 WMS 插件,按工位发送 printer_code。调用 POST /v1/print-jobs,API Key 只放在服务端。

  • 斑马 ZD888 远程打印 ZPL 快递面单

    把 ZPL 发到斑马 ZD888。按机身配置页上的 dpi 计算点阵。Agent 打到系统队列,不需要打印机公网 IP。调用 POST /v1/print-jobs,API Key 只放在服务端。

  • 佳博 GP-1324D 远程打印 TSPL 或 ZPL 标签

    GP-1324D 常见指令是 TSPL,部分机器可切到 ZPL。先在厂商工具里确认,再按 raw 发送。调用 POST /v1/print-jobs,API Key 只放在服务端。

免费套餐:一台电脑每月 100 个任务,不需要信用卡。

免费注册查看 API 文档
PrintBase

PrintBase connects your applications to physical printers anywhere - securely, reliably, and in real time.

Product
Receipt PrintingLabel PrintingDashboardDevicesWebhooks
Resources
DocsBlogStatusAPI ReferenceDownloadPrintBase vs PrintNodePrintNode PricingFAQ
Guides
All guidesIntegrationsPrintersCode samplesComparisonsUse casesTroubleshooting
Company
ContactSecurityPrivacy

© 2026 Aveniq Technologies OÜ. All rights reserved. PrintBase is a service of Aveniq Technologies OÜ.

PrivacyTermsRefunds