标签替换测试

This commit is contained in:
suyl
2021-06-30 13:50:39 +08:00
parent c80f85e43a
commit 83ae819b1a

View File

@@ -9,6 +9,7 @@ import (
"git.rosy.net.cn/jx-callback/globals"
"io"
"net"
"regexp"
"strconv"
"strings"
"sync"
@@ -37,15 +38,6 @@ const (
//标签
const (
//<BR> :换行符
//<CB></CB>:居中放大
//<B></B>:放大一倍
//<C></C>:居中
//<L></L>:字体变高一倍
//<W></W>:字体变宽一倍
//<QR></QR>:二维码(单个订单,最多只能打印一个二维码)
//<RIGHT></RIGHT>:右对齐
//<BOLD></BOLD>:字体加粗
signBR = "<br>" //换行
signCenter = "<center>" //居中
signLeft = "<left>" //居左
@@ -54,6 +46,14 @@ const (
signHighBig = "<hb>" //字体纵向放大
signWideBig = "<wb>" //字体横向放大
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
}