PrintCenter.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\common\library\printer\engine;
  3. use app\common\library\helper;
  4. /**
  5. * 365云打印引擎
  6. * Class PrintCenter
  7. * @package app\common\library\printer\engine
  8. */
  9. class PrintCenter extends Basics
  10. {
  11. /** @const API地址 */
  12. const API = 'http://open.printcenter.cn:8080/addOrder';
  13. /**
  14. * 执行订单打印
  15. * @param $content
  16. * @return bool|mixed
  17. */
  18. public function printTicket($content)
  19. {
  20. // 构建请求参数
  21. $context = stream_context_create([
  22. 'http' => [
  23. 'header' => "Content-type: application/x-www-form-urlencoded ",
  24. 'method' => 'POST',
  25. 'content' => http_build_query([
  26. 'deviceNo' => $this->config['deviceNo'],
  27. 'key' => $this->config['key'],
  28. 'printContent' => $content,
  29. 'times' => $this->times
  30. ]),
  31. ]
  32. ]);
  33. // API请求:开始打印
  34. $result = file_get_contents(self::API, false, $context);
  35. // 处理返回结果
  36. $result = helper::jsonDecode($result);
  37. // 记录日志
  38. log_write([
  39. 'describe' => 'PrintCenter(365) PrintTicket',
  40. 'result' => $result
  41. ]);
  42. // 返回状态
  43. if ($result['responseCode'] != 0) {
  44. $this->error = $result['msg'];
  45. return false;
  46. }
  47. return true;
  48. }
  49. }