FeieConfig.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. use common\helpers\printer\sdk\FeieYun;
  12. class FeieConfig extends BaseConfig
  13. {
  14. public $sn; // 打印机编号
  15. public $key; // 打印机密钥
  16. public $time; // 打印联数
  17. public $user; // 飞鹅云后台注册用户名
  18. public $ukey; // 飞鹅云后台登录生成的UKEY
  19. private $ip = 'api.feieyun.cn';
  20. private $path = '/Api/Open/';
  21. public function print($content)
  22. {
  23. date_default_timezone_set("Asia/Shanghai");
  24. $time = time();
  25. $content = array(
  26. 'user' => $this->user,
  27. 'stime' => $time,
  28. 'sig' => sha1($this->user . $this->ukey . $time),
  29. 'apiname' => 'Open_printMsg',
  30. 'sn' => $this->sn,
  31. 'content' => $content,
  32. 'times' => $this->time
  33. );
  34. $client = new FeieYun($this->ip, 80);
  35. if (!$client->post($this->path, $content)) {
  36. throw new \Exception($client->getError(), $client->getError(), 1);
  37. }
  38. $result = $client->getContent();
  39. $result = json_decode($result, true);
  40. if ($result['ret'] != 0) {
  41. throw new \Exception($result['msg'], $result, 1);
  42. }
  43. return $result;
  44. }
  45. }