|
|
@@ -37,8 +37,19 @@ class printUtil
|
|
|
'content' => $content,
|
|
|
'times' => $this->times//打印次数
|
|
|
);
|
|
|
- $client = new \HttpClient(self::IP, self::PORT);
|
|
|
- if (!$client->post(self::PATH, $msgInfo)) {
|
|
|
+ try {
|
|
|
+ $client = new \HttpClient(self::IP, self::PORT);
|
|
|
+ $client->useGzip(false); //禁用 Gzip
|
|
|
+ $rs = $client->post(self::PATH, $msgInfo);
|
|
|
+ //服务器返回的JSON字符串,建议要当做日志记录起来
|
|
|
+ $result = $client->getContent();
|
|
|
+ //echo $result;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Yii::error('打印日志:' . $e->getMessage());
|
|
|
+ noticeUtil::push("出现打印标签,内容:{$content},原因:" . $e->getMessage(), '15280215347');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!$rs) {
|
|
|
//echo 'error';
|
|
|
} else {
|
|
|
//服务器返回的JSON字符串,建议要当做日志记录起来
|
|
|
@@ -48,6 +59,28 @@ class printUtil
|
|
|
}
|
|
|
|
|
|
public function printMsg($content, $shop = null, $orderSn = '')
|
|
|
+ {
|
|
|
+ $contentLength = strlen($content);
|
|
|
+ if ($contentLength > 5000) {
|
|
|
+ $contents = explode("<BR>", $content);
|
|
|
+ $newContent = '';
|
|
|
+ foreach ($contents as $line) {
|
|
|
+ if (strlen($newContent . $line . "<BR>") > 5000) {
|
|
|
+ $this->doPrint($newContent, $shop, $orderSn);
|
|
|
+ $newContent = $line . "<BR>";
|
|
|
+ } else {
|
|
|
+ $newContent .= $line . "<BR>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($newContent)) {
|
|
|
+ $this->doPrint($newContent, $shop, $orderSn);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->doPrint($content, $shop, $orderSn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function doPrint($content, $shop = null, $orderSn = '')
|
|
|
{
|
|
|
$time = time(); //请求时间
|
|
|
$msgInfo = array(
|
|
|
@@ -59,8 +92,16 @@ class printUtil
|
|
|
'content' => $content,
|
|
|
'times' => $this->times//打印次数
|
|
|
);
|
|
|
- $client = new \HttpClient(self::IP, self::PORT);
|
|
|
- if (!$client->post(self::PATH, $msgInfo)) {
|
|
|
+ try {
|
|
|
+ $client = new \HttpClient(self::IP, self::PORT);
|
|
|
+ $client->useGzip(false); // 禁用 Gzip
|
|
|
+ $rs = $client->post(self::PATH, $msgInfo);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Yii::error('打印日志:' . $e->getMessage());
|
|
|
+ noticeUtil::push($shop->merchantName . $shop->shopName . " 出现订单打印未成功,订单号:{$orderSn},原因:" . $e->getMessage(), '15280215347');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!$rs) {
|
|
|
//echo 'error';
|
|
|
} else {
|
|
|
//服务器返回的JSON字符串,建议要当做日志记录起来
|