This commit is contained in:
suyl
2021-06-30 15:40:37 +08:00
parent 3f666ddb6b
commit 14584d9171

View File

@@ -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 = "<br>" //换行
signCenter = "<center>" //居中
signLeft = "<left>" //居左
signRight = "<right>" //居右
signBig = "<b>" //字体放大
signHighBig = "<hb>" //字体纵向放大
signWideBig = "<wb>" //字体横向放大
signBR = "<br>" //换行
signCenter = "<center>" //居中
signLeft = "<left>" //居左
signRight = "<right>" //居右
signBig = "<b>" //字体放大
signHighBig = "<hb>" //字体纵向放大
signWideBig = "<wb>" //字体横向放大
signQrCenter = "<qrc>" //二维码居中
signQrLeft = "<qrl>" //二维码居左
signQrRight = "<qrr>" //二维码居右
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
}