PrintCenter.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\library\printer\engine;
  13. use app\common\library\helper;
  14. /**
  15. * 365云打印引擎
  16. */
  17. class PrintCenter extends Basics
  18. {
  19. /** @const API地址 */
  20. const API = 'http://open.printcenter.cn:8080/addOrder';
  21. /**
  22. * 执行订单打印
  23. * @param string $content
  24. * @return bool
  25. */
  26. public function printTicket(string $content): bool
  27. {
  28. // 构建请求参数
  29. $context = stream_context_create([
  30. 'http' => [
  31. 'header' => "Content-type: application/x-www-form-urlencoded ",
  32. 'method' => 'POST',
  33. 'content' => http_build_query([
  34. 'deviceNo' => $this->config['deviceNo'],
  35. 'key' => $this->config['key'],
  36. 'printContent' => $content,
  37. 'times' => $this->times
  38. ]),
  39. ]
  40. ]);
  41. // API请求:开始打印
  42. $result = file_get_contents(self::API, false, $context);
  43. // 处理返回结果
  44. $result = helper::jsonDecode($result);
  45. log_record($result);
  46. // 返回状态
  47. if ($result['responseCode'] != 0) {
  48. $this->error = $result['msg'];
  49. return false;
  50. }
  51. return true;
  52. }
  53. }