PrintCenter.php 1.2 KB

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