qr test
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -63,8 +64,8 @@ const (
|
|||||||
hexSignQrCenter = "1d5802"
|
hexSignQrCenter = "1d5802"
|
||||||
hexSignQrLeft = "1d5800"
|
hexSignQrLeft = "1d5800"
|
||||||
hexSignQrRight = "1d5804"
|
hexSignQrRight = "1d5804"
|
||||||
hexSignQr = "1b5a0001060600" //"1b5a0001061600"
|
hexSignQr = "1b5a000106" //"1b5a000106" 0600 : 后面二维码的字节数
|
||||||
hexSignQrEnd = "000a1b40" //000a0a0a1b40
|
hexSignQrEnd = "000a1b40" //000a0a0a1b40
|
||||||
|
|
||||||
byteSignBR = "3c62723e" //换行
|
byteSignBR = "3c62723e" //换行
|
||||||
byteSignCenter = "3c63656e7465723e" //居中
|
byteSignCenter = "3c63656e7465723e" //居中
|
||||||
@@ -98,6 +99,10 @@ var (
|
|||||||
signMap = map[string]string{
|
signMap = map[string]string{
|
||||||
byteSignBR: hexSignBROrEXE,
|
byteSignBR: hexSignBROrEXE,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
regexpQrc = regexp.MustCompile(byteSignQrCenter + "(.*?)" + byteSignQrCenterE)
|
||||||
|
regexpQrl = regexp.MustCompile(byteSignQrLeft + "(.*?)" + byteSignQrLeftE)
|
||||||
|
regexpQrr = regexp.MustCompile(byteSignQrRight + "(.*?)" + byteSignQrRightE)
|
||||||
)
|
)
|
||||||
|
|
||||||
type PrintInfo struct {
|
type PrintInfo struct {
|
||||||
@@ -346,6 +351,10 @@ func buildMsg(printMsg *model.PrintMsg) (data []byte, err error) {
|
|||||||
|
|
||||||
//内容中的标签替换成指令
|
//内容中的标签替换成指令
|
||||||
func replaceContent(content string) (result string) {
|
func replaceContent(content string) (result string) {
|
||||||
|
var (
|
||||||
|
lenqr int
|
||||||
|
hexLenqr string
|
||||||
|
)
|
||||||
result = content
|
result = content
|
||||||
for k, v := range signMap {
|
for k, v := range signMap {
|
||||||
if strings.Contains(result, k) {
|
if strings.Contains(result, k) {
|
||||||
@@ -377,15 +386,36 @@ func replaceContent(content string) (result string) {
|
|||||||
result = strings.ReplaceAll(result, byteSignWideBigE, hexSignBROrEXE+hexSignNormal)
|
result = strings.ReplaceAll(result, byteSignWideBigE, hexSignBROrEXE+hexSignNormal)
|
||||||
}
|
}
|
||||||
if strings.Contains(result, byteSignQrCenter) && strings.Contains(result, byteSignQrCenterE) {
|
if strings.Contains(result, byteSignQrCenter) && strings.Contains(result, byteSignQrCenterE) {
|
||||||
result = strings.ReplaceAll(result, byteSignQrCenter, hexSignQrCenter+hexSignQr)
|
if qrs := regexpQrc.FindStringSubmatch(result); len(qrs) > 0 {
|
||||||
|
lenqr = len(qrs[1])
|
||||||
|
hexLenqr = fmt.Sprintf("%x", lenqr)
|
||||||
|
if len(hexLenqr) < 2 {
|
||||||
|
hexLenqr = "0" + hexLenqr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = strings.ReplaceAll(result, byteSignQrCenter, hexSignQrCenter+hexSignQr+hexLenqr+"00")
|
||||||
result = strings.ReplaceAll(result, byteSignQrCenterE, hexSignQrEnd)
|
result = strings.ReplaceAll(result, byteSignQrCenterE, hexSignQrEnd)
|
||||||
}
|
}
|
||||||
if strings.Contains(result, byteSignQrLeft) && strings.Contains(result, byteSignQrLeftE) {
|
if strings.Contains(result, byteSignQrLeft) && strings.Contains(result, byteSignQrLeftE) {
|
||||||
result = strings.ReplaceAll(result, byteSignQrLeft, hexSignQrLeft+hexSignQr)
|
if qrs := regexpQrl.FindStringSubmatch(result); len(qrs) > 0 {
|
||||||
|
lenqr = len(qrs[1])
|
||||||
|
hexLenqr = fmt.Sprintf("%x", lenqr)
|
||||||
|
if len(hexLenqr) < 2 {
|
||||||
|
hexLenqr = "0" + hexLenqr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = strings.ReplaceAll(result, byteSignQrLeft, hexSignQrLeft+hexSignQr+hexLenqr+"00")
|
||||||
result = strings.ReplaceAll(result, byteSignQrLeftE, hexSignQrEnd)
|
result = strings.ReplaceAll(result, byteSignQrLeftE, hexSignQrEnd)
|
||||||
}
|
}
|
||||||
if strings.Contains(result, byteSignQrRight) && strings.Contains(result, byteSignQrRightE) {
|
if strings.Contains(result, byteSignQrRight) && strings.Contains(result, byteSignQrRightE) {
|
||||||
result = strings.ReplaceAll(result, byteSignQrRight, hexSignQrRight+hexSignQr)
|
if qrs := regexpQrr.FindStringSubmatch(result); len(qrs) > 0 {
|
||||||
|
lenqr = len(qrs[1])
|
||||||
|
hexLenqr = fmt.Sprintf("%x", lenqr)
|
||||||
|
if len(hexLenqr) < 2 {
|
||||||
|
hexLenqr = "0" + hexLenqr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = strings.ReplaceAll(result, byteSignQrRight, hexSignQrRight+hexSignQr+hexLenqr+"00")
|
||||||
result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd)
|
result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user