標籤:配置 聯絡電話 pos 狀態 host ted www 拼接 null
從飛鵝印表機官網http://www.feieyun.cn/api.php 下載對應的文檔。這裡以php為例
下載後,目錄如下:
這是官方封裝好的印表機類,沒有特殊需求,不需要去改動裡面的方法。
HttpClient.class.php
在這個檔案裡是寫調用印表機的方法,拼接需要列印的字元內容,裡面的方法,根據需要自己做相應的改動:
<?phpheader("Content-type: text/html; charset=utf-8");include ‘HttpClient.class.php‘;define(‘USER‘, ‘xxxxxxxxxxxxx‘); //*使用者填寫*:飛鵝雲後台註冊帳號define(‘UKEY‘, ‘xxxxxxxxxxxxx‘); //*使用者填寫*: 飛鵝雲註冊帳號後產生的UKEY//API URLdefine(‘IP‘,‘api.feieyun.cn‘); //介面IP或網域名稱define(‘PORT‘,80); //介面IP連接埠define(‘HOSTNAME‘,‘/Api/Open/‘); //介面路徑define(‘STIME‘, time()); //公用參數,請求時間define(‘SIG‘, sha1(USER.UKEY.STIME)); //公用參數,請求公開金鑰//==================方法1.列印訂單================== //***介面傳回值說明*** //正確例子:{"msg":"ok","ret":0,"data":"316500004_20160823165104_1853029628","serverExecutedTime":6} //錯誤:{"msg":"錯誤資訊.","ret":非零錯誤碼,"data":null,"serverExecutedTime":5} //標籤說明: //"<BR>"為分行符號 //"<CUT>"為切刀指令(主動切紙,僅限切刀印表機使用才有效果) //"<LOGO>"為列印LOGO指令(前提是預先在機器內建LOGO圖片) //"<PLUGIN>"為錢箱或者外置音響指令 //"<CB></CB>"為置中放大 //"<B></B>"為放大一倍 //"<C></C>"為置中 //"<L></L>"為字型變高一倍 //"<W></W>"為字型變寬一倍 //"<QR></QR>"為二維碼 //"<RIGHT></RIGHT>"為靠右對齊 //拼湊訂單內容時可參考如下格式 //根據列印紙張的寬度,自行調整內容的格式,可參考下面的範例格式 $orderInfo = ‘<CB>測試列印</CB><BR>‘; $orderInfo .= ‘名稱 單價 數量 金額<BR>‘; $orderInfo .= ‘--------------------------------<BR>‘; $orderInfo .= ‘飯 10.0 10 10.0<BR>‘; $orderInfo .= ‘炒飯 10.0 10 10.0<BR>‘; $orderInfo .= ‘蛋炒飯 10.0 100 100.0<BR>‘; $orderInfo .= ‘雞蛋炒飯 100.0 100 100.0<BR>‘; $orderInfo .= ‘西紅柿炒飯 1000.0 1 100.0<BR>‘; $orderInfo .= ‘西紅柿蛋炒飯 100.0 100 100.0<BR>‘; $orderInfo .= ‘西紅柿雞蛋炒飯 15.0 1 15.0<BR>‘; $orderInfo .= ‘備忘:加辣<BR>‘; $orderInfo .= ‘--------------------------------<BR>‘; $orderInfo .= ‘合計:xx.0元<BR>‘; $orderInfo .= ‘送貨地點:廣州市南沙區xx路xx號<BR>‘; $orderInfo .= ‘聯絡電話:13888888888888<BR>‘; $orderInfo .= ‘訂餐時間:2014-08-08 08:08:08<BR>‘; $orderInfo .= ‘<QR>http://www.dzist.com</QR>‘;//把二維碼字串用標籤套上即可自動產生二維碼 //開啟注釋可測試 //wp_print("印表機編號",$orderInfo,1); //===========方法2.查詢某訂單是否列印成功============= //***介面傳回值說明*** //正確例子: //已列印:{"msg":"ok","ret":0,"data":true,"serverExecutedTime":6} //未列印:{"msg":"ok","ret":0,"data":false,"serverExecutedTime":6} //開啟注釋可測試 //$orderindex = "xxxxxxxxxxxxxx";//訂單索引,從方法1傳回值中擷取 //queryOrderState($orderindex); //===========方法3.查詢指定印表機某天的訂單詳情============ //***介面傳回值說明*** //正確例子:{"msg":"ok","ret":0,"data":{"print":6,"waiting":1},"serverExecutedTime":9} //開啟注釋可測試 //$sn = "xxxxxxxxx";//印表機編號 //$date = "2016-08-27";//注意時間格式為"yyyy-MM-dd",如2016-08-27 //queryOrderInfoByDate($sn,$date); //===========方法4.查詢印表機的狀態========================== //***介面傳回值說明*** //正確例子: //{"msg":"ok","ret":0,"data":"離線","serverExecutedTime":9} //{"msg":"ok","ret":0,"data":"線上,工作狀態正常","serverExecutedTime":9} //{"msg":"ok","ret":0,"data":"線上,工作狀態不正常","serverExecutedTime":9} //開啟注釋可測試 //queryPrinterStatus("印表機編號");/* * 方法1 拼湊訂單內容時可參考如下格式 根據列印紙張的寬度,自行調整內容的格式,可參考下面的範例格式*/function wp_print($printer_sn,$orderInfo,$times){ $content = array( ‘user‘=>USER, ‘stime‘=>STIME, ‘sig‘=>SIG, ‘apiname‘=>‘Open_printMsg‘, ‘sn‘=>$printer_sn, ‘content‘=>$orderInfo, ‘times‘=>$times//列印次數 ); $client = new HttpClient(IP,PORT); if(!$client->post(HOSTNAME,$content)){ echo ‘error‘; } else{ echo $client->getContent(); } }/* * 方法2 根據訂單索引,去查詢訂單是否列印成功,訂單索引由方法1返回*/function queryOrderState($index){ $msgInfo = array( ‘user‘=>USER, ‘stime‘=>STIME, ‘sig‘=>SIG, ‘apiname‘=>‘Open_queryOrderState‘, ‘orderid‘=>$index ); $client = new HttpClient(IP,PORT); if(!$client->post(HOSTNAME,$msgInfo)){ echo ‘error‘; } else{ $result = $client->getContent(); echo $result; } }/* * 方法3 查詢指定印表機某天的訂單詳情*/function queryOrderInfoByDate($printer_sn,$date){ $msgInfo = array( ‘user‘=>USER, ‘stime‘=>STIME, ‘sig‘=>SIG, ‘apiname‘=>‘Open_queryOrderInfoByDate‘, ‘sn‘=>$printer_sn, ‘date‘=>$date ); $client = new HttpClient(IP,PORT); if(!$client->post(HOSTNAME,$msgInfo)){ echo ‘error‘; } else{ $result = $client->getContent(); echo $result; } }/* * 方法4 查詢印表機的狀態*/function queryPrinterStatus($printer_sn){ $msgInfo = array( ‘user‘=>USER, ‘stime‘=>STIME, ‘sig‘=>SIG, ‘debug‘=>‘nojson‘, ‘apiname‘=>‘Open_queryPrinterStatus‘, ‘sn‘=>$printer_sn ); $client = new HttpClient(IP,PORT); if(!$client->post(HOSTNAME,$msgInfo)){ echo ‘error‘; } else{ $result = $client->getContent(); echo $result; }}?>
上述方法裡的常量在註冊後可獲得
define(‘USER‘, ‘xxxxxxxxxxxxx‘); //*使用者填寫*:飛鵝雲後台註冊帳號
define(‘UKEY‘, ‘xxxxxxxxxxxxx‘); //*使用者填寫*: 飛鵝雲註冊帳號後產生的UKEY
如:
本文為個人原創,望能便利自己,有益他人。
飛鵝WiFi印表機配置,php調用介面