# ipp-server **Repository Path**: FEIGE/ipp-server ## Basic Information - **Project Name**: ipp-server - **Description**: php ipp server - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-19 - **Last Updated**: 2026-06-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # IPP Virtual Printer Server 基于 PHP Workerman 的 IPP (Internet Printing Protocol) 虚拟打印服务器,支持 Windows 客户端通过标准 IPP 协议进行打印。 **协议标准**:RFC 8010 (IPP Encodings) / RFC 8011 (IPP Model and Semantics) **HTTP 层**:使用 Workerman 内置 HTTP 协议(`Workerman\Protocols\Http`),自动处理请求解析、Content-Length 缓冲、keep-alive ## 功能特性 - **IPP 2.0 协议**:完整的 Get-Printer-Attributes、Validate-Job、Create-Job、Send-Document、Get-Job-Attributes、Cancel-Job、Get-Jobs 操作 - **Windows 兼容**:响应格式严格对标 CUPS 2.4 IPP 实现,已通过 Windows 10/11 IPP 驱动验证 - **多打印机**:默认 80mm、58mm 热敏打印机 + A4 PDF 打印机 - **ESC/POS 转换**:自动将打印数据转换为 ESC/POS 指令 - **Collection 属性**:完整支持 media-col-default、media-col-database、media-col-ready - **Web 状态页**:浏览器访问可查看打印机状态 ## 环境要求 - PHP >= 8.1 - PHP 扩展:pcntl, posix, mbstring - Workerman >= 4.1 - Composer ## 安装 ```bash composer install ``` ## 启动 ```bash # 前台启动(调试) php start.php start # 后台守护进程 php start.php start -d # 停止 php start.php stop # 重启 php start.php restart ``` ## Windows 添加打印机 1. 设置 → 蓝牙和设备 → 打印机和扫描仪 → 添加设备 2. 选择「我所需的打印机未列出」→「按IP地址或者主机名添加打印机」 3. 输入:`http://服务器IP:8631/ipp/print` 4. 驱动:`Generic / Text Only` 或 `Microsoft IPP Class Driver` ## 项目结构 ``` ipp-server/ ├── composer.json # Composer 配置 ├── start.php # Workerman HTTP 服务器启动入口 ├── src/ │ ├── Handler/ │ │ ├── IPPHandler.php # IPP 操作处理器(请求分发、属性构建、过滤) │ │ └── WebHandler.php # Web 状态页处理器 │ ├── Model/ │ │ ├── Printer.php # 打印机模型(状态、作业队列) │ │ └── Job.php # 打印作业模型 │ ├── Printer/ │ │ └── ESCPOS.php # ESC/POS 指令生成器 │ └── Protocol/ │ └── IPP.php # IPP 协议编解码器(RFC 8010/8011) ├── tests/ │ ├── test-compare.php # 8631 vs 631 响应对比测试 │ ├── test-windows-print.php # Windows 打印流程测试 │ ├── decode-ipp.php # IPP 二进制解码工具 │ ├── decode-cups.php # CUPS 流量解码工具 │ ├── decode_compare.php # 解码对比工具 │ ├── 631PK8631.md # CUPS 与 PHP 响应对比分析 │ ├── cups_631_analysis.md # CUPS 631 数据详细分析 │ └── cups-flow.txt # CUPS 完整 IPP 交互流程 ├── examples/ │ └── print_example.php # ESC/POS 使用示例 ├── data/ # 运行时数据目录 ├── state/ # 状态文件目录 └── print_jobs/ # 打印作业输出目录 ``` ## IPP 协议支持 ### 支持的操作码 | 操作码 | 操作名称 | 说明 | |--------|---------|------| | 0x0002 | Print-Job | 提交打印任务 | | 0x0004 | Validate-Job | 验证任务参数 | | 0x0005 | Create-Job | 创建打印作业 | | 0x0006 | Send-Document | 发送打印文档 | | 0x0008 | Cancel-Job | 取消打印作业 | | 0x0009 | Get-Job-Attributes | 获取作业属性 | | 0x000A | Get-Jobs | 获取作业列表 | | 0x000B | Get-Printer-Attributes | 获取打印机属性 | | 0x000E | Restart-Job | 重启打印作业 | ### 打印机属性(对标 CUPS 2.4) 服务器返回的打印机属性严格对标 CUPS 实现,包括: - `printer-uri-supported` / `printer-name` / `printer-uuid` - `printer-state` / `printer-state-reasons` / `printer-is-accepting-jobs` - `document-format-supported`(34 种 MIME 类型) - `media-supported`(61 种纸张尺寸,精确匹配 CUPS 顺序) - `operations-supported`(47 个操作,精确匹配 CUPS 值) - `media-col-supported` / `media-col-default` / `media-col-database` / `media-col-ready` - `printer-resolution-supported`(150/300/600/1200/2400 dpi) - `ipp-versions-supported`(1.0, 1.1, 2.0, 2.1) - 以及所有其他 CUPS 标准属性 `Get-Printer-Attributes` 按照客户端 `requested-attributes` 过滤返回属性,与 CUPS 行为一致。 ### IPP 协议编码 服务器使用 `TAG_MEMBER_ATTR_NAME = 0x4A`(与 CUPS 一致),正确编码 collection 属性中的成员属性名。 ### HTTP 响应 使用 `Workerman\Protocols\Http\Response` 构建响应,Workerman 自动处理 HTTP 协议编码。 ```php new Response(200, ['Content-Type' => 'application/ipp', 'Content-Language' => 'en'], $ippResponse) ``` 等效 HTTP 头: ```http HTTP/1.1 200 OK Content-Type: application/ipp Content-Language: en ``` ## ESC/POS 指令参考 ### 基础方法 | 方法 | 说明 | |-----|------| | `init()` | 初始化打印机 | | `text($str)` | 打印文本 | | `textLine($str)` | 打印文本并换行 | | `lineFeed($n)` | 换行 n 次 | | `cut($partial)` | 切纸 | ### 格式控制 | 方法 | 说明 | |-----|------| | `setAlign(0/1/2)` | 对齐:0=左, 1=中, 2=右 | | `setBold(true/false)` | 粗体 | | `setUnderline(true/false)` | 下划线 | | `setReverse(true/false)` | 反转打印 | | `setFontSize($size)` | 字体大小 (0-3) | ### 布局方法 | 方法 | 说明 | |-----|------| | `title($text, $bold, $double)` | 居中标题 | | `divider($char)` | 分割线 | | `twoColumns($left, $right)` | 双列布局 | | `threeColumns($c1, $c2, $c3)` | 三列布局 | ### 特殊功能 | 方法 | 说明 | |-----|------| | `qrCode($data, $size)` | 二维码 | | `barcode($data, $type, $w, $h)` | 条形码 | | `openCashDrawer()` | 打开钱箱 | | `beep($times, $duration)` | 蜂鸣提示 | | `image($imageData)` | 打印图片 | ## 打印机配置 | 参数 | 58mm | 80mm | A4 | |-----|------|------|-----| | 纸张宽度 | 58mm | 80mm | 210mm | | 每行字符数 | ~32 | ~48 | ~80 | | 用途 | 小票、收据 | 发票、详细收据 | PDF 文档打印 | ### IPP URL | 打印机 | IPP URL | |--------|---------| | 默认 (80mm) | `http://服务器IP:8631/ipp/print` | | 58mm | `http://服务器IP:8631/ipp/print/58mm` | | 80mm | `http://服务器IP:8631/ipp/print/80mm` | | A4 | `http://服务器IP:8631/ipp/print/a4` | ## 测试 ```bash # 测试 IPP 请求 php tests/test-compare.php # 测试打印流程 php tests/test-windows-print.php ``` ## 项目文件说明 | 文件 | 说明 | |-----|------| | `start.php` | Workerman HTTP 服务器启动入口 | | `tests/test-compare.php` | 8631 vs 631 响应对比测试 | | `tests/test-windows-print.php` | Windows 打印流程测试 | | `tests/decode-ipp.php` | IPP 二进制解码工具 | | `tests/decode-cups.php` | CUPS 流量解码工具 | | `tests/decode_compare.php` | 解码对比工具 | | `tests/631PK8631.md` | CUPS 与 PHP 响应对比分析 | | `tests/cups_631_analysis.md` | CUPS 631 数据详细分析 | | `tests/cups-flow.txt` | CUPS 完整 IPP 交互流程 | ## License MIT