修改数据转化
This commit is contained in:
@@ -475,15 +475,61 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
|
|||||||
result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd)
|
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]
|
||||||
|
printer := model.Printer{}
|
||||||
|
printer.Volume = 4
|
||||||
|
printer.Sound = "sounda"
|
||||||
|
//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)
|
||||||
|
|
||||||
|
// 将语音包转换为十六进制
|
||||||
|
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
|
||||||
|
}
|
||||||
|
voiceDataGBK, _ := jxutils.Utf8ToGbk([]byte(replaceContentOther(voice)))
|
||||||
|
voiceData := hex.EncodeToString(voiceDataGBK)
|
||||||
|
globals.SugarLogger.Debug("voice============", voiceData)
|
||||||
|
|
||||||
|
realSound := hexPrefixStr + voiceData
|
||||||
|
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)
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 自动合成语音功能
|
||||||
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]
|
||||||
if printer, _ := dao.GetPrinter(dao.GetDB(), printMsg.PrintNo); printer != nil {
|
if printer, _ := dao.GetPrinter(dao.GetDB(), printMsg.PrintNo); printer != nil {
|
||||||
//先把结束标签消了
|
//先把结束标签消了
|
||||||
result = strings.ReplaceAll(result, byteSignSoundE, "")
|
result = strings.ReplaceAll(result, byteSignSoundE, "")
|
||||||
//fd 固定
|
|
||||||
//001a (声音数据长度高八位低八位)
|
|
||||||
//0101 固定
|
|
||||||
soundPrefix := ""
|
soundPrefix := ""
|
||||||
if printer.Sound != "" {
|
if printer.Sound != "" {
|
||||||
soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + printer.Sound
|
soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + printer.Sound
|
||||||
@@ -492,60 +538,16 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
|
|||||||
}
|
}
|
||||||
hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix))
|
hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix))
|
||||||
hexPrefixStr := hex.EncodeToString(hexPrefix)
|
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
|
|
||||||
}
|
|
||||||
globals.SugarLogger.Debug("voice============", voice)
|
|
||||||
|
|
||||||
realSound := hexPrefixStr + voice
|
|
||||||
allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2)
|
allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2)
|
||||||
if len(allLen) < 2 {
|
if len(allLen) < 2 {
|
||||||
allLen = "0" + allLen
|
allLen = "0" + allLen
|
||||||
}
|
}
|
||||||
globals.SugarLogger.Debug("realSound============", realSound)
|
|
||||||
globals.SugarLogger.Debug("allLen============", allLen)
|
|
||||||
|
|
||||||
soundLenH, soundLenX := int2h8l8(int64((len(realSound) + len("0101")) / 2))
|
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)
|
result = strings.ReplaceAll(result, byteSignSound, hexSignSound+allLen+"fd"+soundLenH+soundLenX+"0100"+hexPrefixStr)
|
||||||
globals.SugarLogger.Debug("result2============", result)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 自动合成语音功能
|
|
||||||
//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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ func TestPrintMsg(t *testing.T) {
|
|||||||
msg := &model.PrintMsg{
|
msg := &model.PrintMsg{
|
||||||
ModelIDCULD: model.ModelIDCULD{},
|
ModelIDCULD: model.ModelIDCULD{},
|
||||||
PrintNo: "20220707000002",
|
PrintNo: "20220707000002",
|
||||||
Content: "\t<sound>01,01,01</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",
|
Content: "\t<sound>20</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,
|
OrderNo: 2022071109,
|
||||||
Status: 0,
|
Status: 0,
|
||||||
Comment: "",
|
Comment: "",
|
||||||
@@ -27,7 +27,7 @@ func TestPrintMsg(t *testing.T) {
|
|||||||
|
|
||||||
// 十六进制转字符串
|
// 十六进制转字符串
|
||||||
func TestDC(t *testing.T) {
|
func TestDC(t *testing.T) {
|
||||||
str := "3031"
|
str := "093c736f756e643e323009091b61011b2130bea9cef7b9fbd4b00a1b21000a1b61000a0a09091b6101cad6bbfac2f2b2cbc9cfbea9cef70a1b61000a1b6101bcabcbd9b5bdbcd2cbcdbeaacfb20a1b61000a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d0acfc2b5a5cab1bce43a20323032312d30382d32372032313a35373a32360ad4a4bcc6cbcdb4ef3a20323032312d30382d32372032323a35373a32360ab6a9b5a5b1e0bac53a2039333135343434313733303231313130300a0a1b2130c3c0cdc5cde2c2f42331390a1b21000a1d58021b5a00010611003933313534343431373330323131313030000a1b400abfcdbba73a20c0eeb4f3c3ce28cfc8c9fa290ab5e7bbb03a2031353938373230303334300ab5d8d6b73a20b1b1c6d6ceb0d2b5b9e3b3a12d32bac5c2a52028ceb0d2b5b9e3b3a142c7f8294023d4c6c4cfcaa1b3fed0dbd2cdd7e5d7d4d6ced6ddb3fed0dbcad0c2b9b3c7d5f2ceb0d2b5b9e3b3a10a0abfcdbba7b1b8d7a23a200a1b2130a1bec8e7d3f6c8b1bbf5a1bfa3ba20c8b1bbf5cab1b5e7bbb0d3ebced2b9b5cda80a1b21000a0a0ac9ccc6b7c3f7cfb83a200ac6b7c3fb20202020cafdc1bf20202020b5a5bcdb20202020202020d0a1bcc60a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d0aa1bed7d4d3c9c6b4a1bfcfb4bebbbaeccce1313630672fbad00a20202020202078312020202020a3a4392e32302020202020a3a4392e32300aa1beb9fbc7d0a1bf20c5a3c4ccc4beb9cfd4bc333030672fb7dd0a20202020202078312020202020a3a4392e37302020202020a3a4392e37300aa1bed7d4d3c9c6b4a1bfd1cfd1a1cfe3bdb6b9fbc7d0313830672fbad00a20202020202078312020202020a3a4382e38302020202020a3a4382e38300a5bcdf8baecb9fbc7d05dcedac3b7d0a1b7acc7d13235672fb8f60a20202020207831302020202020a3a4302e38302020202020a3a4382e30300a5bcfd6b0fe5dccf0caafc1f1d7d1d4bc323530672fb7dd2831b8f6290a20202020202078312020202020a3a4332e35302020202020a3a4332e35300aa1beb1acc6b7ccd8bbdda1bfd0c2cfcab4e0ccf0b0ebbdefb9fec3dcb9cf20b9fec3dbb9cfb9fbc7d0d2bbbad0323530672fbad0283233307e32363067290a20202020202078312020202020a3a4302e30312020202020a3a4302e30310aa1beb1acc6b7ccd8bbdda1bfd0c2cfcab4e0ccf0b0ebbdefb9fec3dcb9cf20b9fec3dbb9cfb9fbc7d0d2bbbad0323530672fbad0283233307e32363067290a20202020202078312020202020a3a4382e36302020202020a3a4382\ne36300a0ab9b237d6d63136bcfec9ccc6b70a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d0a1b61011b2110c9ccc6b7d6cac1bfcecacce2c7ebc1aacfb53a0a1b21000a1b61000a1b61011b2110bea9cef7b9fbd4b0a1a4b9fbc7d0a1a4cbaeb9fbc0cca3a8b9fbb9fbceddb5eaa3a93a31353834313031313339370a1b21000a1b61000a0ab8fcb6e0d0c5cfa2c7ebb9d8d7a2b9d9b7bdcea2d0c53a20bea9cef7b2cbcad00a0a0a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d0a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d0a0a0a"
|
||||||
str2, _ := hex.DecodeString(str)
|
str2, _ := hex.DecodeString(str)
|
||||||
fmt.Println(string(str2))
|
fmt.Println(string(str2))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user