87
tests/test_printer.php
普通文件
87
tests/test_printer.php
普通文件
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
$config = include __DIR__ . "/../application/extra/printer.php";
|
||||
|
||||
$user = $config["client_id"];
|
||||
$ukey = $config["client_secret"];
|
||||
$sn = $config["sn"];
|
||||
$url = "https://open.xprinter.com/Api/Open/";
|
||||
|
||||
echo "================ 芯烨云 (Xprinter) 小票打印测试 ================\n";
|
||||
echo "打印机SN: " . $sn . "\n";
|
||||
echo "开发者账号: " . $user . "\n";
|
||||
echo "开发者密钥: " . $ukey . "\n\n";
|
||||
|
||||
$stime = time();
|
||||
$sig = sha1($user . $ukey . $stime);
|
||||
|
||||
// 1. 查询状态
|
||||
$statusParams = [
|
||||
"user" => $user,
|
||||
"stime" => $stime,
|
||||
"sig" => $sig,
|
||||
"apiname" => "Open_queryPrinterStatus",
|
||||
"sn" => $sn
|
||||
];
|
||||
|
||||
$cookieFile = "/tmp/xprinter_cookie.txt";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($statusParams));
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
|
||||
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Cookie: _gp_pc=1"]);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
$resStatus = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
echo "1. 查询打印机在线状态返回: " . $resStatus . "\n\n";
|
||||
|
||||
// 2. 发送测试小票
|
||||
$info = "<CB>小众厨房设备商城</CB><BR>";
|
||||
$info .= "<CB>-- 联小票单 --</CB><BR>";
|
||||
$info .= "--------------------------------<BR>";
|
||||
$info .= "订单编号:TEST" . date("YmdHis") . "<BR>";
|
||||
$info .= "下单时间:" . date("Y-m-d H:i:s") . "<BR>";
|
||||
$info .= "--------------------------------<BR>";
|
||||
$info .= "商品名称 数量 单价<BR>";
|
||||
$info .= "商用切菜机(测试) 1 ¥69.00<BR>";
|
||||
$info .= "不锈钢隔热垫 2 ¥15.00<BR>";
|
||||
$info .= "--------------------------------<BR>";
|
||||
$info .= "合计金额:¥99.00 元<BR>";
|
||||
$info .= "客户姓名:测试用户<BR>";
|
||||
$info .= "联系电话:13984283762<BR>";
|
||||
$info .= "送货地址:贵州省修文县城内配送点<BR>";
|
||||
$info .= "--------------------------------<BR>";
|
||||
$info .= "<CB>谢谢惠顾,欢迎再次光临!</CB><BR><BR>";
|
||||
|
||||
$printParams = [
|
||||
"user" => $user,
|
||||
"stime" => $stime,
|
||||
"sig" => $sig,
|
||||
"apiname" => "Open_printMsg",
|
||||
"sn" => $sn,
|
||||
"content" => $info,
|
||||
"times" => 1
|
||||
];
|
||||
|
||||
$ch2 = curl_init();
|
||||
curl_setopt($ch2, CURLOPT_URL, $url);
|
||||
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch2, CURLOPT_POST, 1);
|
||||
curl_setopt($ch2, CURLOPT_POSTFIELDS, http_build_query($printParams));
|
||||
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch2, CURLOPT_COOKIEJAR, $cookieFile);
|
||||
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookieFile);
|
||||
curl_setopt($ch2, CURLOPT_HTTPHEADER, ["Cookie: _gp_pc=1"]);
|
||||
curl_setopt($ch2, CURLOPT_TIMEOUT, 10);
|
||||
$resPrint = curl_exec($ch2);
|
||||
curl_close($ch2);
|
||||
|
||||
echo "2. 发送测试订单打单指令返回: " . $resPrint . "\n";
|
||||
echo "===============================================================\n";
|
||||
|
||||
在新工单中引用
屏蔽一个用户