fix: change the judge condition

pull/1783/head
luhaoling 2 years ago
parent 76d4b94fa3
commit 3212289d36

@ -411,129 +411,131 @@ func (m *MessageApi) CallbackExample(c *gin.Context) {
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
robotics := "5078764102" robotics := "5078764102"
if req.SendID == robotics || req.ContentType != constant.Text || req.ContentType != constant.Picture { if req.SendID == robotics {
return return
} }
if req.ContentType == constant.Text || req.ContentType == constant.Picture {
log.ZInfo(c, "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "req", req) log.ZInfo(c, "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "req", req)
log.ZInfo(c, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "req.Content", req.Content) log.ZInfo(c, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "req.Content", req.Content)
url := "http://127.0.0.1:10002/auth/user_token" url := "http://127.0.0.1:10002/auth/user_token"
header := map[string]string{} header := map[string]string{}
header["operationID"] = req.OperationID header["operationID"] = req.OperationID
input_token := &auth.UserTokenReq{ input_token := &auth.UserTokenReq{
Secret: config.Config.Secret, Secret: config.Config.Secret,
PlatformID: req.SenderPlatformID, PlatformID: req.SenderPlatformID,
UserID: config.Config.IMAdmin.UserID[0], UserID: config.Config.IMAdmin.UserID[0],
} }
type token struct {
ErrCode int `json:"errCode"`
ErrMsg string `json:"errMsg"`
ErrDlt string `json:"errDlt"`
Data auth.UserTokenResp `json:"data,omitempty"`
}
output_token := &token{}
data, err := http2.Post(c, url, header, input_token, 10)
if err != nil {
log.ZError(c, "CallbackExample get Sender token failed", err)
apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap())
return
}
log.ZDebug(c, "CallbackExample data Token", "token", data)
if err = json.Unmarshal(data, output_token); err != nil { type token struct {
log.ZError(c, "CallbackExample unmarshal userToken failed", err) ErrCode int `json:"errCode"`
apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap()) ErrMsg string `json:"errMsg"`
return ErrDlt string `json:"errDlt"`
} Data auth.UserTokenResp `json:"data,omitempty"`
}
log.ZDebug(c, "CallbackExample get User Token", "token", output_token) output_token := &token{}
user, err := m.userRpcClient.GetUserInfo(c, robotics) data, err := http2.Post(c, url, header, input_token, 10)
if err != nil { if err != nil {
log.ZError(c, "CallbackExample get Sender failed", err) log.ZError(c, "CallbackExample get Sender token failed", err)
apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap()) apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap())
return return
} }
content := make(map[string]any, 1) log.ZDebug(c, "CallbackExample data Token", "token", data)
if req.ContentType == constant.Text { if err = json.Unmarshal(data, output_token); err != nil {
con := apistruct.TextElem{} log.ZError(c, "CallbackExample unmarshal userToken failed", err)
err = json.Unmarshal([]byte(req.Content), &con)
if err != nil {
log.ZError(c, "CallbackExample unmarshal failed", err)
apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap()) apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap())
return return
} }
log.ZDebug(c, "CallbackExample TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ", con)
content["content"] = con.Content
} else {
con := apistruct.PictureElem{}
err := json.Unmarshal([]byte(req.Content), &con)
content["sourcePath"] = con.SourcePath
content["sourcePicture"] = con.SourcePicture
content["bigPicture"] = con.BigPicture
content["snapshotPicture"] = con.SnapshotPicture
log.ZDebug(c, "CallbackExample get User Token", "token", output_token)
user, err := m.userRpcClient.GetUserInfo(c, robotics)
if err != nil { if err != nil {
log.ZError(c, "picktureStruct unmarshal failed", err) log.ZError(c, "CallbackExample get Sender failed", err)
apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap()) apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap())
return return
} }
log.ZDebug(c, "CallbackExample PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE ", con)
}
log.ZDebug(c, "CallbackExample CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT ", content) content := make(map[string]any, 1)
input := &apistruct.SendMsgReq{
RecvID: req.SendID,
SendMsg: apistruct.SendMsg{
SendID: user.UserID,
SenderNickname: user.Nickname,
SenderFaceURL: user.FaceURL,
SenderPlatformID: req.SenderPlatformID,
Content: content,
ContentType: req.ContentType,
SessionType: req.SessionType,
SendTime: utils.GetCurrentTimestampByMill(),
},
}
log.ZDebug(c, "CallbackExample input input input input input input input input input input input input ", input) if req.ContentType == constant.Text {
url = "http://127.0.0.1:10002/msg/send_msg" con := apistruct.TextElem{}
header["token"] = output_token.Data.Token err = json.Unmarshal([]byte(req.Content), &con)
type sendResp struct { if err != nil {
ErrCode int `json:"errCode"` log.ZError(c, "CallbackExample unmarshal failed", err)
ErrMsg string `json:"errMsg"` apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap())
ErrDlt string `json:"errDlt"` return
Data pbmsg.SendMsgResp `json:"data,omitempty"` }
} log.ZDebug(c, "CallbackExample TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ", con)
content["content"] = con.Content
} else {
con := apistruct.PictureElem{}
err := json.Unmarshal([]byte(req.Content), &con)
content["sourcePath"] = con.SourcePath
content["sourcePicture"] = con.SourcePicture
content["bigPicture"] = con.BigPicture
content["snapshotPicture"] = con.SnapshotPicture
output := &sendResp{} if err != nil {
log.ZError(c, "picktureStruct unmarshal failed", err)
apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap())
return
}
log.ZDebug(c, "CallbackExample PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE PICKTURE ", con)
}
log.ZDebug(c, "CallbackExample Header", "header", header) log.ZDebug(c, "CallbackExample CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT ", content)
input := &apistruct.SendMsgReq{
RecvID: req.SendID,
SendMsg: apistruct.SendMsg{
SendID: user.UserID,
SenderNickname: user.Nickname,
SenderFaceURL: user.FaceURL,
SenderPlatformID: req.SenderPlatformID,
Content: content,
ContentType: req.ContentType,
SessionType: req.SessionType,
SendTime: utils.GetCurrentTimestampByMill(),
},
}
b, err := http2.Post(c, url, header, input, 10) log.ZDebug(c, "CallbackExample input input input input input input input input input input input input ", input)
if err != nil { url = "http://127.0.0.1:10002/msg/send_msg"
log.ZError(c, "CallbackExample send message failed", err) header["token"] = output_token.Data.Token
apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap()) type sendResp struct {
return ErrCode int `json:"errCode"`
} ErrMsg string `json:"errMsg"`
if err = json.Unmarshal(b, output); err != nil { ErrDlt string `json:"errDlt"`
log.ZError(c, "CallbackExample unmarshal failed", err) Data pbmsg.SendMsgResp `json:"data,omitempty"`
apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap()) }
return
} output := &sendResp{}
res := &msg.SendMsgResp{
ServerMsgID: output.Data.ServerMsgID, log.ZDebug(c, "CallbackExample Header", "header", header)
ClientMsgID: output.Data.ClientMsgID,
SendTime: output.Data.SendTime, b, err := http2.Post(c, url, header, input, 10)
} if err != nil {
log.ZDebug(c, "CallbackExample output", "output", res) log.ZError(c, "CallbackExample send message failed", err)
apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap())
return
}
if err = json.Unmarshal(b, output); err != nil {
log.ZError(c, "CallbackExample unmarshal failed", err)
apiresp.GinError(c, errs.ErrInternalServer.WithDetail(err.Error()).Wrap())
return
}
res := &msg.SendMsgResp{
ServerMsgID: output.Data.ServerMsgID,
ClientMsgID: output.Data.ClientMsgID,
SendTime: output.Data.SendTime,
}
log.ZDebug(c, "CallbackExample output", "output", res)
apiresp.GinSuccess(c, res) apiresp.GinSuccess(c, res)
}
} }

Loading…
Cancel
Save