Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
ee2bc46b92
server
render
consumer
etc
internal
websocket
server_api
utils/websocket_data
|
@ -1,12 +1,14 @@
|
||||||
package consumer
|
package consumer
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
// 消费渲染需要组装的数据
|
// 消费渲染需要组装的数据
|
||||||
type MqConsumerRenderAssemble struct {
|
type MqConsumerRenderAssemble struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MqConsumerRenderAssemble) Run(data []byte) error {
|
func (m *MqConsumerRenderAssemble) Run(data []byte) error {
|
||||||
fmt.Println("收到消息:" + string(data))
|
logx.Info("收到需要组装的消息:", string(data))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Name: render
|
Name: render
|
||||||
Host: 0.0.0.0
|
Host: 0.0.0.0
|
||||||
Port: 8888
|
Port: 9919
|
||||||
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||||
Auth:
|
Auth:
|
||||||
AccessSecret: fusen2023
|
AccessSecret: fusen2023
|
||||||
|
|
|
@ -11,22 +11,22 @@ import (
|
||||||
"fusenapi/server/render/internal/types"
|
"fusenapi/server/render/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReadImagesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var req types.RequestReadImages
|
var req types.RenderNotifyReq
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
// 创建一个业务逻辑层实例
|
||||||
l := logic.NewReadImagesLogic(r.Context(), svcCtx)
|
l := logic.NewRenderNotifyLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
rl := reflect.ValueOf(l)
|
||||||
basic.BeforeLogic(w, r, rl)
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
resp := l.ReadImages(&req, userinfo)
|
resp := l.RenderNotify(&req, userinfo)
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
basic.NormalAfterLogic(w, r, resp)
|
|
@ -13,14 +13,9 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodPost,
|
||||||
Path: "/api/render/to-unity",
|
Path: "/api/render/render_notify",
|
||||||
Handler: ToUnityHandler(serverCtx),
|
Handler: RenderNotifyHandler(serverCtx),
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: "/api/render/read-images",
|
|
||||||
Handler: ReadImagesHandler(serverCtx),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/render/internal/logic"
|
|
||||||
"fusenapi/server/render/internal/svc"
|
|
||||||
"fusenapi/server/render/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ToUnityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.RequestToUnity
|
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewToUnityLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.ToUnity(&req, userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/render/internal/svc"
|
|
||||||
"fusenapi/server/render/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ReadImagesLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewReadImagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReadImagesLogic {
|
|
||||||
return &ReadImagesLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
|
||||||
// func (l *ReadImagesLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向
|
|
||||||
// func (l *ReadImagesLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (l *ReadImagesLogic) ReadImages(req *types.RequestReadImages, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
|
|
@ -1,15 +1,15 @@
|
||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/websocket_data"
|
"fusenapi/utils/websocket_data"
|
||||||
"time"
|
|
||||||
|
|
||||||
"context"
|
"fusenapi/server/render/internal/svc"
|
||||||
|
"fusenapi/server/render/internal/types"
|
||||||
"fusenapi/server/websocket/internal/svc"
|
|
||||||
"fusenapi/server/websocket/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
@ -37,49 +37,36 @@ func NewRenderNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Rend
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basic.Response) {
|
func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
if time.Now().Unix()-120 > req.Time /*|| req.Time > time.Now().Unix() */ {
|
/*if time.Now().Unix()-120 > req.Time || req.Time > time.Now().Unix() {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param time")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param time")
|
||||||
|
}*/
|
||||||
|
if req.Info.TaskId == "" {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param task_id")
|
||||||
}
|
}
|
||||||
|
if req.Info.Image == "" {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image")
|
||||||
|
}
|
||||||
|
/* if req.Sign == "" {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param sign")
|
||||||
|
}*/
|
||||||
//验证签名 sha256
|
//验证签名 sha256
|
||||||
/*notifyByte, _ := json.Marshal(req.Info)
|
/*notifyByte, _ := json.Marshal(req.Info)
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write([]byte(fmt.Sprintf(constants.RENDER_NOTIFY_SIGN_KEY, string(notifyByte), req.Time)))
|
h.Write([]byte(fmt.Sprintf(constants.RENDER_NOTIFY_SIGN_KEY, string(notifyByte), req.Time)))
|
||||||
signHex := h.Sum(nil)
|
signHex := h.Sum(nil)
|
||||||
sign := hex.EncodeToString(signHex)
|
sign := hex.EncodeToString(signHex)
|
||||||
//fmt.Println(sign)
|
|
||||||
if req.Sign != sign {
|
if req.Sign != sign {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid sign")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid sign")
|
||||||
}*/
|
}*/
|
||||||
//遍历websocket链接把数据传进去
|
data := websocket_data.RenderImageNotify{
|
||||||
mapConnPool.Range(func(key, value any) bool {
|
TaskId: req.Info.TaskId,
|
||||||
//断言连接
|
Image: req.Info.Image,
|
||||||
ws, ok := value.(wsConnectItem)
|
}
|
||||||
if !ok {
|
d, _ := json.Marshal(data)
|
||||||
return true
|
if err := l.svcCtx.RabbitMq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d); err != nil {
|
||||||
}
|
logx.Error(err)
|
||||||
//关闭标识
|
return resp.SetStatus(basic.CodeServiceErr, "failed to send data")
|
||||||
if ws.isClose {
|
}
|
||||||
return true
|
|
||||||
}
|
|
||||||
//查询有无该渲染任务
|
|
||||||
renderId, ok := ws.renderProperty.renderImageTask[req.Info.TaskId]
|
|
||||||
if !ok {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
|
||||||
RenderId: renderId,
|
|
||||||
Image: req.Info.Image,
|
|
||||||
})
|
|
||||||
//删除对应的需要渲染的图片map
|
|
||||||
ws.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
|
||||||
Option: 0, //0删除 1添加
|
|
||||||
TaskId: req.Info.TaskId,
|
|
||||||
RenderId: renderId,
|
|
||||||
}
|
|
||||||
//发送数据到out chan
|
|
||||||
ws.sendToOutChan(b)
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
return resp.SetStatus(basic.CodeOK)
|
||||||
}
|
}
|
|
@ -1,42 +0,0 @@
|
||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/render/internal/svc"
|
|
||||||
"fusenapi/server/render/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ToUnityLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewToUnityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ToUnityLogic {
|
|
||||||
return &ToUnityLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
|
||||||
// func (l *ToUnityLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向
|
|
||||||
// func (l *ToUnityLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (l *ToUnityLogic) ToUnity(req *types.RequestToUnity, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
|
|
@ -11,6 +11,17 @@ type RequestToUnity struct {
|
||||||
type RequestReadImages struct {
|
type RequestReadImages struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RenderNotifyReq struct {
|
||||||
|
Sign string `json:"sign"`
|
||||||
|
Time int64 `json:"time"`
|
||||||
|
Info NotifyInfo `json:"info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type NotifyInfo struct {
|
||||||
|
TaskId string `json:"task_id"` //任务id
|
||||||
|
Image string `json:"image"`
|
||||||
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package consumer
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
// 消费渲染结果数据
|
|
||||||
type MqConsumerRenderResult struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MqConsumerRenderResult) Run(data []byte) error {
|
|
||||||
fmt.Println("收到消息:" + string(data))
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/server/websocket/internal/logic"
|
|
||||||
"fusenapi/server/websocket/internal/svc"
|
|
||||||
"fusenapi/server/websocket/internal/types"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var req types.RenderNotifyReq
|
|
||||||
_, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewRenderNotifyLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.RenderNotify(&req)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,16 +17,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/websocket/data_transfer",
|
Path: "/api/websocket/data_transfer",
|
||||||
Handler: DataTransferHandler(serverCtx),
|
Handler: DataTransferHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/websocket/render_notify",
|
|
||||||
Handler: RenderNotifyHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/websocket/third_party_login_notify",
|
|
||||||
Handler: ThirdPartyLoginNotifyHandler(serverCtx),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/websocket/internal/logic"
|
|
||||||
"fusenapi/server/websocket/internal/svc"
|
|
||||||
"fusenapi/server/websocket/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ThirdPartyLoginNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.ThirdPartyLoginNotifyReq
|
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewThirdPartyLoginNotifyLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.ThirdPartyLoginNotify(&req, userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -270,9 +270,9 @@ func (w *wsConnectItem) dealwithReciveData(data []byte) {
|
||||||
d, _ := json.Marshal(parseInfo.D)
|
d, _ := json.Marshal(parseInfo.D)
|
||||||
//分消息类型给到不同逻辑处理,可扩展
|
//分消息类型给到不同逻辑处理,可扩展
|
||||||
switch parseInfo.T {
|
switch parseInfo.T {
|
||||||
//图片渲染数据组装
|
//图片渲染
|
||||||
case constants.WEBSOCKET_RENDER_IMAGE_ASSEMBLE:
|
case constants.WEBSOCKET_RENDER_IMAGE:
|
||||||
w.assembleRenderData(d)
|
w.renderImage(d)
|
||||||
default:
|
default:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
52
server/websocket/internal/logic/mq_consumer.go
Normal file
52
server/websocket/internal/logic/mq_consumer.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fusenapi/constants"
|
||||||
|
"fusenapi/utils/websocket_data"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 消费渲染结果数据
|
||||||
|
type MqConsumerRenderResult struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MqConsumerRenderResult) Run(data []byte) error {
|
||||||
|
logx.Info("接收到MqConsumerRenderResult数据:", string(data))
|
||||||
|
var parseInfo websocket_data.RenderImageNotify
|
||||||
|
if err := json.Unmarshal(data, &parseInfo); err != nil {
|
||||||
|
logx.Error("MqConsumerRenderResult data format err:", err)
|
||||||
|
return nil //不返回错误则就删掉该消息
|
||||||
|
}
|
||||||
|
//遍历websocket链接把数据传进去
|
||||||
|
mapConnPool.Range(func(key, value any) bool {
|
||||||
|
//断言连接
|
||||||
|
ws, ok := value.(wsConnectItem)
|
||||||
|
if !ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
//关闭标识
|
||||||
|
if ws.isClose {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
//查询有无该渲染任务
|
||||||
|
renderId, ok := ws.renderProperty.renderImageTask[parseInfo.TaskId]
|
||||||
|
if !ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||||
|
RenderId: renderId,
|
||||||
|
Image: parseInfo.Image,
|
||||||
|
})
|
||||||
|
//删除对应的需要渲染的图片map
|
||||||
|
ws.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
||||||
|
Option: 0, //0删除 1添加
|
||||||
|
TaskId: parseInfo.TaskId,
|
||||||
|
RenderId: renderId,
|
||||||
|
}
|
||||||
|
//发送数据到out chan
|
||||||
|
ws.sendToOutChan(b)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -1,79 +0,0 @@
|
||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/constants"
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
"fusenapi/utils/websocket_data"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/websocket/internal/svc"
|
|
||||||
"fusenapi/server/websocket/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ThirdPartyLoginNotifyLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewThirdPartyLoginNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ThirdPartyLoginNotifyLogic {
|
|
||||||
return &ThirdPartyLoginNotifyLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
|
||||||
// func (l *ThirdPartyLoginNotifyLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
||||||
// func (l *ThirdPartyLoginNotifyLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (l *ThirdPartyLoginNotifyLogic) ThirdPartyLoginNotify(req *types.ThirdPartyLoginNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
if time.Now().Unix()-120 > req.Time /*|| req.Time > time.Now().Unix() */ {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param: time is invalid")
|
|
||||||
}
|
|
||||||
if req.Info.WebsocketId <= 0 {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:websocket_id is required")
|
|
||||||
}
|
|
||||||
if req.Info.Token == "" {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:token is required")
|
|
||||||
}
|
|
||||||
//验证签名 sha256
|
|
||||||
/*notifyByte, _ := json.Marshal(req.Info)
|
|
||||||
h := sha256.New()
|
|
||||||
h.Write([]byte(fmt.Sprintf(constants.THIRD_PARTY_LOGIN_NOTIFY_SIGN_KEY, string(notifyByte), req.Time)))
|
|
||||||
signHex := h.Sum(nil)
|
|
||||||
sign := hex.EncodeToString(signHex)
|
|
||||||
//fmt.Println(sign)
|
|
||||||
if req.Sign != sign {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid sign")
|
|
||||||
}*/
|
|
||||||
//查询对应websocket连接
|
|
||||||
val, ok := mapConnPool.Load(req.Info.WebsocketId)
|
|
||||||
if !ok {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success:websocket connection is not exists")
|
|
||||||
}
|
|
||||||
ws, ok := val.(wsConnectItem)
|
|
||||||
if !ok {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "type of websocket connect object is err")
|
|
||||||
}
|
|
||||||
b := ws.respondDataFormat(constants.WEBSOCKET_THIRD_PARTY_LOGIN_NOTIFY, websocket_data.ThirdPartyLoginRspMsg{
|
|
||||||
Token: req.Info.Token,
|
|
||||||
})
|
|
||||||
select {
|
|
||||||
case <-ws.closeChan:
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "websocket connect object is closed")
|
|
||||||
case ws.outChan <- b:
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,7 +22,7 @@ type renderImageControlChanItem struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 渲染发送到组装数据组装数据
|
// 渲染发送到组装数据组装数据
|
||||||
func (w *wsConnectItem) assembleRenderData(data []byte) {
|
func (w *wsConnectItem) renderImage(data []byte) {
|
||||||
var renderImageData websocket_data.RenderImageReqMsg
|
var renderImageData websocket_data.RenderImageReqMsg
|
||||||
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
||||||
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data))
|
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data))
|
||||||
|
|
|
@ -5,28 +5,6 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RenderNotifyReq struct {
|
|
||||||
Sign string `json:"sign"`
|
|
||||||
Time int64 `json:"time"`
|
|
||||||
Info NotifyInfo `json:"info"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type NotifyInfo struct {
|
|
||||||
TaskId string `json:"task_id"` //任务id
|
|
||||||
Image string `json:"image"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ThirdPartyLoginNotifyReq struct {
|
|
||||||
Sign string `json:"sign"`
|
|
||||||
Time int64 `json:"time"`
|
|
||||||
Info ThirdPartyLoginNotify `json:"info"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ThirdPartyLoginNotify struct {
|
|
||||||
WebsocketId uint64 `json:"websocket_id"`
|
|
||||||
Token string `json:"token"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/server/websocket/consumer"
|
"fusenapi/server/websocket/internal/logic"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
|
@ -34,7 +34,7 @@ func main() {
|
||||||
ctx1 := context.Background()
|
ctx1 := context.Background()
|
||||||
ctx2, cancel := context.WithCancel(ctx1)
|
ctx2, cancel := context.WithCancel(ctx1)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_RENDER_RESULT_DATA, &consumer.MqConsumerRenderResult{})
|
go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_RENDER_RESULT_DATA, &logic.MqConsumerRenderResult{})
|
||||||
handler.RegisterHandlers(server, ctx)
|
handler.RegisterHandlers(server, ctx)
|
||||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
server.Start()
|
server.Start()
|
||||||
|
|
|
@ -16,10 +16,18 @@ type RequestReadImages {
|
||||||
}
|
}
|
||||||
|
|
||||||
service render {
|
service render {
|
||||||
// 发送数据到unity渲染
|
//云渲染完了通知接口
|
||||||
@handler ToUnityHandler
|
@handler RenderNotifyHandler
|
||||||
get /api/render/to-unity(RequestToUnity) returns (response);
|
post /api/render/render_notify(RenderNotifyReq) returns (response);
|
||||||
// 读图像
|
}
|
||||||
@handler ReadImagesHandler
|
|
||||||
get /api/render/read-images(RequestReadImages) returns (response);
|
//渲染完了通知接口
|
||||||
|
type RenderNotifyReq {
|
||||||
|
Sign string `json:"sign"`
|
||||||
|
Time int64 `json:"time"`
|
||||||
|
Info NotifyInfo `json:"info"`
|
||||||
|
}
|
||||||
|
type NotifyInfo {
|
||||||
|
TaskId string `json:"task_id"` //任务id
|
||||||
|
Image string `json:"image"`
|
||||||
}
|
}
|
|
@ -12,31 +12,4 @@ service websocket {
|
||||||
//websocket数据交互
|
//websocket数据交互
|
||||||
@handler DataTransferHandler
|
@handler DataTransferHandler
|
||||||
get /api/websocket/data_transfer(request) returns (response);
|
get /api/websocket/data_transfer(request) returns (response);
|
||||||
//云渲染完了通知接口
|
|
||||||
@handler RenderNotifyHandler
|
|
||||||
post /api/websocket/render_notify(RenderNotifyReq) returns (response);
|
|
||||||
//第三方登录通知接口
|
|
||||||
@handler ThirdPartyLoginNotifyHandler
|
|
||||||
post /api/websocket/third_party_login_notify(ThirdPartyLoginNotifyReq) returns (response);
|
|
||||||
}
|
|
||||||
|
|
||||||
//渲染完了通知接口
|
|
||||||
type RenderNotifyReq {
|
|
||||||
Sign string `json:"sign"`
|
|
||||||
Time int64 `json:"time"`
|
|
||||||
Info NotifyInfo `json:"info"`
|
|
||||||
}
|
|
||||||
type NotifyInfo {
|
|
||||||
TaskId string `json:"task_id"` //任务id
|
|
||||||
Image string `json:"image"`
|
|
||||||
}
|
|
||||||
//第三方登录通知接口
|
|
||||||
type ThirdPartyLoginNotifyReq {
|
|
||||||
Sign string `json:"sign"`
|
|
||||||
Time int64 `json:"time"`
|
|
||||||
Info ThirdPartyLoginNotify `json:"info"`
|
|
||||||
}
|
|
||||||
type ThirdPartyLoginNotify {
|
|
||||||
WebsocketId uint64 `json:"websocket_id"`
|
|
||||||
Token string `json:"token"`
|
|
||||||
}
|
}
|
|
@ -5,16 +5,24 @@ type DataTransferData struct {
|
||||||
T string `json:"t"` //消息类型
|
T string `json:"t"` //消息类型
|
||||||
D interface{} `json:"d"` //传递的消息
|
D interface{} `json:"d"` //传递的消息
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// websocket接受要云渲染处理的数据
|
||||||
type RenderImageReqMsg struct {
|
type RenderImageReqMsg struct {
|
||||||
//websocket接受要云渲染处理的数据
|
|
||||||
RenderId string `json:"render_id"` //渲染id
|
RenderId string `json:"render_id"` //渲染id
|
||||||
RenderData interface{} `json:"render_data"` //参数数据
|
RenderData interface{} `json:"render_data"` //参数数据
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// websocket发送渲染完的数据
|
||||||
type RenderImageRspMsg struct {
|
type RenderImageRspMsg struct {
|
||||||
//websocket发送渲染完的数据
|
|
||||||
RenderId string `json:"render_id"` //渲染id
|
RenderId string `json:"render_id"` //渲染id
|
||||||
Image string `json:"image"` //渲染结果图片
|
Image string `json:"image"` //渲染结果图片
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 渲染服务器回调数据
|
||||||
|
type RenderImageNotify struct {
|
||||||
|
TaskId string `json:"task_id"`
|
||||||
|
Image string `json:"image"`
|
||||||
|
}
|
||||||
type ThirdPartyLoginRspMsg struct {
|
type ThirdPartyLoginRspMsg struct {
|
||||||
//websocket三方登录的通知数据
|
//websocket三方登录的通知数据
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user