KdtConfig.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @link:http://www.gdqijianshi.com/
  4. * @copyright: Copyright (c) 2020 广东七件事集团
  5. * Created by PhpStorm
  6. * Author: zal
  7. * Date: 2020-04-01
  8. * Time: 21:49
  9. */
  10. namespace common\helpers\printer\config;
  11. class KdtConfig extends BaseConfig
  12. {
  13. public $name; // 打印机编号
  14. public $key; // 打印机密钥
  15. public $time; // 打印联数
  16. private $url = "http://open.printcenter.cn:8080/addOrder";
  17. public function print($content)
  18. {
  19. date_default_timezone_set("Asia/Shanghai");
  20. header("Content-Type: text/html;charset=utf-8");
  21. $selfMessage = array(
  22. 'deviceNo' => $this->name,
  23. 'printContent' => $content,
  24. 'key' => $this->key,
  25. 'times' => $this->time
  26. );
  27. $options = array(
  28. 'http' => array(
  29. 'header' => "Content-type: application/x-www-form-urlencoded ",
  30. 'method' => 'POST',
  31. 'content' => http_build_query($selfMessage),
  32. ),
  33. );
  34. $context = stream_context_create($options);
  35. $result = file_get_contents($this->url, false, $context);
  36. $result = json_decode($result, true);
  37. if ($result['responseCode'] != 0) {
  38. throw new \Exception($result['msg'], $result, 1);
  39. }
  40. return $result;
  41. }
  42. }