init: import production code mss.nahaichuan.com (exclude Runtime/Uploads/backups/logs)

这个提交包含在:
Developer
2026-10-30 10:18:50 +08:00
当前提交 1f3e0ce2f6
共有 9291 个文件被更改,包括 1776674 次插入 和 0 次删除

2
vendor/huaji-team/xpyun/.gitignore vendored 可执行文件
查看文件

@@ -0,0 +1,2 @@
.idea/
.git/

15
vendor/huaji-team/xpyun/composer.json vendored 可执行文件
查看文件

@@ -0,0 +1,15 @@
{
"name": "huaji-team/xpyun",
"authors": [
{
"name": "huaji group",
"email": "lz-850610@163.com"
}
],
"license": "MIT",
"autoload": {
"psr-4": {
"Xpyun\\": "./src"
}
}
}

查看文件

@@ -0,0 +1,9 @@
<?php
namespace Xpyun\model;
class AddPrinterRequest extends RestRequest
{
var $items;
}
?>

查看文件

@@ -0,0 +1,17 @@
<?php
namespace Xpyun\model;
class AddPrinterRequestItem
{
/**
* 打印机编号
*/
var $sn;
/**
* 打印机名称
*/
var $name;
}
?>

查看文件

@@ -0,0 +1,13 @@
<?php
namespace Xpyun\model;
class DelPrinterRequest extends RestRequest
{
/**
* 打印机编号集合
*/
var $snlist;
}
?>

查看文件

@@ -0,0 +1,45 @@
<?php
namespace Xpyun\model;
class PrintRequest extends RestRequest
{
/**
* 打印机编号
*/
var $sn;
/**
* 打印内容,不能超过5000字节
*/
var $content;
/**
* 打印份数,默认为1
*/
var $copies = 1;
/**
* 打印模式,默认为0
*/
var $mode = 0;
/**
* 支付方式41~55:支付宝 微信 ...
*/
var $payType;
/**
* 支付与否59~61:退款 到账 消费
*/
var $payMode;
/**
* 支付金额
*/
var $money;
/**
* 声音播放模式,0 为取消订单模式,1 为静音模式,2 为来单播放模式,默认为 2 来单播放模式
*/
var $voice = 2;
}
?>

查看文件

@@ -0,0 +1,13 @@
<?php
namespace Xpyun\model;
class PrinterRequest extends RestRequest
{
/**
* 打印机编号
*/
var $sn;
}
?>

查看文件

@@ -0,0 +1,13 @@
<?php
namespace Xpyun\model;
class QueryOrderStateRequest extends RestRequest
{
/**
* 订单编号
*/
var $orderId;
}
?>

查看文件

@@ -0,0 +1,18 @@
<?php
namespace Xpyun\model;
class QueryOrderStatisRequest extends RestRequest
{
/**
* 打印机编号
*/
var $sn;
/**
* 查询日期,格式YY-MM-DD,如:2016-09-20
*/
var $date;
}
?>

查看文件

@@ -0,0 +1,42 @@
<?php
namespace Xpyun\model;
use Xpyun\util\Xputil;
class RestRequest
{
/**
* 开发者ID(芯烨云后台登录账号)
*/
var $user;
/**
* 芯烨云后台开发者密钥
*/
var $userKey;
/**
* 当前UNIX时间戳,10位,精确到秒
*/
var $timestamp;
/**
* 对参数 user + UserKEY + timestamp 拼接后(+号表示连接符)进行SHA1加密得到签名,值为40位小写字符串,其中 UserKEY 为用户开发者密钥
*/
var $sign;
/**
* debug=1返回非json格式的数据。仅测试时候使用
*/
var $debug;
function __construct()
{
$this->debug = "0";
$this->timestamp = Xputil::getMillisecond();
}
public function generateSign()
{
$this->sign = Xputil::sign($this->user . $this->userKey . $this->timestamp);
}
}
?>

查看文件

@@ -0,0 +1,18 @@
<?php
namespace Xpyun\model;
class SetVoiceTypeRequest extends RestRequest
{
/**
* 打印机编号
*/
var $sn;
/**
* 声音类型: 0真人语音(大) 1真人语音(中) 2真人语音(小) 3 嘀嘀声 4 静音
*/
var $voiceType;
}
?>

查看文件

@@ -0,0 +1,17 @@
<?php
namespace Xpyun\model;
class UpdPrinterRequest extends RestRequest
{
/**
* 打印机编号
*/
var $sn;
/**
* 打印机名称
*/
var $name;
}
?>

查看文件

@@ -0,0 +1,27 @@
<?php
namespace Xpyun\model;
class VoiceRequest extends RestRequest
{
/**
* 打印机编号
*/
var $sn;
/**
* 支付方式41~55:支付宝 微信 ...
*/
var $payType;
/**
* 支付与否59~61:退款 到账 消费
*/
var $payMode;
/**
* 支付金额
*/
var $money;
}
?>

查看文件

@@ -0,0 +1,11 @@
<?php
namespace Xpyun\model;
class XPYunResp
{
var $httpStatusCode;
var $content;
}
?>

查看文件

@@ -0,0 +1,12 @@
<?php
namespace Xpyun\model;
class XPYunRespContent
{
var $code;
var $msg;
var $data;
var $serverExecutedTime;
}
?>

查看文件

@@ -0,0 +1,43 @@
<?php
/**
* 发送http的json请求
*
* @param $url 请求url
* @param $jsonStr 发送的json字符串
* @return array
*/
namespace Xpyun\service;
use Exception;
class HttpClient
{
public function http_post_json($url, $jsonStr)
{
//print($jsonStr.'<br/>');
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);// 发送一个常规的Post请求
curl_setopt($ch, CURLOPT_URL, $url);// 要访问的地址
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;charset=UTF-8',
'Content-Length: ' . strlen($jsonStr)
)
);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
throw new Exception(curl_error($ch));
}
curl_close($ch);
return array($httpCode, $response);
}
}
?>

查看文件

@@ -0,0 +1,181 @@
<?php
namespace Xpyun\service;
use Xpyun\model\XPYunResp;
class PrintService
{
private $BASE_URL = 'https://open.xpyun.net/api/openapi';
private function xpyunPostJson($url, $request)
{
$jsonRequest = json_encode($request);
$client = new HttpClient();
list($returnCode, $returnContent) = $client->http_post_json($url, $jsonRequest);
$result = new XPYunResp();
$result->httpStatusCode = $returnCode;
$result->content = json_decode($returnContent);
return $result;
}
/**
* 1.批量添加打印机
* @param restRequest
* @return
*/
public function xpYunAddPrinters($restRequest)
{
$url = $this->BASE_URL . "/xprinter/addPrinters";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 2.设置打印机语音类型
* @param restRequest
* @return
*/
public function xpYunSetVoiceType($restRequest)
{
$url = $this->BASE_URL . "/xprinter/setVoiceType";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 3.打印小票订单
* @param restRequest - 打印订单信息
* @return
*/
public function xpYunPrint($restRequest)
{
$url = $this->BASE_URL . "/xprinter/print";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 4.打印标签订单
* @param restRequest - 打印订单信息
* @return
*/
public function xpYunPrintLabel($restRequest)
{
$url = $this->BASE_URL . "/xprinter/printLabel";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 5.批量删除打印机
* @param restRequest
* @return
*/
public function xpYunDelPrinters($restRequest)
{
$url = $this->BASE_URL . "/xprinter/delPrinters";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 6.修改打印机信息
* @param restRequest
* @return
*/
public function xpYunUpdatePrinter($restRequest)
{
$url = $this->BASE_URL . "/xprinter/updPrinter";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 7.清空待打印队列
* @param restRequest
* @return
*/
public function xpYunDelPrinterQueue($restRequest)
{
$url = $this->BASE_URL . "/xprinter/delPrinterQueue";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 8.查询订单是否打印成功
* @param restRequest
* @return
*/
public function xpYunQueryOrderState($restRequest)
{
$url = $this->BASE_URL . "/xprinter/queryOrderState";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 9.查询打印机某天的订单统计数
* @param restRequest
* @return
*/
public function xpYunQueryOrderStatis($restRequest)
{
$url = $this->BASE_URL . "/xprinter/queryOrderStatis";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 10.查询打印机状态
*
* 0、离线 1、在线正常 2、在线不正常
* 备注:异常一般是无纸,离线的判断是打印机与服务器失去联系超过30秒
* @param restRequest
* @return
*/
public function xpYunQueryPrinterStatus($restRequest)
{
$url = $this->BASE_URL . "/xprinter/queryPrinterStatus";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 11.云喇叭播放语音
* @param restRequest - 播放语音信息
* @return
*/
public function xpYunPlayVoice($restRequest)
{
$url = $this->BASE_URL . "/xprinter/playVoice";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 12.POS指令
* @param restRequest
* @return
*/
public function xpYunPos($restRequest)
{
$url = $this->BASE_URL . "/xprinter/pos";
return $this->xpyunPostJson($url, $restRequest);
}
/**
* 13.钱箱控制
* @param restRequest
* @return
*/
public function xpYunControlBox($restRequest)
{
$url = $this->BASE_URL . "/xprinter/controlBox";
return $this->xpyunPostJson($url, $restRequest);
}
}
?>

18
vendor/huaji-team/xpyun/src/util/Encoding.php vendored 可执行文件
查看文件

@@ -0,0 +1,18 @@
<?php
namespace Xpyun\util;
class Encoding
{
public static function CalcGbkLenForPrint($data)
{
return iconv_strlen($data, iconv_get_encoding("internal_encoding")) * 2;
}
public static function CalcAsciiLenForPrint($data)
{
return strlen($data);
}
}
?>

查看文件

@@ -0,0 +1,64 @@
<?php
namespace Xpyun\util;
class NoteFormatter
{
private const ROW_MAX_CHAR_LEN = 32;
private const MAX_NAME_CHAR_LEN = 20;
private const LAST_ROW_MAX_NAME_CHAR_LEN = 16;
private const MAX_QUANTITY_CHAR_LEN = 6;
private const MAX_PRICE_CHAR_LEN = 6;
/**
* 格式化菜品列表(用于58mm打印机)
* 注意:默认字体排版,若是字体宽度倍大后不适用
* 58mm打印机一行可打印32个字符 汉子按照2个字符算
* 分3列: 名称20字符一般用16字符4空格填充 数量6字符 单价6字符,不足用英文空格填充 名称过长换行
*
* @param foodName 菜品名称
* @param quantity 数量
* @param price 价格
* @throws Exception
*/
public static function formatPrintOrderItem($foodName, $quantity, $price)
{
$orderNameEmpty = str_repeat(" ", self::MAX_NAME_CHAR_LEN);
$foodNameLen = Encoding::CalcGbkLenForPrint($foodName);
// print("foodNameLen=".$foodNameLen."\n");
$quantityStr = '' . $quantity;
$quantityLen = Encoding::CalcAsciiLenForPrint($quantityStr);
// print("quantityLen=".$quantityLen."\n");
$priceStr = '' . round($price, 2);
$priceLen = Encoding::CalcAsciiLenForPrint($priceStr);
// print("priceLen=".$priceLen);
$result = $foodName;
$mod = $foodNameLen % self::ROW_MAX_CHAR_LEN;
// print("mod=".$mod."\n");
if ($mod <= self::LAST_ROW_MAX_NAME_CHAR_LEN) {
// 保证各个列的宽度固定,不足部分,利用空格填充
//make sure all the column length fixed, fill with space if not enough
$result = $result . str_repeat(" ", self::MAX_NAME_CHAR_LEN - $mod);
} else {
// 另起新行
// new line
$result = $result . "<BR>";
$result = $result . $orderNameEmpty;
}
$result = $result . $quantityStr . str_repeat(" ", self::MAX_QUANTITY_CHAR_LEN - $quantityLen);
$result = $result . $priceStr . str_repeat(" ", self::MAX_PRICE_CHAR_LEN - $priceLen);
$result = $result . "<BR>";
return $result;
}
}
?>

29
vendor/huaji-team/xpyun/src/util/Xputil.php vendored 可执行文件
查看文件

@@ -0,0 +1,29 @@
<?php
namespace Xpyun\util;
class Xputil
{
/**
* 哈稀签名
* @param signSource - 源字符串
* @return
*/
public static function sign($signSource)
{
$signature = sha1($signSource);
return $signature;
}
/**
* 当前UNIX时间戳,精确到毫秒
* @return string
*/
public static function getMillisecond()
{
list($s1, $s2) = explode(' ', microtime());
return sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
}
}
?>