This commit is contained in:
laodaming 2023-09-13 13:59:01 +08:00
parent d34d72a5cc
commit 190ac0407e
3 changed files with 26 additions and 15 deletions

View File

@ -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()

View File

@ -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,

View File

@ -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"`
}