结构修改

This commit is contained in:
renzhiyuan 2025-09-24 19:18:40 +08:00
parent 9699bbacbc
commit 50954b4518
9 changed files with 32 additions and 20 deletions

View File

@ -38,6 +38,7 @@ type AiRouterBiz struct {
utilAgent *utils_ollama.UtilOllama utilAgent *utils_ollama.UtilOllama
ollama *utils_ollama.Client ollama *utils_ollama.Client
channelPool *pkg.SafeChannelPool channelPool *pkg.SafeChannelPool
rds *pkg.Rdb
} }
// NewRouterService 创建路由服务 // NewRouterService 创建路由服务
@ -52,6 +53,7 @@ func NewAiRouterBiz(
utilAgent *utils_ollama.UtilOllama, utilAgent *utils_ollama.UtilOllama,
channelPool *pkg.SafeChannelPool, channelPool *pkg.SafeChannelPool,
ollama *utils_ollama.Client, ollama *utils_ollama.Client,
) *AiRouterBiz { ) *AiRouterBiz {
return &AiRouterBiz{ return &AiRouterBiz{
//aiClient: aiClient, //aiClient: aiClient,
@ -75,15 +77,15 @@ func (r *AiRouterBiz) Route(ctx context.Context, req *entitys.ChatRequest) (*ent
func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRequest) (err error) { func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRequest) (err error) {
session := c.Headers("X-Session", "") session := c.Query("x-session", "")
if len(session) == 0 { if len(session) == 0 {
return errors.SessionNotFound return errors.SessionNotFound
} }
auth := c.Headers("X-Authorization", "") auth := c.Query("x-authorization", "")
if len(auth) == 0 { if len(auth) == 0 {
return errors.AuthNotFound return errors.AuthNotFound
} }
key := c.Headers("X-App-Key", "") key := c.Query("x-app-key", "")
if len(key) == 0 { if len(key) == 0 {
return errors.KeyNotFound return errors.KeyNotFound
} }
@ -367,7 +369,7 @@ func (r *AiRouterBiz) handleKnowle(channel chan entitys.Response, c *websocket.C
func (r *AiRouterBiz) handleApiTask(channels chan entitys.Response, c *websocket.Conn, matchJson *entitys.Match, task *model.AiTask) (err error) { func (r *AiRouterBiz) handleApiTask(channels chan entitys.Response, c *websocket.Conn, matchJson *entitys.Match, task *model.AiTask) (err error) {
var ( var (
request l_request.Request request l_request.Request
auth = c.Headers("X-Authorization", "") auth = c.Query("x-authorization", "")
requestParam map[string]interface{} requestParam map[string]interface{}
) )
err = json.Unmarshal([]byte(matchJson.Parameters), &requestParam) err = json.Unmarshal([]byte(matchJson.Parameters), &requestParam)

View File

@ -6,12 +6,12 @@ var (
NotFoundError = &BusinessErr{code: 404, message: "请求地址未找到"} NotFoundError = &BusinessErr{code: 404, message: "请求地址未找到"}
SystemError = &BusinessErr{code: 405, message: "系统错误"} SystemError = &BusinessErr{code: 405, message: "系统错误"}
SupplierNotFound = &BusinessErr{code: 406, message: "供应商不存在"} ClientNotFound = &BusinessErr{code: 406, message: "未找到client_id"}
SessionNotFound = &BusinessErr{code: 407, message: "未找到会话信息"} SessionNotFound = &BusinessErr{code: 407, message: "未找到会话信息"}
AuthNotFound = &BusinessErr{code: 408, message: "身份验证失败"} AuthNotFound = &BusinessErr{code: 408, message: "身份验证失败"}
KeyNotFound = &BusinessErr{code: 409, message: "身份验证失败"} KeyNotFound = &BusinessErr{code: 409, message: "身份验证失败"}
SysNotFound = &BusinessErr{code: 410, message: "未找到系统信息"} SysNotFound = &BusinessErr{code: 410, message: "未找到系统信息"}
InvalidParam = &BusinessErr{code: InvalidParamCode, message: "无效参数"} InvalidParam = &BusinessErr{code: InvalidParamCode, message: "无效参数"}
) )
const ( const (

View File

@ -18,6 +18,7 @@ const (
ResponseFile ResponseType = "file" ResponseFile ResponseType = "file"
ResponseErr ResponseType = "error" ResponseErr ResponseType = "error"
ResponseLog ResponseType = "log" ResponseLog ResponseType = "log"
ResponseAuth ResponseType = "auth"
) )
type ResponseData struct { type ResponseData struct {

View File

@ -20,6 +20,12 @@ type ChatRequestMeta struct {
Authorization string `json:"authorization"` Authorization string `json:"authorization"`
} }
type FirstSockRequest struct {
Authorization string `json:"authorization"`
SessionID string `json:"session_id"`
AppKey string `json:"app_key"`
}
type ChatSockRequest struct { type ChatSockRequest struct {
Text string `json:"text" binding:"required"` Text string `json:"text" binding:"required"`
Img string `json:"img" binding:"required"` Img string `json:"img" binding:"required"`

View File

@ -82,12 +82,7 @@ func (h *ChatService) Chat(c *websocket.Conn) {
log.Println("读取错误:", err) log.Println("读取错误:", err)
break break
} }
//简单协议bind:<uid>
if c.Headers("Sec-Websocket-Protocol") == "bind" && c.Headers("X-Session") != "" {
uid := c.Headers("X-Session")
_ = h.Gw.BindUid(clientID, uid)
log.Printf("bind %s -> uid:%s\n", clientID, uid)
}
msg, chatType := h.handleMessageToString(c, messageType, message) msg, chatType := h.handleMessageToString(c, messageType, message)
if chatType == constants.ConnStatusClosed { if chatType == constants.ConnStatusClosed {
break break
@ -102,6 +97,14 @@ func (h *ChatService) Chat(c *websocket.Conn) {
log.Println("JSON parse error:", err) log.Println("JSON parse error:", err)
continue continue
} }
//简单协议bind:<uid>
if c.Headers("Sec-Websocket-Protocol") == "bind" && req.SessionID != "" {
uid := c.Headers("X-Session")
_ = h.Gw.BindUid(clientID, req.SessionID)
log.Printf("bind %s -> uid:%s\n", clientID, uid)
}
err = h.routerBiz.RouteWithSocket(c, &req) err = h.routerBiz.RouteWithSocket(c, &req)
if err != nil { if err != nil {
log.Println("处理失败:", err) log.Println("处理失败:", err)

View File

@ -100,7 +100,7 @@ func (w *ZltxOrderDetailTool) getZltxOrderDetail(ch chan entitys.Response, c *we
//查询订单详情 //查询订单详情
var auth string var auth string
if c != nil { if c != nil {
auth = c.Headers("X-Authorization", "") auth = c.Query("x-authorization", "")
} }
if len(auth) == 0 { if len(auth) == 0 {
auth = w.config.APIKey auth = w.config.APIKey

View File

@ -82,7 +82,7 @@ func (t *ZltxOrderLogTool) getZltxOrderLog(channel chan entitys.Response, c *web
//查询订单详情 //查询订单详情
var auth string var auth string
if c != nil { if c != nil {
auth = c.Headers("X-Authorization", "") auth = c.Query("x-authorization", "")
} }
if len(auth) == 0 { if len(auth) == 0 {
auth = t.config.APIKey auth = t.config.APIKey

View File

@ -135,7 +135,7 @@ type ZltxProductData struct {
func (z ZltxProductTool) getZltxProduct(channel chan entitys.Response, c *websocket.Conn, id string, name string) error { func (z ZltxProductTool) getZltxProduct(channel chan entitys.Response, c *websocket.Conn, id string, name string) error {
var auth string var auth string
if c != nil { if c != nil {
auth = c.Headers("X-Authorization", "") auth = c.Query("x-authorization", "")
} }
if len(auth) == 0 { if len(auth) == 0 {
auth = z.config.APIKey auth = z.config.APIKey

View File

@ -78,7 +78,7 @@ func (z ZltxOrderStatisticsTool) getZltxOrderStatistics(channel chan entitys.Res
//查询订单详情 //查询订单详情
var auth string var auth string
if c != nil { if c != nil {
auth = c.Headers("X-Authorization", "") auth = c.Query("x-authorization", "")
} }
if len(auth) == 0 { if len(auth) == 0 {
auth = z.config.APIKey auth = z.config.APIKey