wuyj/php-json-escpos
Composer 安装命令:
composer require wuyj/php-json-escpos
包简介
ESC/POS Printer JSON Template Parser for PHP.
README 文档
README
Based on mike42/escpos-php project, works properly on x-printer 80mm.
English | 简体中文
Quick Start
Include the library
composer require wuyj/php-json-escpos
Examples
<?php require __DIR__ . '/vendor/autoload.php'; use Wuyj\Escpos\EscposPrinter; $printer = new EscposPrinter(); /** Print receipts. **/ $json = '[{"styles":"alignCenter;fontBold;fontSize:2,2","text":["TITLE TITLE TITLE","","标题标题标题标题",""]},{"styles":"fontSize:1,1","text":["订单号: ${order_sn}"]},{"styles":"fontSize:1,1","text":["订单时间: ${add_time}"]},{"styles":"alignSide:12,12","text":["座位号: ${table_sn}","用餐人数: ${cover}"]},{"styles":"hidden:hide_refund_text","text":["原因:${refund_reason}"]},{"styles":"strRepeat","text":["-"]},{"styles":"each:foods;alignSide:17,-2,-5","text":[{"styles":"","text":[["${item_name_en}","${item_quantity}","${item_price}"],["${item_name_zh}","",""]]},{"styles":"each:specs_items","text":[["* ${item_attr_en} ${item_attr}","",""]]},{"styles":"hidden:hide_remark","text":["* ${remark}","",""]}]},{"styles":"strRepeat","text":["-"]},{"styles":"alignSide:-14,-10;fontSize:1,1","text":["小计:","${sub_total}"]},{"styles":"alignSide:-14,-10;fontSize:1,1","text":["折扣:","${discount}"]},{"styles":"alignSide:-14,-10;fontSize:1,1;fontBold","text":["总计:","${total}"]},{"styles":"alignSide:8,8,-8;fontSize:1,1;fontBold","text":["支付方式","","金额"]},{"styles":"each:payTypeItems;alignSide:8,8,-8","text":["${pay_name}","${en_name}","${amount}"]}]'; $data = '{"order_sn":"0123456789","add_time":"2019/02/01","table_sn":"T100","cover":4,"refund_reason":"TOO EXPENSIVE","hide_refund_text":true,"sub_total":600,"total":540,"discount":"90%","payTypeItems":[{"pay_name":"支付宝","en_name":"AliPay","amount":540}],"hide_pay_type_list":false,"foods":[{"remark":"remark test","hide_remark":true,"item_name_en":"foods","item_quantity":2,"item_price":100.00,"item_name_zh":"食物","specs_items":[]},{"remark":"remark test","hide_remark":false,"item_name_en":"juice","item_quantity":2,"item_price":200.00,"item_name_zh":"饮料","specs_items":[{"item_attr_en":"No Ice","item_attr":"不加冰"},{"item_attr_en":"No Sugar","item_attr":"不加糖"}]}]}'; $printer->render($json, json_encode($data, true)); $printer->connect('10.10.10.201'); $printer->printing(); /** Open cashier drawer. **/ $printer->connect('10.10.10.201'); $printer->pulse(); /** Detect printer device status. **/ $printer->connect('10.10.10.201'); $status = $printer->detect(); switch ($status) { case 1: echo 'OK'; $printer->close(); break; case -1: echo 'Not Connected'; break; case 0x20: echo 'BTN PRESSED'; break; case 0x08: echo 'BTN PRESSED'; break; case 0x64: echo 'HARDWARE ERROR'; break; }
Supported styles
underLine
- add underline for text
qrCode
- print qrCode
actionCut
- cut receipts paper
actionFeed
- actionFeed: 1 (feed 1 line)
- feed paper
fontSize
- fontSize: width, height
- FONT_A: 1, 2, 3
- FONT_B: 1.5
alignSide
- alignSide: 8, 8, -8 (print text as table, total 3 columns, each column will display 8 cell, -8 means align text by right, default to align text to left)
- 24 for FONT_A, 32 for FONT_B
strRepeat
- strRepeat (default char
_will be repeated 48 times)
alignLeft
alignRight
alignCenter
fontBold
lineBreak
actionText
Supported directives
each
- each: data_items (loop
data_itemsto print text line)
hidden
- hidden: hidden_value (hidden text line if hidden_value is true)
repeat
- repeat: repeat_times (repeat the specified line with
repeat_timestimes)
wuyj/php-json-escpos 适用场景与选型建议
wuyj/php-json-escpos 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 44 次下载、GitHub Stars 达 6, 最近一次更新时间为 2019 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「template」 「ESC-POS」 「printer」 「receipts」 「escpos」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wuyj/php-json-escpos 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wuyj/php-json-escpos 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wuyj/php-json-escpos 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHPUnit result printer, variant of the TestDoxCli Printer, that reduces the test failure message size for better readability
zhongwu cloud printer api
Printing package for Nette framework
Simple ASCII output of array data
A presentable result printer for PHPUnit
The package allows you to print GraphQL Schema and Queries in a highly customized way eg you can choose indent size, print only used/wanted/all types, print only one type, print used/wanted/all directives and even check which types/directives are used in the Schema/Query.
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-19