diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go index fed4fb98..236c048e 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -3,6 +3,7 @@ package logic //云渲染回调 import ( "context" + "encoding/json" "fmt" "fusenapi/server/websocket/internal/svc" "fusenapi/server/websocket/internal/types" @@ -10,7 +11,6 @@ import ( "fusenapi/utils/basic" "fusenapi/utils/file" "fusenapi/utils/websocket_data" - "strconv" "strings" "time" @@ -52,21 +52,17 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image") } unityRenderEndTime := time.Now().UTC().UnixMilli() - //解析出真的taskId跟wid - splitSlice := strings.Split(req.TaskId, " ") - if len(splitSlice) != 4 { - logx.Error("渲染回调参数错误:task_id拆分得不到合理结果") - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param task_id!!") + //解析数据 + var info websocket_data.ToUnityIdStruct + if err := json.Unmarshal([]byte(req.TaskId), &info); err != nil { + logx.Error("解析taskId错误") + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "failed to parse param taskId !!!!") } //重新赋值(很重要) - req.TaskId = splitSlice[0] - wid := splitSlice[1] - renderId := splitSlice[2] - unityRenderBeginTime, err := strconv.ParseInt(splitSlice[3], 10, 64) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "failed to parse send to unity time") - } + req.TaskId = info.TaskId + wid := info.Wid + renderId := info.RenderId + unityRenderBeginTime := info.RenderBeginTime //存base64打印测试 /* f, _ := os.Create("b.txt") defer f.Close() diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index fb464a2a..9eec5dc0 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -400,8 +400,15 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st } //发送运行阶段消息(组装数据) w.sendAssembleRenderDataStepResponseMessage(info.RenderId) + temId := websocket_data.ToUnityIdStruct{ + TaskId: taskId, + Wid: w.uniqueId, + RenderId: info.RenderId, + RenderBeginTime: time.Now().UTC().UnixMilli(), + } + temIdBytes, _ := json.Marshal(temId) sendData := map[string]interface{}{ - "id": taskId + " " + w.uniqueId + " " + info.RenderId + " " + fmt.Sprintf("%d", time.Now().UTC().UnixMilli()), //空格分开(渲染回调接口中按这个拆分) + "id": string(temIdBytes), "order_id": 0, "user_id": info.RenderData.UserId, "guest_id": info.RenderData.GuestId, diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 124950d1..16f3326b 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -62,3 +62,11 @@ type AssembleRenderDataRspMsg struct { type ToUnityRspMsg struct { RenderId string `json:"render_id"` //渲染id } + +// 发送到unity结构中id的结构 +type ToUnityIdStruct struct { + TaskId string `json:"task_id"` + Wid string `json:"wid"` + RenderId string `json:"render_id"` + RenderBeginTime int64 `json:"render_begin_time"` +}