API开发文档329

接口1:打印内容(支持S1、S2、USB三种小票机)
参数 说明
deviceNo 打印机编号
key 密钥
printContent 打印内容
times 打印联数(同一订单,打印的次数,只对S2小票机有效,S1小票机和USB小票机使用打印机命令完成打印联数的设定)
调用方式:HTTP POST
URL:http://open.printcenter.cn:8080/addOrder
返回结果:JSON字符串
注释:服务器接收订单成功不等同于打印成功
----------S2小票机返回的结果有如下几种:---------- {"responseCode":0,"msg":"服务器接收订单成功","orderindex":"xxxxxxxxxxxxxxxxxx"} {"responseCode":1,"msg":"打印机编号错误"} {"responseCode":2,"msg":"服务器处理订单失败"} {"responseCode":3,"msg":"打印内容太长"} {"responseCode":4,"msg":"请求参数错误"} {"responseCode":4,"msg":"错误的机器号或口令"}




接口2:查询订单是否打印成功(支持S1、S2两种小票机)
参数 说明
deviceNo 打印机编号
key 密钥
orderindex 订单索引(orderindex,该值由接口一返回)
调用方式:HTTP POST
URL:http://open.printcenter.cn:8080/queryOrder
返回结果:JSON字符串
----------S2小票机返回的结果有如下几种:---------- {"responseCode":0,"msg":"已打印"} {"responseCode":0,"msg":"未打印"} {"responseCode":1,"msg":"请求参数错误"} {"responseCode":2,"msg":"没有找到该索引的订单"} {"responseCode":4,"msg":"错误的机器号或口令"}




接口3:查询打印机的状态(支持S1、S2两种小票机)
参数 说明
deviceNo 打印机编号
key 打印密钥
调用方式:HTTP POST
URL:http://open.printcenter.cn:8080/queryPrinterStatus
返回结果:JSON字符串
注释:打印机离线状态在打印机异常状态90秒之后可被检测到。
----------S2小票机返回的结果有如下几种:---------- {"responseCode":0,"msg":"离线"} {"responseCode":0,"msg":"在线,纸张正常"} {"responseCode":0,"msg":"在线,缺纸"} {"responseCode":1,"msg":"请求参数错误"} {"responseCode":4,"msg":"错误的机器号或口令"}



代码示例

<?php
header("Content-Type: text/html;charset=utf-8");
$DEVICE_NO = '815501988';
$key = '72264';
$content = "";
$content .= "<CB>测试打印</CB><BR>";
$content .= "名称      单价  数量 金额
"; $content .= "--------------------------------<BR>"; $content .= "饭       1.0 1 1.0<BR>"; $content .= "炒饭      10.0 10 10.0<BR>"; $content .= "蛋炒饭     10.0 10 100.0<BR>"; $content .= "鸡蛋炒饭    100.0 1 100.0<BR>"; $content .= "番茄蛋炒饭   1000.0 1 100.0<BR>"; $content .= "西红柿蛋炒饭  1000.0 1 100.0<BR>"; $content .= "西红柿鸡蛋炒饭 100.0 10 100.0<BR>"; $content .= "备注:加辣<BR>"; $content .= "--------------------------------<BR>"; $content .= "合计:xx.0元<BR>"; $content .= "送货地点:北京市海淀区xx路xx号<BR>"; $content .= "联系电话:15999999988888<BR>"; $content .= "订餐时间:2015-09-09 09:08:08<BR>"; $content .= "<QR>http://open.printcenter.cn</QR><BR>"; $result = sendSelfFormatOrderInfo($DEVICE_NO, $key, 1,$content); var_dump($result); function sendSelfFormatOrderInfo($device_no,$key,$times,$orderInfo){ // $times打印次数 $selfMessage = array( 'deviceNo'=>$device_no, 'printContent'=>$orderInfo, 'key'=>$key, 'times'=>$times ); $url = "http://open.printcenter.cn:8080/addOrder"; $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded ", 'method' => 'POST', 'content' => http_build_query($selfMessage), ), ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; } ?>


打印机基本指令

点我查看打印机指令