From 7284949cd74418a04c684cd619c53c7cd376d142 Mon Sep 17 00:00:00 2001 From: suyl <770236076@qq.com> Date: Wed, 14 Jul 2021 09:38:31 +0800 Subject: [PATCH] unicode --- controllers/api_controller.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/controllers/api_controller.go b/controllers/api_controller.go index f3d4fefe1..bdcdffad9 100644 --- a/controllers/api_controller.go +++ b/controllers/api_controller.go @@ -376,12 +376,37 @@ func (c *ApiController) GetPrintMsg(dataMap map[string]interface{}) (data, errCo } else { if byteData, err := json.Marshal(printMsg); err == nil { data = string(byteData) + data = unicode2utf8(data) } else { return "", model.ErrCodeGeneralFailed, err } } return data, errCode, err } +func unicode2utf8(source string) string { + var res = []string{""} + sUnicode := strings.Split(source, "\\u") + var context = "" + for _, v := range sUnicode { + var additional = "" + if len(v) < 1 { + continue + } + if len(v) > 4 { + rs := []rune(v) + v = string(rs[:4]) + additional = string(rs[4:]) + } + temp, err := strconv.ParseInt(v, 16, 32) + if err != nil { + context += v + } + context += fmt.Sprintf("%c", temp) + context += additional + } + res = append(res, context) + return strings.Join(res, "") +} //查询打印机状态 func (c *ApiController) GetPrinterStatus(dataMap map[string]interface{}) (data, errCode string, err error) {