From 14584d9171fb4225926d7a8bda36e2571c37ee65 Mon Sep 17 00:00:00 2001
From: suyl <770236076@qq.com>
Date: Wed, 30 Jun 2021 15:40:37 +0800
Subject: [PATCH] test qr
---
business/jxstore/event/event_tcp.go | 95 +++++++++++++++++------------
1 file changed, 55 insertions(+), 40 deletions(-)
diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go
index 4409e45ba..04c2544b1 100644
--- a/business/jxstore/event/event_tcp.go
+++ b/business/jxstore/event/event_tcp.go
@@ -9,7 +9,6 @@ import (
"git.rosy.net.cn/jx-callback/globals"
"io"
"net"
- "regexp"
"strconv"
"strings"
"sync"
@@ -38,36 +37,50 @@ const (
//标签
const (
- signBR = "
" //换行
- signCenter = "
" //居中
- signLeft = "" //居左
- signRight = "" //居右
- signBig = "" //字体放大
- signHighBig = "" //字体纵向放大
- signWideBig = "" //字体横向放大
+ signBR = "
" //换行
+ signCenter = "" //居中
+ signLeft = "" //居左
+ signRight = "" //居右
+ signBig = "" //字体放大
+ signHighBig = "" //字体纵向放大
+ signWideBig = "" //字体横向放大
+ signQrCenter = "" //二维码居中
+ signQrLeft = "" //二维码居左
+ signQrRight = "" //二维码居右
- hexSignCenter = "1b6101"
- hexSignLeft = "1b6100"
- hexSignRight = "1b6102"
- hexSignNormal = "1b2100"
- hexSignBig = "1b2130"
- hexSignHighBig = "1b2110"
- hexSignWideBig = "1b2120"
+ hexSignCenter = "1b6101"
+ hexSignLeft = "1b6100"
+ hexSignRight = "1b6102"
+ hexSignNormal = "1b2100"
+ hexSignBig = "1b2130"
+ hexSignHighBig = "1b2110"
+ hexSignWideBig = "1b2120"
+ hexSignQrCenter = "1d5802"
+ hexSignQrLeft = "1d5800"
+ hexSignQrRight = "1d5804"
+ hexSignQr = "1b5a0001061600"
+ hexSignQrEnd = "6100"
- byteSignBR = "3c62723e" //换行
- byteSignCenter = "3c63656e7465723e" //居中
- byteSignLeft = "3c6c6566743e" //居左
- byteSignRight = "3c72696768743e" //居右
- byteSignBig = "3c623e" //字体放大
- byteSignHighBig = "3c68623e" //字体纵向放大
- byteSignWideBig = "3c77623e" //字体横向放大
+ byteSignBR = "3c62723e" //换行
+ byteSignCenter = "3c63656e7465723e" //居中
+ byteSignLeft = "3c6c6566743e" //居左
+ byteSignRight = "3c72696768743e" //居右
+ byteSignBig = "3c623e" //字体放大
+ byteSignHighBig = "3c68623e" //字体纵向放大
+ byteSignWideBig = "3c77623e" //字体横向放大
+ byteSignQrCenter = "3c7172633e"
+ byteSignQrLeft = "3c71726c3e"
+ byteSignQrRight = "3c7172723e"
- byteSignCenterE = "3c2f63656e7465723e" //居中
- byteSignLeftE = "3c2f6c6566743e" //居左
- byteSignRightE = "3c2f72696768743e" //居右
- byteSignBigE = "3c2f623e" //字体放大
- byteSignHighBigE = "3c2f68623e" //字体纵向放大
- byteSignWideBigE = "3c2f77623e" //字体横向放大
+ byteSignCenterE = "3c2f63656e7465723e" //居中
+ byteSignLeftE = "3c2f6c6566743e" //居左
+ byteSignRightE = "3c2f72696768743e" //居右
+ byteSignBigE = "3c2f623e" //字体放大
+ byteSignHighBigE = "3c2f68623e" //字体纵向放大
+ byteSignWideBigE = "3c2f77623e" //字体横向放大
+ byteSignQrCenterE = "3c2f7172633e"
+ byteSignQrLeftE = "3c2f71726c3e"
+ byteSignQrRightE = "3c2f7172723e"
)
var (
@@ -80,15 +93,6 @@ var (
signMap = map[string]string{
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")
)
//连接的客户端,吧每个客户端都放进来
@@ -271,16 +275,15 @@ func buildMsg(printMsg *model.PrintMsg) (data []byte, err error) {
voice = "1b59415501" //语音响一次
check = "ff"
orderNoHexH, orderNoHexL, printData string
- qr = "1D58021b5a000106160068747470733a2f2f7777772e62616964752e636f6d2f1b6100"
)
//写入数据
orderNoHexH, orderNoHexL = int2h8l8(int64(orderNo))
printDataGBK, _ := jxutils.Utf8ToGbk([]byte(content))
printData = hex.EncodeToString(printDataGBK)
printData = replaceContent(printData)
- lenData := int64(len(str) + len(const1) + len(orderNoHexH) + len(orderNoHexL) + len(printInit) + len(voice) + len(check) + 4 + len(printData) + len(qr))
+ 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 + qr + check
+ dataStr := str + x1 + x2 + const1 + orderNoHexH + orderNoHexL + printInit + voice + printData + check
return jxutils.Hextob(dataStr), err
}
@@ -316,6 +319,18 @@ func replaceContent(content string) (result string) {
result = strings.ReplaceAll(result, byteSignWideBig, hexSignWideBig)
result = strings.ReplaceAll(result, byteSignWideBigE, hexSignNormal)
}
+ if strings.Contains(result, byteSignQrCenter) && strings.Contains(result, byteSignQrCenterE) {
+ result = strings.ReplaceAll(result, byteSignQrCenter, hexSignQrCenter+hexSignQr)
+ result = strings.ReplaceAll(result, byteSignQrCenterE, hexSignQrEnd)
+ }
+ if strings.Contains(result, byteSignQrLeft) && strings.Contains(result, byteSignQrLeftE) {
+ result = strings.ReplaceAll(result, byteSignQrLeft, hexSignQrLeft+hexSignQr)
+ result = strings.ReplaceAll(result, byteSignQrLeftE, hexSignQrEnd)
+ }
+ if strings.Contains(result, byteSignQrRight) && strings.Contains(result, byteSignQrRightE) {
+ result = strings.ReplaceAll(result, byteSignQrRight, hexSignQrRight+hexSignQr)
+ result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd)
+ }
return result
}