1
This commit is contained in:
@@ -41,57 +41,58 @@ const (
|
|||||||
|
|
||||||
//标签
|
//标签
|
||||||
const (
|
const (
|
||||||
signBR = "<br>" //换行
|
signBR = "<br>" //换行
|
||||||
signCenter = "<center>" //居中
|
signCenter = "<center>" //居中
|
||||||
signLeft = "<left>" //居左
|
signLeft = "<left>" //居左
|
||||||
signRight = "<right>" //居右
|
signRight = "<right>" //居右
|
||||||
signBig = "<b>" //字体放大
|
signBig = "<b>" //字体放大
|
||||||
signHighBig = "<hb>" //字体纵向放大
|
signHighBig = "<hb>" //字体纵向放大
|
||||||
signWideBig = "<wb>" //字体横向放大
|
signWideBig = "<wb>" //字体横向放大
|
||||||
signQrCenter = "<qrc>" //二维码居中
|
signQrCenter = "<qrc>" //二维码居中
|
||||||
signQrLeft = "<qrl>" //二维码居左
|
signQrLeft = "<qrl>" //二维码居左
|
||||||
signQrRight = "<qrr>" //二维码居右
|
signQrRight = "<qrr>" //二维码居右
|
||||||
signSound, signSoundEnd = "<sound>", "</sound>"
|
signSound, signSoundEnd = "<sound>", "</sound>" // 声音结束标签
|
||||||
|
|
||||||
|
// GPRS通讯说明,打印机识别二进制码
|
||||||
hexSignBROrEXE = "0a"
|
hexSignBROrEXE = "0a"
|
||||||
hexSignCenter = "1b6101"
|
hexSignCenter = "1b6101" // 居中打印
|
||||||
hexSignLeft = "1b6100"
|
hexSignLeft = "1b6100" // 恢复居左打印
|
||||||
hexSignRight = "1b6102"
|
hexSignRight = "1b6102" // 居右打印
|
||||||
hexSignNormal = "1b2100"
|
hexSignNormal = "1b2100"
|
||||||
hexSignBig = "1b2130"
|
hexSignBig = "1b2130" // 横向及纵向都放大
|
||||||
hexSignHighBig = "1b2110"
|
hexSignHighBig = "1b2110" // 倍高
|
||||||
hexSignWideBig = "1b2120"
|
hexSignWideBig = "1b2120" // 倍宽
|
||||||
hexSignQrCenter = "1d5802"
|
hexSignQrCenter = "1d5802" // 二维码居中
|
||||||
hexSignQrLeft = "1d5800"
|
hexSignQrLeft = "1d5800" // 二维码居左
|
||||||
hexSignQrRight = "1d5804"
|
hexSignQrRight = "1d5804" // 二维码居右
|
||||||
hexSignQr = "1b5a000106" //"1b5a000106" 0600 : 后面二维码的字节数
|
hexSignQr = "1b5a000106" // "1b5a000106" 0600 : 后面二维码的字节数
|
||||||
hexSignQrEnd = "000a1b40" //000a0a0a1b40
|
hexSignQrEnd = "000a1b40" // 000a0a0a1b40
|
||||||
hexSignSound = "1d6b40"
|
hexSignSound = "1d6b40" // 音频指令
|
||||||
|
|
||||||
//起始标签
|
//起始标签 -- 自定义标签utf8转码为gbk字符集
|
||||||
byteSignBR = "3c62723e" //换行
|
byteSignBR = "3c62723e" // 换行
|
||||||
byteSignCenter = "3c63656e7465723e" //居中
|
byteSignCenter = "3c63656e7465723e" // 居中
|
||||||
byteSignLeft = "3c6c6566743e" //居左
|
byteSignLeft = "3c6c6566743e" // 居左
|
||||||
byteSignRight = "3c72696768743e" //居右
|
byteSignRight = "3c72696768743e" // 居右
|
||||||
byteSignBig = "3c623e" //字体放大
|
byteSignBig = "3c623e" // 字体放大
|
||||||
byteSignHighBig = "3c68623e" //字体纵向放大
|
byteSignHighBig = "3c68623e" // 字体纵向放大
|
||||||
byteSignWideBig = "3c77623e" //字体横向放大
|
byteSignWideBig = "3c77623e" // 字体横向放大
|
||||||
byteSignQrCenter = "3c7172633e"
|
byteSignQrCenter = "3c7172633e" // 二维码居中
|
||||||
byteSignQrLeft = "3c71726c3e"
|
byteSignQrLeft = "3c71726c3e" // 二维码居左
|
||||||
byteSignQrRight = "3c7172723e"
|
byteSignQrRight = "3c7172723e" // 二维码居右
|
||||||
byteSignSound = "3c736f756e643e"
|
byteSignSound = "3c736f756e643e" // 声音
|
||||||
|
|
||||||
//结束标签
|
//结束标签
|
||||||
byteSignCenterE = "3c2f63656e7465723e" //居中
|
byteSignCenterE = "3c2f63656e7465723e" // 居中
|
||||||
byteSignLeftE = "3c2f6c6566743e" //居左
|
byteSignLeftE = "3c2f6c6566743e" // 居左
|
||||||
byteSignRightE = "3c2f72696768743e" //居右
|
byteSignRightE = "3c2f72696768743e" // 居右
|
||||||
byteSignBigE = "3c2f623e" //字体放大
|
byteSignBigE = "3c2f623e" // 字体放大
|
||||||
byteSignHighBigE = "3c2f68623e" //字体纵向放大
|
byteSignHighBigE = "3c2f68623e" // 字体纵向放大
|
||||||
byteSignWideBigE = "3c2f77623e" //字体横向放大
|
byteSignWideBigE = "3c2f77623e" // 字体横向放大
|
||||||
byteSignQrCenterE = "3c2f7172633e"
|
byteSignQrCenterE = "3c2f7172633e" // 二维码居中
|
||||||
byteSignQrLeftE = "3c2f71726c3e"
|
byteSignQrLeftE = "3c2f71726c3e" // 二维码居左
|
||||||
byteSignQrRightE = "3c2f7172723e"
|
byteSignQrRightE = "3c2f7172723e" // 二维码居右
|
||||||
byteSignSoundE = "3c2f736f756e643e"
|
byteSignSoundE = "3c2f736f756e643e" // 声音
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -405,30 +406,37 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
|
|||||||
result = strings.ReplaceAll(result, k, v)
|
result = strings.ReplaceAll(result, k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 居中标签
|
||||||
if strings.Contains(result, byteSignCenter) && strings.Contains(result, byteSignCenterE) {
|
if strings.Contains(result, byteSignCenter) && strings.Contains(result, byteSignCenterE) {
|
||||||
result = strings.ReplaceAll(result, byteSignCenter, hexSignCenter)
|
result = strings.ReplaceAll(result, byteSignCenter, hexSignCenter)
|
||||||
result = strings.ReplaceAll(result, byteSignCenterE, hexSignBROrEXE+hexSignLeft)
|
result = strings.ReplaceAll(result, byteSignCenterE, hexSignBROrEXE+hexSignLeft)
|
||||||
}
|
}
|
||||||
|
// 居左标签
|
||||||
if strings.Contains(result, byteSignLeft) && strings.Contains(result, byteSignLeftE) {
|
if strings.Contains(result, byteSignLeft) && strings.Contains(result, byteSignLeftE) {
|
||||||
result = strings.ReplaceAll(result, byteSignLeft, hexSignLeft)
|
result = strings.ReplaceAll(result, byteSignLeft, hexSignLeft)
|
||||||
result = strings.ReplaceAll(result, byteSignLeftE, hexSignBROrEXE+hexSignLeft)
|
result = strings.ReplaceAll(result, byteSignLeftE, hexSignBROrEXE+hexSignLeft)
|
||||||
}
|
}
|
||||||
|
// 居右标签
|
||||||
if strings.Contains(result, byteSignRight) && strings.Contains(result, byteSignRightE) {
|
if strings.Contains(result, byteSignRight) && strings.Contains(result, byteSignRightE) {
|
||||||
result = strings.ReplaceAll(result, byteSignRight, hexSignRight)
|
result = strings.ReplaceAll(result, byteSignRight, hexSignRight)
|
||||||
result = strings.ReplaceAll(result, byteSignRightE, hexSignBROrEXE+hexSignLeft)
|
result = strings.ReplaceAll(result, byteSignRightE, hexSignBROrEXE+hexSignLeft)
|
||||||
}
|
}
|
||||||
|
// 字体放大
|
||||||
if strings.Contains(result, byteSignBig) && strings.Contains(result, byteSignBigE) {
|
if strings.Contains(result, byteSignBig) && strings.Contains(result, byteSignBigE) {
|
||||||
result = strings.ReplaceAll(result, byteSignBig, hexSignBig)
|
result = strings.ReplaceAll(result, byteSignBig, hexSignBig)
|
||||||
result = strings.ReplaceAll(result, byteSignBigE, hexSignBROrEXE+hexSignNormal)
|
result = strings.ReplaceAll(result, byteSignBigE, hexSignBROrEXE+hexSignNormal)
|
||||||
}
|
}
|
||||||
|
// 字体高大
|
||||||
if strings.Contains(result, byteSignHighBig) && strings.Contains(result, byteSignHighBigE) {
|
if strings.Contains(result, byteSignHighBig) && strings.Contains(result, byteSignHighBigE) {
|
||||||
result = strings.ReplaceAll(result, byteSignHighBig, hexSignHighBig)
|
result = strings.ReplaceAll(result, byteSignHighBig, hexSignHighBig)
|
||||||
result = strings.ReplaceAll(result, byteSignHighBigE, hexSignBROrEXE+hexSignNormal)
|
result = strings.ReplaceAll(result, byteSignHighBigE, hexSignBROrEXE+hexSignNormal)
|
||||||
}
|
}
|
||||||
|
// 字体宽大
|
||||||
if strings.Contains(result, byteSignWideBig) && strings.Contains(result, byteSignWideBigE) {
|
if strings.Contains(result, byteSignWideBig) && strings.Contains(result, byteSignWideBigE) {
|
||||||
result = strings.ReplaceAll(result, byteSignWideBig, hexSignWideBig)
|
result = strings.ReplaceAll(result, byteSignWideBig, hexSignWideBig)
|
||||||
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) {
|
||||||
if qrs := regexpQrc.FindStringSubmatch(result); len(qrs) > 0 {
|
if qrs := regexpQrc.FindStringSubmatch(result); len(qrs) > 0 {
|
||||||
lenqr = len(qrs[1]) / 2
|
lenqr = len(qrs[1]) / 2
|
||||||
@@ -440,6 +448,7 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
|
|||||||
result = strings.ReplaceAll(result, byteSignQrCenter, hexSignQrCenter+hexSignQr+hexLenqr+"00")
|
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) {
|
||||||
if qrs := regexpQrl.FindStringSubmatch(result); len(qrs) > 0 {
|
if qrs := regexpQrl.FindStringSubmatch(result); len(qrs) > 0 {
|
||||||
lenqr = len(qrs[1]) / 2
|
lenqr = len(qrs[1]) / 2
|
||||||
@@ -451,6 +460,7 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
|
|||||||
result = strings.ReplaceAll(result, byteSignQrLeft, hexSignQrLeft+hexSignQr+hexLenqr+"00")
|
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) {
|
||||||
if qrs := regexpQrr.FindStringSubmatch(result); len(qrs) > 0 {
|
if qrs := regexpQrr.FindStringSubmatch(result); len(qrs) > 0 {
|
||||||
lenqr = len(qrs[1])
|
lenqr = len(qrs[1])
|
||||||
@@ -462,6 +472,7 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
|
|||||||
result = strings.ReplaceAll(result, byteSignQrRight, hexSignQrRight+hexSignQr+hexLenqr+"00")
|
result = strings.ReplaceAll(result, byteSignQrRight, hexSignQrRight+hexSignQr+hexLenqr+"00")
|
||||||
result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd)
|
result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd)
|
||||||
}
|
}
|
||||||
|
// 声音
|
||||||
if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) {
|
if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) {
|
||||||
if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 {
|
if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 {
|
||||||
sound := sounds[1]
|
sound := sounds[1]
|
||||||
|
|||||||
24
business/jxstore/event/print_test.go
Normal file
24
business/jxstore/event/print_test.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package event
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPrintMsg(t *testing.T) {
|
||||||
|
|
||||||
|
msg := &model.PrintMsg{
|
||||||
|
ModelIDCULD: model.ModelIDCULD{},
|
||||||
|
PrintNo: "1111",
|
||||||
|
Content: "\t<sound>您有新订单啦!</sound>\t\t<center><b>京西果园</b></center><br><br>\t\t<center>手机买菜上京西</center><br><center>极速到家送惊喜</center><br>--------------------------------<br>下单时间: 2021-08-27 21:57:26<br>预计送达: 2021-08-27 22:57:26<br>订单编号: 93154441730211100<br><br><b>美团外卖#19</b><br><qrc>93154441730211100</qrc><br>客户: 李大梦(先生)<br>电话: 15987200340<br>地址: 北浦伟业广场-2号楼 (伟业广场B区)@#云南省楚雄彝族自治州楚雄市鹿城镇伟业广场<br><br>客户备注: <br><b>【如遇缺货】: 缺货时电话与我沟通</b><br><br><br>商品明细: <br>品名 数量 单价 小计<br>--------------------------------<br>【自由拼】洗净红提160g/盒<br> x1 ¥9.20 ¥9.20<br>【果切】 牛奶木瓜约300g/份<br> x1 ¥9.70 ¥9.70<br>【自由拼】严选香蕉果切180g/盒<br> x1 ¥8.80 ¥8.80<br>[网红果切]乌梅小番茄25g/个<br> x10 ¥0.80 ¥8.00<br>[现剥]甜石榴籽约250g/份(1个)<br> x1 ¥3.50 ¥3.50<br>【爆品特惠】新鲜脆甜半斤哈密瓜 哈蜜瓜果切一盒250g/盒(230~260g)<br> x1 ¥0.01 ¥0.01<br>【爆品特惠】新鲜脆甜半斤哈密瓜 哈蜜瓜果切一盒250g/盒(230~260g)<br> x1 ¥8.60 ¥8.60<br><br>共7种16件商品<br>--------------------------------<br><center><hb>商品质量问题请联系:</hb></center><br><center><hb>京西果园·果切·水果捞(果果屋店):15841011397</hb></center><br><br>更多信息请关注官方微信: 京西菜市<br><br><br>--------------------------------<br>--------------------------------<br><br>\n",
|
||||||
|
OrderNo: 2022071109,
|
||||||
|
Status: 0,
|
||||||
|
Comment: "",
|
||||||
|
MsgID: "1",
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := buildMsg(msg)
|
||||||
|
fmt.Println("data=", string(data))
|
||||||
|
fmt.Println("err=", err)
|
||||||
|
}
|
||||||
@@ -90,7 +90,6 @@ func TestSplitUniversalOrderID(t *testing.T) {
|
|||||||
[]interface{}{
|
[]interface{}{
|
||||||
"3022716176275221584",
|
"3022716176275221584",
|
||||||
"3022716176275221584",
|
"3022716176275221584",
|
||||||
model.VendorIDELM,
|
|
||||||
},
|
},
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
"15380342248732",
|
"15380342248732",
|
||||||
@@ -105,7 +104,6 @@ func TestSplitUniversalOrderID(t *testing.T) {
|
|||||||
[]interface{}{
|
[]interface{}{
|
||||||
"5287873015048",
|
"5287873015048",
|
||||||
"5287873015048",
|
"5287873015048",
|
||||||
model.VendorIDWSC,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, v := range testData {
|
for _, v := range testData {
|
||||||
@@ -151,7 +149,6 @@ func TestGetPossibleVendorIDFromVendorOrderID(t *testing.T) {
|
|||||||
},
|
},
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
"5287873015048",
|
"5287873015048",
|
||||||
model.VendorIDWSC,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, v := range testData {
|
for _, v := range testData {
|
||||||
|
|||||||
Reference in New Issue
Block a user