From fa903fe325823fb0bfa45305919ddcb672227d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 26 Jul 2022 11:37:22 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=E6=92=AD=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/event/event_tcp_utils.go | 46 +++++++++++++++++++++-- business/jxstore/event/print_test.go | 18 ++++++++- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/business/jxstore/event/event_tcp_utils.go b/business/jxstore/event/event_tcp_utils.go index 2a122e688..7661d9737 100644 --- a/business/jxstore/event/event_tcp_utils.go +++ b/business/jxstore/event/event_tcp_utils.go @@ -54,7 +54,7 @@ const ( signSound, signSoundEnd = "", "" // 声音结束标签 // GPRS通讯说明,打印机识别二进制码 - hexSignBROrEXE = "0a" + hexSignBROrEXE = "0a" // 换行 hexSignCenter = "1b6101" // 居中打印 hexSignLeft = "1b6100" // 恢复居左打印 hexSignRight = "1b6102" // 居右打印 @@ -368,8 +368,8 @@ func buildMsg(printMsg *model.PrintMsg) (data []byte, err error) { ) //写入数据 orderNoHexH, orderNoHexL = int2h8l8(int64(orderNo)) - // 将数据与模板组装 + // 将数据与模板组装 printDataGBK, _ := jxutils.Utf8ToGbk([]byte(replaceContentOther(content))) printData = hex.EncodeToString(printDataGBK) printData = replaceContent(printData, printMsg) @@ -474,7 +474,7 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) { result = strings.ReplaceAll(result, byteSignQrRight, hexSignQrRight+hexSignQr+hexLenqr+"00") result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd) } - // 声音 + // 固定模板输出语音 if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 { sound := sounds[1] @@ -492,7 +492,17 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) { } hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix)) hexPrefixStr := hex.EncodeToString(hexPrefix) - realSound := hexPrefixStr + sound + + // 将语音包转换为十六进制 + voice := "" + for _, v := range strings.Split(sound, "2c") { + soundNum, _ := hex.DecodeString(v) // 十六进制转字符串 + intSound, _ := strconv.ParseInt(string(soundNum), 10, 64) + int16Sound := strconv.FormatInt(intSound, 16) + voice += int16Sound + } + + realSound := hexPrefixStr + voice allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2) if len(allLen) < 2 { allLen = "0" + allLen @@ -502,6 +512,34 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) { } } } + // 自动合成语音功能 + //if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { + // if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 { + // sound := sounds[1] + // if printer, _ := dao.GetPrinter(dao.GetDB(), printMsg.PrintNo); printer != nil { + // //先把结束标签消了 + // result = strings.ReplaceAll(result, byteSignSoundE, "") + // //fd 固定 + // //001a (声音数据长度高八位低八位) + // //0101 固定 + // soundPrefix := "" + // if printer.Sound != "" { + // soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + printer.Sound + // } else { + // soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + // } + // hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix)) + // hexPrefixStr := hex.EncodeToString(hexPrefix) + // realSound := hexPrefixStr + sound + // allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2) + // if len(allLen) < 2 { + // allLen = "0" + allLen + // } + // soundLenH, soundLenX := int2h8l8(int64((len(realSound) + len("0101")) / 2)) + // result = strings.ReplaceAll(result, byteSignSound, hexSignSound+allLen+"fd"+soundLenH+soundLenX+"0100"+hexPrefixStr) + // } + // } + //} return result } diff --git a/business/jxstore/event/print_test.go b/business/jxstore/event/print_test.go index 194d0159d..9ad290f72 100644 --- a/business/jxstore/event/print_test.go +++ b/business/jxstore/event/print_test.go @@ -1,8 +1,10 @@ package event import ( + "encoding/hex" "fmt" "git.rosy.net.cn/jx-callback/business/model" + "strconv" "testing" ) @@ -10,8 +12,8 @@ func TestPrintMsg(t *testing.T) { msg := &model.PrintMsg{ ModelIDCULD: model.ModelIDCULD{}, - PrintNo: "1111", - Content: "\t您有新订单啦!\t\t
京西果园


\t\t
手机买菜上京西

极速到家送惊喜

--------------------------------
下单时间: 2021-08-27 21:57:26
预计送达: 2021-08-27 22:57:26
订单编号: 93154441730211100

美团外卖#19
93154441730211100
客户: 李大梦(先生)
电话: 15987200340
地址: 北浦伟业广场-2号楼 (伟业广场B区)@#云南省楚雄彝族自治州楚雄市鹿城镇伟业广场

客户备注:
【如遇缺货】: 缺货时电话与我沟通


商品明细:
品名 数量 单价 小计
--------------------------------
【自由拼】洗净红提160g/盒
x1 ¥9.20 ¥9.20
【果切】 牛奶木瓜约300g/份
x1 ¥9.70 ¥9.70
【自由拼】严选香蕉果切180g/盒
x1 ¥8.80 ¥8.80
[网红果切]乌梅小番茄25g/个
x10 ¥0.80 ¥8.00
[现剥]甜石榴籽约250g/份(1个)
x1 ¥3.50 ¥3.50
【爆品特惠】新鲜脆甜半斤哈密瓜 哈蜜瓜果切一盒250g/盒(230~260g)
x1 ¥0.01 ¥0.01
【爆品特惠】新鲜脆甜半斤哈密瓜 哈蜜瓜果切一盒250g/盒(230~260g)
x1 ¥8.60 ¥8.60

共7种16件商品
--------------------------------
商品质量问题请联系:

京西果园·果切·水果捞(果果屋店):15841011397


更多信息请关注官方微信: 京西菜市


--------------------------------
--------------------------------

\n", + PrintNo: "20220707000002", + Content: "\t01,01,01\t\t
京西果园


\t\t
手机买菜上京西

极速到家送惊喜

--------------------------------
下单时间: 2021-08-27 21:57:26
预计送达: 2021-08-27 22:57:26
订单编号: 93154441730211100

美团外卖#19
93154441730211100
客户: 李大梦(先生)
电话: 15987200340
地址: 北浦伟业广场-2号楼 (伟业广场B区)@#云南省楚雄彝族自治州楚雄市鹿城镇伟业广场

客户备注:
【如遇缺货】: 缺货时电话与我沟通


商品明细:
品名 数量 单价 小计
--------------------------------
【自由拼】洗净红提160g/盒
x1 ¥9.20 ¥9.20
【果切】 牛奶木瓜约300g/份
x1 ¥9.70 ¥9.70
【自由拼】严选香蕉果切180g/盒
x1 ¥8.80 ¥8.80
[网红果切]乌梅小番茄25g/个
x10 ¥0.80 ¥8.00
[现剥]甜石榴籽约250g/份(1个)
x1 ¥3.50 ¥3.50
【爆品特惠】新鲜脆甜半斤哈密瓜 哈蜜瓜果切一盒250g/盒(230~260g)
x1 ¥0.01 ¥0.01
【爆品特惠】新鲜脆甜半斤哈密瓜 哈蜜瓜果切一盒250g/盒(230~260g)
x1 ¥8.60 ¥8.60

共7种16件商品
--------------------------------
商品质量问题请联系:

京西果园·果切·水果捞(果果屋店):15841011397


更多信息请关注官方微信: 京西菜市


--------------------------------
--------------------------------

\n", OrderNo: 2022071109, Status: 0, Comment: "", @@ -22,3 +24,15 @@ func TestPrintMsg(t *testing.T) { fmt.Println("data=", string(data)) fmt.Println("err=", err) } + +// 十六进制转字符串 +func TestDC(t *testing.T) { + str := "3031" + str2, _ := hex.DecodeString(str) + fmt.Println(string(str2)) +} + +// 十进制字符串转十六进制 +func Test10Two16(t *testing.T) { + fmt.Println(strconv.FormatInt(11, 16)) // 2 to 10 +} From 1d2c5e7cb38c4e89a0b4fd33af58cbbf23496889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 26 Jul 2022 11:40:30 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/financial/financial.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/business/jxstore/financial/financial.go b/business/jxstore/financial/financial.go index 1272131b1..cb222f4c2 100644 --- a/business/jxstore/financial/financial.go +++ b/business/jxstore/financial/financial.go @@ -296,13 +296,9 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) { if call.TrxStatus == tonglianpayapi.TrxStatusSuccess { switch order.OrderType { case model.PayType4Express: -<<<<<<< HEAD - err = q_bida.CreateOrder2QBiDa(&userOrder) -======= err = q_bida.CreateOrder2QBiDa(&userOrder, order.OrderID) case model.PayType4Member, model.PayType4Recharge: err = OnPayFinished(order) ->>>>>>> 273aa3164fbc887ac30837bd4ce1b25410ca498c } } return err From 6a409d113b1b048c25a7d17ac2bb1b5de9f2280f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 26 Jul 2022 11:47:37 +0800 Subject: [PATCH 3/3] 1 --- business/jxstore/event/event_tcp_utils.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/business/jxstore/event/event_tcp_utils.go b/business/jxstore/event/event_tcp_utils.go index 7661d9737..e9fbd52e3 100644 --- a/business/jxstore/event/event_tcp_utils.go +++ b/business/jxstore/event/event_tcp_utils.go @@ -501,14 +501,20 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) { int16Sound := strconv.FormatInt(intSound, 16) voice += int16Sound } + globals.SugarLogger.Debug("voice============", voice) realSound := hexPrefixStr + voice allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2) if len(allLen) < 2 { allLen = "0" + allLen } + globals.SugarLogger.Debug("realSound============", realSound) + globals.SugarLogger.Debug("allLen============", allLen) + soundLenH, soundLenX := int2h8l8(int64((len(realSound) + len("0101")) / 2)) + globals.SugarLogger.Debug("result1============", result) result = strings.ReplaceAll(result, byteSignSound, hexSignSound+allLen+"fd"+soundLenH+soundLenX+"0100"+hexPrefixStr) + globals.SugarLogger.Debug("result2============", result) } } }