From 83ae819b1af83df09eb8fb47f952824fac2e87a9 Mon Sep 17 00:00:00 2001
From: suyl <770236076@qq.com>
Date: Wed, 30 Jun 2021 13:50:39 +0800
Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=9B=BF=E6=8D=A2=E6=B5=8B?=
=?UTF-8?q?=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
business/jxstore/event/event_tcp.go | 67 +++++++++++++++++++++--------
1 file changed, 50 insertions(+), 17 deletions(-)
diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go
index c62b3a92f..b53aedfe6 100644
--- a/business/jxstore/event/event_tcp.go
+++ b/business/jxstore/event/event_tcp.go
@@ -9,6 +9,7 @@ import (
"git.rosy.net.cn/jx-callback/globals"
"io"
"net"
+ "regexp"
"strconv"
"strings"
"sync"
@@ -37,15 +38,6 @@ const (
//标签
const (
- //
:换行符
- //:居中放大
- //:放大一倍
- //:居中
- //:字体变高一倍
- //:字体变宽一倍
- //:二维码(单个订单,最多只能打印一个二维码)
- //:右对齐
- //:字体加粗
signBR = "
" //换行
signCenter = "
" //居中
signLeft = "" //居左
@@ -54,6 +46,14 @@ const (
signHighBig = "" //字体纵向放大
signWideBig = "" //字体横向放大
+ hexSignCenter = "1b6101"
+ hexSignLeft = "1b6100"
+ hexSignRight = "1b6102"
+ hexSignNormal = "1b2100"
+ hexSignBig = "1b2130"
+ hexSignHighBig = "1b2110"
+ hexSignWideBig = "1b2120"
+
byteSignBR = "3c62723e" //换行
byteSignCenter = "3c63656e7465723e" //居中
byteSignLeft = "3c6c6566743e" //居左
@@ -61,6 +61,13 @@ const (
byteSignBig = "3c623e" //字体放大
byteSignHighBig = "3c68623e" //字体纵向放大
byteSignWideBig = "3c77623e" //字体横向放大
+
+ byteSignCenterE = "3c2f63656e7465723e" //居中
+ byteSignLeftE = "3c2f6c6566743e" //居左
+ byteSignRightE = "3c2f72696768743e" //居右
+ byteSignBigE = "3c2f623e" //字体放大
+ byteSignHighBigE = "3c2f68623e" //字体纵向放大
+ byteSignWideBigE = "3c2f77623e" //字体横向放大
)
var (
@@ -71,14 +78,17 @@ var (
}
signMap = map[string]string{
- byteSignBR: "0a",
- byteSignCenter: "1b6101",
- byteSignLeft: "1b6100",
- byteSignRight: "1b6102",
- byteSignBig: "1b2130",
- byteSignHighBig: "1b2110",
- byteSignWideBig: "1b2120",
+ byteSignBR: "0a",
}
+
+ signMapByte = map[string]string{}
+
+ regxpCenter = regexp.MustCompile("3c63656e7465723e(.*?)3c2f63656e7465723e")
+ regxpLeft = regexp.MustCompile("3c6c6566743e(.*?)3c2f6c6566743e")
+ regxpRight = regexp.MustCompile("3c72696768743e(.*?)3c2f72696768743e")
+ regxpBig = regexp.MustCompile("3c623e(.*?)3c2f623e")
+ regxpHighBig = regexp.MustCompile("3c68623e(.*?)3c2f68623e")
+ regxpWideBig = regexp.MustCompile("3c77623e(.*?)3c2f77623e")
)
//连接的客户端,吧每个客户端都放进来
@@ -267,7 +277,6 @@ func buildMsg(printMsg *model.PrintMsg) (data []byte, err error) {
printDataGBK, _ := jxutils.Utf8ToGbk([]byte(content))
printData = hex.EncodeToString(printDataGBK)
printData = replaceContent(printData)
- fmt.Println("printdata:111111111111", printData)
lenData := int64(len(str) + len(const1) + len(orderNoHexH) + len(orderNoHexL) + len(printInit) + len(voice) + len(check) + 4 + len(printData))
x1, x2 := int2h8l8(lenData / 2)
dataStr := str + x1 + x2 + const1 + orderNoHexH + orderNoHexL + printInit + voice + printData + check
@@ -282,6 +291,30 @@ func replaceContent(content string) (result string) {
result = strings.ReplaceAll(result, k, v)
}
}
+ if strings.Contains(result, byteSignCenter) && strings.Contains(result, byteSignCenterE) {
+ result = strings.ReplaceAll(result, byteSignCenter, hexSignCenter)
+ result = strings.ReplaceAll(result, byteSignCenterE, hexSignLeft)
+ }
+ if strings.Contains(result, byteSignLeft) && strings.Contains(result, byteSignLeftE) {
+ result = strings.ReplaceAll(result, byteSignLeft, hexSignLeft)
+ result = strings.ReplaceAll(result, byteSignLeftE, hexSignLeft)
+ }
+ if strings.Contains(result, byteSignRight) && strings.Contains(result, byteSignRightE) {
+ result = strings.ReplaceAll(result, byteSignRight, hexSignRight)
+ result = strings.ReplaceAll(result, byteSignRightE, hexSignLeft)
+ }
+ if strings.Contains(result, byteSignBig) && strings.Contains(result, byteSignBigE) {
+ result = strings.ReplaceAll(result, byteSignBig, hexSignBig)
+ result = strings.ReplaceAll(result, byteSignBigE, hexSignNormal)
+ }
+ if strings.Contains(result, byteSignHighBig) && strings.Contains(result, byteSignHighBigE) {
+ result = strings.ReplaceAll(result, byteSignHighBig, hexSignHighBig)
+ result = strings.ReplaceAll(result, byteSignHighBigE, hexSignNormal)
+ }
+ if strings.Contains(result, byteSignWideBig) && strings.Contains(result, byteSignWideBigE) {
+ result = strings.ReplaceAll(result, byteSignWideBig, hexSignWideBig)
+ result = strings.ReplaceAll(result, byteSignWideBigE, hexSignNormal)
+ }
return result
}