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

微店如何自动打印发货单

微店订单同步到你的服务后打印发货单。没有微店插件,调用方式是标准的打印任务接口。调用 POST /v1/print-jobs,API Key 只放在服务端。调用 POST /v1/print-jobs,API Key 只放在服务端。

面向 需要在仓库打印机上打发货单的微店卖家

说明

微店后台可以看订单,不能驱动你仓库里的打印机。把订单同步到你自己的程序(官方推送或你定时拉取,以你当前能用的微店接口为准),生成发货单后再打印。本产品没有微店插件。打印机由门店电脑上的 Agent 主动连出,不需要公网 IP,也不需要把 9100 端口映射到互联网。

发货单 PDF 使用 content_type pdf。若你同时打热敏面单,那是另一个 printer_code 和另一种 content_type。不要在微店页面的前端脚本里放 API Key。

用微店订单号作为 Idempotency-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

    把订单拿到你的服务器

    只在服务端保存打印密钥。请求使用 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 对应仓库电脑上的队列。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

  4. 04

    处理重复通知

    相同 key 与相同 body 不会打第二张。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

  5. 05

    记录 job id

    仓库反馈没纸时,先查任务状态再补打。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

PHP

<?php
// 微店订单:发货单 PDF
$payload = [
    'printer_code' => (int) getenv('PRINTER_CODE'),
    'content_type' => 'pdf',
    'content' => base64_encode($pdf),,
    'copies' => 1,
];
$ch = curl_init('https://api.printbase.cloud/v1/print-jobs');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('PRINTBASE_API_KEY'),
        'Content-Type: application/json',
        'Idempotency-Key: ' . 'weidian-' . $orderId,
    ],
    CURLOPT_POSTFIELDS => json_encode($payload),
]);
$body = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) >= 300) {
    throw new RuntimeException($body);
}
$job = json_decode($body, true); // id, status=queued

这一套的细节

拉取还是推送

两种方式都可以,只要打印动作发生在你拿到完整订单之后。缺行项目时不要先打一张半成品。Agent 只打印你提交的内容,不会替你向平台拉取单据。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。

常见问题

有微店应用吗?(详见本页)

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

能和快递面单一起打吗?(详见本页)

可以分两个任务,分别选择打印机和文件类型。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

PDF 从微店后台下载链接能直接当 content_url 吗?

通常不行,那些链接要登录。请在服务器下载后用 base64 的 content。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

免费额度够测试吗?(详见本页)

免费套餐是一台电脑每月 100 个任务,不需要信用卡。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

相关页面

  • 有赞订单如何自动打印发货单

    有赞消息推到你的服务后,再把发货单 PDF 或小票打到门店打印机。没有 PrintBase 有赞插件。调用 POST /v1/print-jobs,API Key 只放在服务端。

  • 自建 PHP 商城如何自动打印订单小票

    在 PHP 订单支付逻辑里调用打印接口,把门店小票机打出来。不需要商城插件市场里的打印组件。调用 POST /v1/print-jobs,API Key 只放在服务端。

  • 汉印 N41 远程打印快递面单

    汉印 N41 常用来打快递面单。优先发送面单 PDF。原始指令只在你确认机内语言之后使用。调用 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