diff --git a/controllers/api_controller.go b/controllers/api_controller.go index 671351b8b..420165e3b 100644 --- a/controllers/api_controller.go +++ b/controllers/api_controller.go @@ -1,9 +1,7 @@ package controllers import ( - "bytes" "crypto/md5" - "encoding/json" "fmt" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxstore/cms" @@ -173,7 +171,7 @@ success: { callResult.Code = model.ErrCodeSuccess if len(result) > 0 { - callResult.Data = result[0].String() + callResult.Data = result[0].Interface() } c.Data["json"] = callResult c.ServeJSON() @@ -356,35 +354,34 @@ func (c *ApiController) DoPrint(dataMap map[string]interface{}) (data, errCode s } //获取某打印消息 -func (c *ApiController) GetPrintMsg(dataMap map[string]interface{}) (data, errCode string, err error) { +func (c *ApiController) GetPrintMsg(dataMap map[string]interface{}) (printMsg *cms.GetPrintMsgResult, errCode string, err error) { var ( msgID string appID int ) globals.SugarLogger.Debugf("Begin API GetPrintMsg data: [%v]", utils.Format4Output(dataMap, false)) if _, ok := dataMap[keyMsgID].(string); !ok { - return buildParamErrCodeAndErr(keyMsgID) + return printMsg, model.ErrCodeOpenAPIParamErrNormal, fmt.Errorf("参数[%s]错误,请传入正确的值!", keyMsgID) } else { if msgID = dataMap[keyMsgID].(string); msgID == "" { - return buildParamErrCodeAndErr(keyMsgID) + return printMsg, model.ErrCodeOpenAPIParamErrNormal, fmt.Errorf("参数[%s]错误,请传入正确的值!", keyMsgID) } } appID = utils.Str2Int(dataMap[keyAppID].(string)) - if printMsg, err := cms.GetPrintMsg(appID, msgID); err != nil { - return "", model.ErrCodeGeneralFailed, err + if printMsg, err = cms.GetPrintMsg(appID, msgID); err != nil { + return printMsg, model.ErrCodeGeneralFailed, err } else if printMsg == nil { - return "", model.ErrCodeGeneralFailed, fmt.Errorf("未查询到该消息! msg_id: %v", msgID) + return printMsg, model.ErrCodeGeneralFailed, fmt.Errorf("未查询到该消息! msg_id: %v", msgID) } else { - bf := bytes.NewBuffer([]byte{}) - jsonEncoder := json.NewEncoder(bf) - jsonEncoder.SetEscapeHTML(false) - if err2 := jsonEncoder.Encode(printMsg); err2 == nil { - data = strings.Replace(bf.String(), "\n", "", strings.LastIndex(bf.String(), "\n")) - } else { - return "", model.ErrCodeGeneralFailed, err - } + //bf := bytes.NewBuffer([]byte{}) + //jsonEncoder := json.NewEncoder(bf) + //jsonEncoder.SetEscapeHTML(false) + //if err2 := jsonEncoder.Encode(printMsg); err2 == nil { + // data = strings.Replace(bf.String(), "\n", "", strings.LastIndex(bf.String(), "\n")) + //} else { + return printMsg, model.ErrCodeGeneralFailed, err } - return data, errCode, err + return printMsg, errCode, err } func unicode2utf8(source string) string { var res = []string{""} diff --git a/controllers/controllers.go b/controllers/controllers.go index f76a725bc..2fac03eb5 100644 --- a/controllers/controllers.go +++ b/controllers/controllers.go @@ -6,9 +6,9 @@ import ( ) type CallResult struct { - Code string `json:"code"` - Desc string `json:"desc"` - Data string `json:"data"` + Code string `json:"code"` + Desc string `json:"desc"` + Data interface{} `json:"data"` } func buildParamRequiredErr(str []string) (err error) {