Print Relay API 文档

通用订单打印网关 — HTTP POST → 热敏打印机
生产地址: https://api.printrelay.es · TCP 客户端: printrelay.es:51902

架构 (2026-05-25): 纯中继管道 — 不做渲染,只做透传。你发 ESC/POS 就转 ESC/POS,发 PDF 就转 PDF。支持两种模式:标准模板模式(兼容 WooCommerce)和纯中转模式(_raw_escpos)。

🚀 快速开始

三步对接:

  1. 获取 API Token(注册/登录)
  2. 发送订单(POST /wc?token=xxx
  3. 打印完成

cURL 测试

# 1. 注册
curl -X POST https://api.printrelay.es/api/register \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"test123"}'

# 2. 登录
curl -X POST https://api.printrelay.es/api/login \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"test123"}'

# 3. 发送测试打印(标准模板模式)
curl -X POST "https://api.printrelay.es/wc?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"number":"9999","total":"9.99","billing":{"first_name":"Test"},"line_items":[{"name":"Test Item","quantity":1,"total":"9.99"}]}'

📡 API 参考

认证

所有 API 通过 URL 参数 ?token=xxx 认证(/api/register/api/login 除外)。

端点认证方式
/api/register无(email + password)
/api/login无(email + password)
其他 /api/*?token=TOKEN
/wc?token=TOKEN
/health

账户

注册

POST /api/register
Content-Type: application/json

{"email":"you@example.com","password":"your_password"}

→ {"success":true,"token":"tok_xxxxxxxxxxxxxxxx"}

登录

POST /api/login
Content-Type: application/json

{"email":"you@example.com","password":"your_password"}

→ {"success":true,"token":"tok_xxxxxxxxxxxxxxxx"}

控制面板

https://api.printrelay.es/panel?token=***

面板功能:添加配对(白名单 Token)· 配置路由(订单来源→目标打印机)· 测试打印 · 模板预览 · 历史记录

模板

GET /api/templates?token=TOKEN          → 模板列表
GET /api/templates/{name}?token=TOKEN  → 单个模板 JSON

🛒 标准模板模式(WooCommerce 兼容)

POST /wc?token=YOUR_TOKEN
Content-Type: application/json

请求体

{
  "number": "2676",
  "total": "56.00",
  "currency": "EUR",
  "date_created": "2026-05-16T19:06:00",
  "payment_method": "Barzahlung",
  "status": "processing",
  "customer_note": "Keine Zwiebeln bitte",
  "billing": {
    "first_name": "Lukas",
    "last_name": "Müller",
    "phone": "06802387206",
    "email": "lukas@example.com",
    "address_1": "Hauptstr. 1",
    "city": "Ziersdorf",
    "postcode": "3710",
    "country": "AT"
  },
  "line_items": [
    {"id":90,"name":"Gebr. Nudel mit Gemüse","sku":"90","quantity":1,"price":"9.90","total":"9.90"},
    {"id":55,"name":"Mini Frühlingsrolle (6 Stk.)","sku":"1a","quantity":2,"price":"3.70","total":"7.40"}
  ]
}

返回

成功:

{"status":"ok","results":[{"client":"餐厅XP80","printer":"XP-80C","ok":true}]}

客户端不在线: HTTP 503 {"error":"Client offline"}
Token 未配对: HTTP 403 {"error":"Unauthorized"}

⚡ 纯中转模式 _raw_escpos(推荐 POS 端使用)

你的 POS 系统自己生成 ESC/POS 字节流,Relay 不做任何渲染,直接透传到打印机。

POST /wc?token=YOUR_TOKEN
Content-Type: application/json

{
  "ticket_no": "T0001",
  "_raw_escpos": true,
  "ticket_b64": "<base64 编码的 ESC/POS 字节流(含裁切命令 GS V B)>"
}

数据流

你的 POS 系统 Print Relay 店内 PC python-escpos/qrcode POST ┌──────────┐ TCP ┌──────┐ → ESC/POS bytes → b64 ──────────→│ 检测 _raw │──────────────→│客户端│→ 打印机 │ 跳过渲染 │ │纯通道│ └──────────┘ └──────┘

📋 字段说明

字段类型必填说明
numberstring订单号
totalstring订单总价
currencystring货币代码 (EUR/USD)
payment_methodstring支付方式
statusstring订单状态
customer_notestring客户备注
billing.first_namestring客户名
billing.phonestring电话
line_items[].namestring菜品名
line_items[].quantityint数量
line_items[].totalstring行总价
line_items[].skustringSKU/编码