This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
yoshop/source/application/common/library/printer/engine/PrintCenter.php

55 lines
1.4 KiB
PHP
Raw Normal View History

2020-04-25 22:20:29 +08:00
<?php
namespace app\common\library\printer\engine;
2020-08-28 10:38:52 +08:00
use app\common\library\helper;
2020-04-25 22:20:29 +08:00
2020-08-28 10:38:52 +08:00
/**
* 365云打印引擎
* Class PrintCenter
* @package app\common\library\printer\engine
*/
2020-04-25 22:20:29 +08:00
class PrintCenter extends Basics
{
/** @const API地址 */
const API = 'http://open.printcenter.cn:8080/addOrder';
/**
* 执行订单打印
* @param $content
* @return bool|mixed
*/
public function printTicket($content)
{
// 构建请求参数
$context = stream_context_create([
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded ",
'method' => 'POST',
'content' => http_build_query([
'deviceNo' => $this->config['deviceNo'],
'key' => $this->config['key'],
'printContent' => $content,
'times' => $this->times
]),
]
]);
// API请求开始打印
$result = file_get_contents(self::API, false, $context);
// 处理返回结果
2020-08-28 10:38:52 +08:00
$result = helper::jsonDecode($result);
// 记录日志
log_write([
'describe' => 'PrintCenter(365) PrintTicket',
'result' => $result
]);
2020-04-25 22:20:29 +08:00
// 返回状态
2020-08-28 10:38:52 +08:00
if ($result['responseCode'] != 0) {
$this->error = $result['msg'];
2020-04-25 22:20:29 +08:00
return false;
}
return true;
}
2020-08-28 10:38:52 +08:00
}