FeiEYun.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace crmeb\services\printer\storage;
  3. use crmeb\services\printer\BasePrinter;
  4. class FeiEYun extends BasePrinter
  5. {
  6. /**
  7. * 初始化
  8. * @param array $config
  9. * @return mixed|void
  10. */
  11. protected function initialize(array $config){}
  12. /**
  13. * 开始打印
  14. * @return bool|mixed|string
  15. * @throws \Exception
  16. */
  17. public function startPrinter()
  18. {
  19. if (!$this->printerContent) {
  20. return $this->setError('Missing print');
  21. }
  22. $time = time();
  23. $request = $this->accessToken->postRequest('http://api.feieyun.cn/Api/Open/', [
  24. 'user' => $this->accessToken->feyUser,
  25. 'stime' => $time,
  26. 'sig' => sha1($this->accessToken->feyUser . $this->accessToken->feyUkey . $time),
  27. 'apiname' => 'Open_printMsg',
  28. 'sn' => $this->accessToken->feySn,
  29. 'content' => $this->printerContent,
  30. 'times' => $this->times
  31. ]);
  32. $res = json_decode($request, true);
  33. if ($res['msg'] == 'ok') {
  34. return $res;
  35. } else {
  36. return $this->setError($res['msg']);
  37. }
  38. }
  39. public function setPrinterContent($content, $times = 1): self
  40. {
  41. $this->times = $times;
  42. $this->printerContent = $content;
  43. return $this;
  44. }
  45. // /**
  46. // * 设置打印内容
  47. // * @param array $config
  48. // * @return YiLianYun
  49. // */
  50. // public function setPrinterContent(array $config): self
  51. // {
  52. // $printTime = date('Y-m-d H:i:s', time());
  53. // $product = $config['product'];
  54. // $orderInfo = $config['orderInfo'];
  55. // $orderTime = date('Y-m-d H:i:s', $orderInfo['pay_time']);
  56. // $this->printerContent = '<CB>**' . $config['name'] . '**</CB><BR>';
  57. // $this->printerContent .= '--------------------------------<BR>';
  58. // $this->printerContent .= '订单编号:' . $orderInfo['order_id'] . '<BR>';
  59. // $this->printerContent .= '打印时间: ' . $printTime . '<BR>';
  60. // $this->printerContent .= '付款时间: ' . $orderTime . '<BR>';
  61. // $this->printerContent .= '姓 名: ' . $orderInfo['real_name'] . '<BR>';
  62. // $this->printerContent .= '电 话: ' . $orderInfo['user_phone'] . '<BR>';
  63. // $this->printerContent .= '地 址: ' . $orderInfo['user_address'] . '<BR>';
  64. // $this->printerContent .= '赠送积分: ' . $orderInfo['gain_integral'] . '<BR>';
  65. // $this->printerContent .= '订单备注:' . $orderInfo['mark'] . '<BR>';
  66. // $this->printerContent .= '**************商品**************<BR>';
  67. // $this->printerContent .= '名称 单价 数量 金额<BR>';
  68. // $this->printerContent .= '--------------------------------<BR>';
  69. // foreach ($product as $item) {
  70. // $name = $item['productInfo']['store_name'] . " | " . $item['productInfo']['attrInfo']['suk'];
  71. // $price = $item['truePrice'];
  72. // $num = $item['cart_num'];
  73. // $prices = bcmul((string)$item['cart_num'], (string)$item['truePrice'], 2);
  74. // $kw3 = '';
  75. // $kw1 = '';
  76. // $kw2 = '';
  77. // $kw4 = '';
  78. // $str = $name;
  79. // $blankNum = 14;//名称控制为14个字节
  80. // $lan = mb_strlen($str, 'utf-8');
  81. // $m = 0;
  82. // $j = 1;
  83. // $blankNum++;
  84. // $result = array();
  85. // if (strlen($price) < 6) {
  86. // $k1 = 6 - strlen($price);
  87. // for ($q = 0; $q < $k1; $q++) {
  88. // $kw1 .= ' ';
  89. // }
  90. // $price = $price . $kw1;
  91. // }
  92. // if (strlen($num) < 3) {
  93. // $k2 = 3 - strlen($num);
  94. // for ($q = 0; $q < $k2; $q++) {
  95. // $kw2 .= ' ';
  96. // }
  97. // $num = $num . $kw2;
  98. // }
  99. // if (strlen($prices) < 6) {
  100. // $k3 = 6 - strlen($prices);
  101. // for ($q = 0; $q < $k3; $q++) {
  102. // $kw4 .= ' ';
  103. // }
  104. // $prices = $prices . $kw4;
  105. // }
  106. // for ($i = 0; $i < $lan; $i++) {
  107. // $new = mb_substr($str, $m, $j, 'utf-8');
  108. // $j++;
  109. // if (mb_strwidth($new, 'utf-8') < $blankNum) {
  110. // if ($m + $j > $lan) {
  111. // $m = $m + $j;
  112. // $tail = $new;
  113. // $lenght = iconv("UTF-8", "GBK//IGNORE", $new);
  114. // $k = 14 - strlen($lenght);
  115. // for ($q = 0; $q < $k; $q++) {
  116. // $kw3 .= ' ';
  117. // }
  118. // if ($m == $j) {
  119. // $tail .= $kw3 . ' ' . $price . ' ' . $num . ' ' . $prices;
  120. // } else {
  121. // $tail .= $kw3 . '<BR>';
  122. // }
  123. // break;
  124. // } else {
  125. // $next_new = mb_substr($str, $m, $j, 'utf-8');
  126. // if (mb_strwidth($next_new, 'utf-8') < $blankNum) {
  127. // continue;
  128. // } else {
  129. // $m = $i + 1;
  130. // $result[] = $new;
  131. // $j = 1;
  132. // }
  133. // }
  134. // }
  135. // }
  136. // $head = '';
  137. // foreach ($result as $key => $value) {
  138. // if ($key < 1) {
  139. // $v_lenght = iconv("UTF-8", "GBK//IGNORE", $value);
  140. // $v_lenght = strlen($v_lenght);
  141. // if ($v_lenght == 13) $value = $value . " ";
  142. // $head .= $value . ' ' . $price . ' ' . $num . ' ' . $prices;
  143. // } else {
  144. // $head .= $value . '<BR>';
  145. // }
  146. // }
  147. // $this->printerContent .= $head . $tail;
  148. // unset($price);
  149. // }
  150. // $this->printerContent .= '--------------------------------<BR>';
  151. // $this->printerContent .= '合计:' . number_format($orderInfo['total_price'], 2) . '元<BR>';
  152. // $this->printerContent .= '邮费:' . number_format($orderInfo['pay_postage'], 2) . '元<BR>';
  153. // $this->printerContent .= '优惠:' . number_format($orderInfo['coupon_price'], 2) . '元<BR>';
  154. // $this->printerContent .= '抵扣:' . number_format($orderInfo['deduction_price'], 2) . '元<BR>';
  155. // $this->printerContent .= '实际支付:' . number_format($orderInfo['pay_price'], 2) . '元<BR>';
  156. // $this->printerContent .= '<QR>' . $config['url'] . '</QR>';//把解析后的二维码生成的字符串用标签套上即可自动生成二维码
  157. // return $this;
  158. // }
  159. }