admin/addon/printer/data/sdk/yilianyun/api/PrintService.php

41 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace addon\printer\data\sdk\yilianyun\api;
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 = [])
{
$res = $this->client->call('print/index', array('machine_code' => $machineCode, 'content' => $content, 'origin_id' => $originId));
if (is_null($res)) {
throw new Exception("invalid response.");
}
if($res->error == 18 && $printer){
$printer_model = new Printer();
$config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
$access_token = $printer_model->getYlyToken($config, $printer[ 'site_id' ], 1);
$this->index($machineCode, $content, $originId, []);
}
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);
}
}
}