PrintCenter.php 1.3 KB

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