初始上传

This commit is contained in:
2026-04-04 17:27:12 +08:00
parent 4d80d28eb4
commit b7e11774ee
11191 changed files with 1588469 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace addon\printer\data\sdk\yilianyun\api;
use addon\printer\data\sdk\yilianyun\config\YlyConfig;
use addon\printer\model\Printer;
use think\Exception;
class PrintService extends RpcService
{
/**
* 打印接口
*
* @param $machineCode string 机器码
* @param $content string 打印内容
* @param $originId string 商户系统内部订单号要求32个字符内只能是数字、大小写字母
* @return mixed
*/
public function index($machineCode, $content, $originId, $printer = [])
{
static $call_num = 0;
$call_num ++;
$res = $this->client->call('print/index', array ( 'machine_code' => $machineCode, 'content' => $content, 'origin_id' => $originId ));
if (is_null($res)) {
throw new Exception("invalid response.");
}
//token过期处理
if ($res->error == 18 && $printer && $call_num <= 3) {
$printer_model = new Printer();
$config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
$access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ], 1);
$res = (new self($access_token, $config))->index($machineCode, $content, $originId, $printer);
}
if (isset($res->error) && $res->error != 0) {
$errorDescription = isset($res->body) ? $res->error_description . $res->body : $res->error_description;
throw new Exception('Call method print/index error code is ' . $res->error . ' error message is ' . $errorDescription);
}
return $res;
}
}