Browse Source

Merge branch 'feature/v0.0.1'

* feature/v0.0.1:
  v0.0.1开发:玩家操作开发
#Suyghur 2 years ago
parent
commit
239541cef9
52 changed files with 1603 additions and 491 deletions
  1. 1 1
      apis/auth/etc/auth.yaml
  2. 45 34
      apis/cmd/cmd/cmd.go
  3. 4 3
      apis/cmd/internal/logic/csconnectplayerlogic.go
  4. 30 4
      apis/cmd/internal/logic/csfetchhistorychatlogic.go
  5. 28 4
      apis/cmd/internal/logic/csfetchhistorymsglogic.go
  6. 27 4
      apis/cmd/internal/logic/csfetchmsglogic.go
  7. 23 3
      apis/cmd/internal/logic/csfetchplayerqueuelogic.go
  8. 4 5
      apis/cmd/internal/logic/cssendmsglogic.go
  9. 3 3
      apis/cmd/internal/logic/playerdisconnectlogic.go
  10. 7 17
      apis/cmd/internal/logic/playerfetchcsinfologic.go
  11. 30 6
      apis/cmd/internal/logic/playerfetchhistorymsglogic.go
  12. 27 3
      apis/cmd/internal/logic/playerfetchmsglogic.go
  13. 4 3
      apis/cmd/internal/logic/playersendmsglogic.go
  14. 11 11
      apis/cmd/internal/server/cmdserver.go
  15. 739 133
      apis/cmd/pb/cmd.pb.go
  16. 97 32
      apis/cmd/pb/cmd.proto
  17. 55 55
      apis/cmd/pb/cmd_grpc.pb.go
  18. 0 1
      bff/apibff/apibff.go
  19. 12 11
      bff/apibff/desc/apibff.api
  20. 40 9
      bff/apibff/desc/bean.api
  21. 1 1
      bff/apibff/etc/apibff.yaml
  22. 4 8
      bff/apibff/internal/handler/cs/cmd/csconnectplayerhandler.go
  23. 2 2
      bff/apibff/internal/handler/cs/cmd/cssendmsghandler.go
  24. 3 7
      bff/apibff/internal/handler/player/cmd/playerdisconnecthandler.go
  25. 3 7
      bff/apibff/internal/handler/player/cmd/playerfetchcsinfohandler.go
  26. 3 7
      bff/apibff/internal/handler/player/cmd/playerfetchhistorymsghandler.go
  27. 2 6
      bff/apibff/internal/handler/player/cmd/playerfetchmsghandler.go
  28. 4 8
      bff/apibff/internal/handler/player/cmd/playersendmsghandler.go
  29. 36 33
      bff/apibff/internal/handler/routes.go
  30. 11 4
      bff/apibff/internal/logic/cs/cmd/csconnectplayerlogic.go
  31. 1 1
      bff/apibff/internal/logic/cs/cmd/csfetchhistorylistlogic.go
  32. 1 1
      bff/apibff/internal/logic/cs/cmd/csfetchhistorymsglogic.go
  33. 1 1
      bff/apibff/internal/logic/cs/cmd/csfetchmsglogic.go
  34. 1 1
      bff/apibff/internal/logic/cs/cmd/csfetchplayerqueuelogic.go
  35. 2 2
      bff/apibff/internal/logic/cs/cmd/cssendmsglogic.go
  36. 11 7
      bff/apibff/internal/logic/player/cmd/playerdisconnectlogic.go
  37. 7 6
      bff/apibff/internal/logic/player/cmd/playerfetchcsinfologic.go
  38. 19 5
      bff/apibff/internal/logic/player/cmd/playerfetchhistorymsglogic.go
  39. 15 4
      bff/apibff/internal/logic/player/cmd/playerfetchmsglogic.go
  40. 12 4
      bff/apibff/internal/logic/player/cmd/playersendmsglogic.go
  41. 33 0
      bff/apibff/internal/middleware/player2ctxmiddleware.go
  42. 11 4
      bff/apibff/internal/svc/servicecontext.go
  43. 40 8
      bff/apibff/internal/types/types.go
  44. 25 0
      ext/ctxdata/ctxdata.go
  45. 2 3
      ext/globalkey/rediskey.go
  46. 0 17
      ext/jwtdata/jwtdata.go
  47. 39 0
      ext/result/err.go
  48. 20 0
      ext/result/errcode.go
  49. 33 0
      ext/result/errmsg.go
  50. 49 0
      ext/result/httpresult.go
  51. 22 0
      ext/result/responsebean.go
  52. 3 2
      go.mod

+ 1 - 1
apis/auth/etc/auth.yaml

@@ -8,4 +8,4 @@ Etcd:
 
 JwtAuth:
   AccessSecret: ylink2022
-  AccessExpire: 86400
+  AccessExpire: 604800

+ 45 - 34
apis/cmd/cmd/cmd.go

@@ -13,31 +13,42 @@ import (
 )
 
 type (
-	CmdResp                  = pb.CmdResp
-	CsConnectPlayerReq       = pb.CsConnectPlayerReq
-	CsFetchHistoryChatReq    = pb.CsFetchHistoryChatReq
-	CsFetchHistoryMsgReq     = pb.CsFetchHistoryMsgReq
-	CsFetchMsgReq            = pb.CsFetchMsgReq
-	CsFetchPlayerQueueReq    = pb.CsFetchPlayerQueueReq
-	CsSendMsgReq             = pb.CsSendMsgReq
-	PlayerDisconnectReq      = pb.PlayerDisconnectReq
-	PlayerFetchCsInfoReq     = pb.PlayerFetchCsInfoReq
-	PlayerFetchHistoryMsgReq = pb.PlayerFetchHistoryMsgReq
-	PlayerFetchMsgReq        = pb.PlayerFetchMsgReq
-	PlayerSendMsgReq         = pb.PlayerSendMsgReq
+	CmdResp                   = pb.CmdResp
+	CsConnectPlayerReq        = pb.CsConnectPlayerReq
+	CsConnectPlayerResp       = pb.CsConnectPlayerResp
+	CsFetchHistoryChatReq     = pb.CsFetchHistoryChatReq
+	CsFetchHistoryChatResp    = pb.CsFetchHistoryChatResp
+	CsFetchHistoryMsgReq      = pb.CsFetchHistoryMsgReq
+	CsFetchHistoryMsgResp     = pb.CsFetchHistoryMsgResp
+	CsFetchMsgReq             = pb.CsFetchMsgReq
+	CsFetchMsgResp            = pb.CsFetchMsgResp
+	CsFetchPlayerQueueReq     = pb.CsFetchPlayerQueueReq
+	CsFetchPlayerQueueResp    = pb.CsFetchPlayerQueueResp
+	CsSendMsgReq              = pb.CsSendMsgReq
+	CsSendMsgResp             = pb.CsSendMsgResp
+	PlayerDisconnectReq       = pb.PlayerDisconnectReq
+	PlayerDisconnectResp      = pb.PlayerDisconnectResp
+	PlayerFetchCsInfoReq      = pb.PlayerFetchCsInfoReq
+	PlayerFetchCsInfoResp     = pb.PlayerFetchCsInfoResp
+	PlayerFetchHistoryMsgReq  = pb.PlayerFetchHistoryMsgReq
+	PlayerFetchHistoryMsgResp = pb.PlayerFetchHistoryMsgResp
+	PlayerFetchMsgReq         = pb.PlayerFetchMsgReq
+	PlayerFetchMsgResp        = pb.PlayerFetchMsgResp
+	PlayerSendMsgReq          = pb.PlayerSendMsgReq
+	PlayerSendMsgResp         = pb.PlayerSendMsgResp
 
 	Cmd interface {
-		PlayerFetchCsInfo(ctx context.Context, in *PlayerFetchCsInfoReq, opts ...grpc.CallOption) (*CmdResp, error)
-		PlayerFetchHistoryMsg(ctx context.Context, in *PlayerFetchHistoryMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
-		PlayerFetchMsg(ctx context.Context, in *PlayerFetchMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
-		PlayerSendMsg(ctx context.Context, in *PlayerSendMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
-		PlayerDisconnect(ctx context.Context, in *PlayerDisconnectReq, opts ...grpc.CallOption) (*CmdResp, error)
-		CsFetchPlayerQueue(ctx context.Context, in *CsFetchPlayerQueueReq, opts ...grpc.CallOption) (*CmdResp, error)
-		CsConnectPlayer(ctx context.Context, in *CsConnectPlayerReq, opts ...grpc.CallOption) (*CmdResp, error)
-		CsFetchHistoryChat(ctx context.Context, in *CsFetchHistoryChatReq, opts ...grpc.CallOption) (*CmdResp, error)
-		CsFetchHistoryMsg(ctx context.Context, in *CsFetchHistoryMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
-		CsFetchMsg(ctx context.Context, in *CsFetchMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
-		CsSendMsg(ctx context.Context, in *CsSendMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
+		PlayerFetchCsInfo(ctx context.Context, in *PlayerFetchCsInfoReq, opts ...grpc.CallOption) (*PlayerFetchCsInfoResp, error)
+		PlayerFetchHistoryMsg(ctx context.Context, in *PlayerFetchHistoryMsgReq, opts ...grpc.CallOption) (*PlayerFetchHistoryMsgResp, error)
+		PlayerFetchMsg(ctx context.Context, in *PlayerFetchMsgReq, opts ...grpc.CallOption) (*PlayerFetchMsgResp, error)
+		PlayerSendMsg(ctx context.Context, in *PlayerSendMsgReq, opts ...grpc.CallOption) (*PlayerSendMsgResp, error)
+		PlayerDisconnect(ctx context.Context, in *PlayerDisconnectReq, opts ...grpc.CallOption) (*PlayerDisconnectResp, error)
+		CsFetchPlayerQueue(ctx context.Context, in *CsFetchPlayerQueueReq, opts ...grpc.CallOption) (*CsFetchPlayerQueueResp, error)
+		CsConnectPlayer(ctx context.Context, in *CsConnectPlayerReq, opts ...grpc.CallOption) (*CsConnectPlayerResp, error)
+		CsFetchHistoryChat(ctx context.Context, in *CsFetchHistoryChatReq, opts ...grpc.CallOption) (*CsFetchHistoryChatResp, error)
+		CsFetchHistoryMsg(ctx context.Context, in *CsFetchHistoryMsgReq, opts ...grpc.CallOption) (*CsFetchHistoryMsgResp, error)
+		CsFetchMsg(ctx context.Context, in *CsFetchMsgReq, opts ...grpc.CallOption) (*CsFetchMsgResp, error)
+		CsSendMsg(ctx context.Context, in *CsSendMsgReq, opts ...grpc.CallOption) (*CsSendMsgResp, error)
 	}
 
 	defaultCmd struct {
@@ -51,57 +62,57 @@ func NewCmd(cli zrpc.Client) Cmd {
 	}
 }
 
-func (m *defaultCmd) PlayerFetchCsInfo(ctx context.Context, in *PlayerFetchCsInfoReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) PlayerFetchCsInfo(ctx context.Context, in *PlayerFetchCsInfoReq, opts ...grpc.CallOption) (*PlayerFetchCsInfoResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.PlayerFetchCsInfo(ctx, in, opts...)
 }
 
-func (m *defaultCmd) PlayerFetchHistoryMsg(ctx context.Context, in *PlayerFetchHistoryMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) PlayerFetchHistoryMsg(ctx context.Context, in *PlayerFetchHistoryMsgReq, opts ...grpc.CallOption) (*PlayerFetchHistoryMsgResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.PlayerFetchHistoryMsg(ctx, in, opts...)
 }
 
-func (m *defaultCmd) PlayerFetchMsg(ctx context.Context, in *PlayerFetchMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) PlayerFetchMsg(ctx context.Context, in *PlayerFetchMsgReq, opts ...grpc.CallOption) (*PlayerFetchMsgResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.PlayerFetchMsg(ctx, in, opts...)
 }
 
-func (m *defaultCmd) PlayerSendMsg(ctx context.Context, in *PlayerSendMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) PlayerSendMsg(ctx context.Context, in *PlayerSendMsgReq, opts ...grpc.CallOption) (*PlayerSendMsgResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.PlayerSendMsg(ctx, in, opts...)
 }
 
-func (m *defaultCmd) PlayerDisconnect(ctx context.Context, in *PlayerDisconnectReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) PlayerDisconnect(ctx context.Context, in *PlayerDisconnectReq, opts ...grpc.CallOption) (*PlayerDisconnectResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.PlayerDisconnect(ctx, in, opts...)
 }
 
-func (m *defaultCmd) CsFetchPlayerQueue(ctx context.Context, in *CsFetchPlayerQueueReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) CsFetchPlayerQueue(ctx context.Context, in *CsFetchPlayerQueueReq, opts ...grpc.CallOption) (*CsFetchPlayerQueueResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.CsFetchPlayerQueue(ctx, in, opts...)
 }
 
-func (m *defaultCmd) CsConnectPlayer(ctx context.Context, in *CsConnectPlayerReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) CsConnectPlayer(ctx context.Context, in *CsConnectPlayerReq, opts ...grpc.CallOption) (*CsConnectPlayerResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.CsConnectPlayer(ctx, in, opts...)
 }
 
-func (m *defaultCmd) CsFetchHistoryChat(ctx context.Context, in *CsFetchHistoryChatReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) CsFetchHistoryChat(ctx context.Context, in *CsFetchHistoryChatReq, opts ...grpc.CallOption) (*CsFetchHistoryChatResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.CsFetchHistoryChat(ctx, in, opts...)
 }
 
-func (m *defaultCmd) CsFetchHistoryMsg(ctx context.Context, in *CsFetchHistoryMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) CsFetchHistoryMsg(ctx context.Context, in *CsFetchHistoryMsgReq, opts ...grpc.CallOption) (*CsFetchHistoryMsgResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.CsFetchHistoryMsg(ctx, in, opts...)
 }
 
-func (m *defaultCmd) CsFetchMsg(ctx context.Context, in *CsFetchMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) CsFetchMsg(ctx context.Context, in *CsFetchMsgReq, opts ...grpc.CallOption) (*CsFetchMsgResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.CsFetchMsg(ctx, in, opts...)
 }
 
-func (m *defaultCmd) CsSendMsg(ctx context.Context, in *CsSendMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
+func (m *defaultCmd) CsSendMsg(ctx context.Context, in *CsSendMsgReq, opts ...grpc.CallOption) (*CsSendMsgResp, error) {
 	client := pb.NewCmdClient(m.cli.Conn())
 	return client.CsSendMsg(ctx, in, opts...)
 }

+ 4 - 3
apis/cmd/internal/logic/csconnectplayerlogic.go

@@ -23,8 +23,9 @@ func NewCsConnectPlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
 	}
 }
 
-func (l *CsConnectPlayerLogic) CsConnectPlayer(in *pb.CsConnectPlayerReq) (*pb.CmdResp, error) {
-	// todo: add your logic here and delete this line
+func (l *CsConnectPlayerLogic) CsConnectPlayer(in *pb.CsConnectPlayerReq) (*pb.CsConnectPlayerResp, error) {
+	// todo 调用inner修改状态,如果玩家在等待队列中,则取出玩家
+	// todo 建立连接的映射关系
 
-	return &pb.CmdResp{}, nil
+	return &pb.CsConnectPlayerResp{}, nil
 }

+ 30 - 4
apis/cmd/internal/logic/csfetchhistorychatlogic.go

@@ -2,6 +2,9 @@ package logic
 
 import (
 	"context"
+	"github.com/pkg/errors"
+	"google.golang.org/protobuf/types/known/structpb"
+	"ylink/ext/result"
 
 	"ylink/apis/cmd/internal/svc"
 	"ylink/apis/cmd/pb"
@@ -23,8 +26,31 @@ func NewCsFetchHistoryChatLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 	}
 }
 
-func (l *CsFetchHistoryChatLogic) CsFetchHistoryChat(in *pb.CsFetchHistoryChatReq) (*pb.CmdResp, error) {
-	// todo: add your logic here and delete this line
-
-	return &pb.CmdResp{}, nil
+func (l *CsFetchHistoryChatLogic) CsFetchHistoryChat(in *pb.CsFetchHistoryChatReq) (*pb.CsFetchHistoryChatResp, error) {
+	list, err := structpb.NewList([]interface{}{
+		map[string]interface{}{
+			"player_id":         "test1231",
+			"player_name":       "一条大菜狗",
+			"player_avatar_url": "https://www.baidu.com",
+			"game_id":           "game1231",
+			"game_name":         "青云诀2",
+			"update_time":       "2022-04-27 17:01:40",
+		},
+		map[string]interface{}{
+			"player_id":         "test1111",
+			"player_name":       "高手",
+			"player_avatar_url": "https://www.baidu.com",
+			"game_id":           "game1231",
+			"game_name":         "青云诀2",
+			"update_time":       "2022-04-27 17:01:40",
+		},
+	})
+	if err != nil {
+		return nil, errors.Wrap(result.NewErrMsg("fetch cs chat list error"), "")
+	}
+	return &pb.CsFetchHistoryChatResp{
+		TotalPage:   1,
+		CurrentPage: 1,
+		List:        list,
+	}, nil
 }

+ 28 - 4
apis/cmd/internal/logic/csfetchhistorymsglogic.go

@@ -2,6 +2,9 @@ package logic
 
 import (
 	"context"
+	"github.com/pkg/errors"
+	"google.golang.org/protobuf/types/known/structpb"
+	"ylink/ext/result"
 
 	"ylink/apis/cmd/internal/svc"
 	"ylink/apis/cmd/pb"
@@ -23,8 +26,29 @@ func NewCsFetchHistoryMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 	}
 }
 
-func (l *CsFetchHistoryMsgLogic) CsFetchHistoryMsg(in *pb.CsFetchHistoryMsgReq) (*pb.CmdResp, error) {
-	// todo: add your logic here and delete this line
-
-	return &pb.CmdResp{}, nil
+func (l *CsFetchHistoryMsgLogic) CsFetchHistoryMsg(in *pb.CsFetchHistoryMsgReq) (*pb.CsFetchHistoryMsgResp, error) {
+	list, err := structpb.NewList([]interface{}{
+		map[string]interface{}{
+			"content":     "你好呀,我是玩家",
+			"pic":         "https://www.baidu.com",
+			"send_id":     in.PlayerId,
+			"receiver_id": in.CsId,
+			"create_time": "2022-04-27 14:47:50",
+		},
+		map[string]interface{}{
+			"content":     "有个问题需要帮忙处理一下",
+			"pic":         "",
+			"send_id":     in.PlayerId,
+			"receiver_id": in.CsId,
+			"create_time": "2022-04-27 14:47:50",
+		},
+	})
+	if err != nil {
+		return nil, errors.Wrap(result.NewErrMsg("fetch cs history message list error"), "")
+	}
+	return &pb.CsFetchHistoryMsgResp{
+		TotalPage:   1,
+		CurrentPage: 1,
+		List:        list,
+	}, nil
 }

+ 27 - 4
apis/cmd/internal/logic/csfetchmsglogic.go

@@ -2,6 +2,9 @@ package logic
 
 import (
 	"context"
+	"github.com/pkg/errors"
+	"google.golang.org/protobuf/types/known/structpb"
+	"ylink/ext/result"
 
 	"ylink/apis/cmd/internal/svc"
 	"ylink/apis/cmd/pb"
@@ -23,8 +26,28 @@ func NewCsFetchMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CsFetc
 	}
 }
 
-func (l *CsFetchMsgLogic) CsFetchMsg(in *pb.CsFetchMsgReq) (*pb.CmdResp, error) {
-	// todo: add your logic here and delete this line
-
-	return &pb.CmdResp{}, nil
+func (l *CsFetchMsgLogic) CsFetchMsg(in *pb.CsFetchMsgReq) (*pb.CsFetchMsgResp, error) {
+	// todo 查询自己收件箱下对应玩家的信息
+	list, err := structpb.NewList([]interface{}{
+		map[string]interface{}{
+			"content":     "你好呀,我是玩家",
+			"pic":         "https://www.baidu.com",
+			"send_id":     in.PlayerId,
+			"receiver_id": in.CsId,
+			"create_time": "2022-04-27 14:47:50",
+		},
+		map[string]interface{}{
+			"content":     "有个问题需要帮忙处理一下",
+			"pic":         "",
+			"send_id":     in.PlayerId,
+			"receiver_id": in.CsId,
+			"create_time": "2022-04-27 14:47:50",
+		},
+	})
+	if err != nil {
+		return nil, errors.Wrap(result.NewErrMsg("fetch cs message list error"), "")
+	}
+	return &pb.CsFetchMsgResp{
+		List: list,
+	}, nil
 }

+ 23 - 3
apis/cmd/internal/logic/csfetchplayerqueuelogic.go

@@ -2,6 +2,9 @@ package logic
 
 import (
 	"context"
+	"github.com/pkg/errors"
+	"google.golang.org/protobuf/types/known/structpb"
+	"ylink/ext/result"
 
 	"ylink/apis/cmd/internal/svc"
 	"ylink/apis/cmd/pb"
@@ -23,8 +26,25 @@ func NewCsFetchPlayerQueueLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 	}
 }
 
-func (l *CsFetchPlayerQueueLogic) CsFetchPlayerQueue(in *pb.CsFetchPlayerQueueReq) (*pb.CmdResp, error) {
-	// todo: add your logic here and delete this line
+func (l *CsFetchPlayerQueueLogic) CsFetchPlayerQueue(in *pb.CsFetchPlayerQueueReq) (*pb.CsFetchPlayerQueueResp, error) {
+	// todo 查询等待用户的队列
 
-	return &pb.CmdResp{}, nil
+	list, err := structpb.NewList([]interface{}{
+		map[string]interface{}{
+			"player_id": "player1111",
+			"game_id":   "game1231",
+			"wait_time": 1000,
+		},
+		map[string]interface{}{
+			"player_id": "player2222",
+			"game_id":   "game1231",
+			"wait_time": 10,
+		},
+	})
+	if err != nil {
+		return nil, errors.Wrap(result.NewErrMsg("fetch player wait queue error"), "")
+	}
+	return &pb.CsFetchPlayerQueueResp{
+		List: list,
+	}, nil
 }

+ 4 - 5
apis/cmd/internal/logic/cssendmsglogic.go

@@ -2,7 +2,6 @@ package logic
 
 import (
 	"context"
-
 	"ylink/apis/cmd/internal/svc"
 	"ylink/apis/cmd/pb"
 
@@ -23,8 +22,8 @@ func NewCsSendMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CsSendM
 	}
 }
 
-func (l *CsSendMsgLogic) CsSendMsg(in *pb.CsSendMsgReq) (*pb.CmdResp, error) {
-	// todo: add your logic here and delete this line
-
-	return &pb.CmdResp{}, nil
+func (l *CsSendMsgLogic) CsSendMsg(in *pb.CsSendMsgReq) (*pb.CsSendMsgResp, error) {
+	// todo 投递到对应客服的收件箱
+	// todo 写入db
+	return &pb.CsSendMsgResp{}, nil
 }

+ 3 - 3
apis/cmd/internal/logic/playerdisconnectlogic.go

@@ -23,8 +23,8 @@ func NewPlayerDisconnectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 	}
 }
 
-func (l *PlayerDisconnectLogic) PlayerDisconnect(in *pb.PlayerDisconnectReq) (*pb.CmdResp, error) {
-	// todo: add your logic here and delete this line
+func (l *PlayerDisconnectLogic) PlayerDisconnect(in *pb.PlayerDisconnectReq) (*pb.PlayerDisconnectResp, error) {
+	// todo 修改inner服务玩家状态
 
-	return &pb.CmdResp{}, nil
+	return &pb.PlayerDisconnectResp{}, nil
 }

+ 7 - 17
apis/cmd/internal/logic/playerfetchcsinfologic.go

@@ -2,7 +2,6 @@ package logic
 
 import (
 	"context"
-	"google.golang.org/protobuf/types/known/structpb"
 
 	"ylink/apis/cmd/internal/svc"
 	"ylink/apis/cmd/pb"
@@ -24,22 +23,13 @@ func NewPlayerFetchCsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 	}
 }
 
-func (l *PlayerFetchCsInfoLogic) PlayerFetchCsInfo(in *pb.PlayerFetchCsInfoReq) (*pb.CmdResp, error) {
-	l.Logger.Infof("invoke PlayerFetchCsInfo func, cs_id: %s", in.CsId)
+func (l *PlayerFetchCsInfoLogic) PlayerFetchCsInfo(in *pb.PlayerFetchCsInfoReq) (*pb.PlayerFetchCsInfoResp, error) {
 
-	data, err := structpb.NewStruct(map[string]interface{}{
-		"cs_id":         "cs_1231",
-		"cs_nickname":   "vip客服1231",
-		"cs_avatar_url": "https://www.baidu.com",
-		"cs_signature":  "服务时间:9:30-20:30",
-		"online_status": 1,
-	})
-	if err != nil {
-		return nil, err
-	}
-	return &pb.CmdResp{
-		Code: 0,
-		Msg:  "success",
-		Data: data,
+	return &pb.PlayerFetchCsInfoResp{
+		CsId:         in.CsId,
+		CsNickname:   "vip客服1231",
+		CsAvatarUrl:  "https://www.baiduc.om",
+		CsSignature:  "服务时间:9:30-20:30",
+		OnlineStatus: 1,
 	}, nil
 }

+ 30 - 6
apis/cmd/internal/logic/playerfetchhistorymsglogic.go

@@ -2,11 +2,12 @@ package logic
 
 import (
 	"context"
-
+	"github.com/pkg/errors"
+	"github.com/zeromicro/go-zero/core/logx"
+	"google.golang.org/protobuf/types/known/structpb"
 	"ylink/apis/cmd/internal/svc"
 	"ylink/apis/cmd/pb"
-
-	"github.com/zeromicro/go-zero/core/logx"
+	"ylink/ext/result"
 )
 
 type PlayerFetchHistoryMsgLogic struct {
@@ -23,8 +24,31 @@ func NewPlayerFetchHistoryMsgLogic(ctx context.Context, svcCtx *svc.ServiceConte
 	}
 }
 
-func (l *PlayerFetchHistoryMsgLogic) PlayerFetchHistoryMsg(in *pb.PlayerFetchHistoryMsgReq) (*pb.CmdResp, error) {
-	// todo: add your logic here and delete this line
+func (l *PlayerFetchHistoryMsgLogic) PlayerFetchHistoryMsg(in *pb.PlayerFetchHistoryMsgReq) (*pb.PlayerFetchHistoryMsgResp, error) {
+	// todo 查询db下自己对应客服下的信息
+	list, err := structpb.NewList([]interface{}{
+		map[string]interface{}{
+			"content":     "你好呀,我是玩家",
+			"pic":         "https://www.baidu.com",
+			"send_id":     "test1231",
+			"receiver_id": "cs1231",
+			"create_time": "2022-04-27 14:47:50",
+		},
+		map[string]interface{}{
+			"content":     "你好呀,我是客服",
+			"pic":         "",
+			"send_id":     "cs1231",
+			"receiver_id": "test1231",
+			"create_time": "2022-04-27 14:47:50",
+		},
+	})
+	if err != nil {
+		return nil, errors.Wrap(result.NewErrMsg("fetch history message list error"), "")
+	}
 
-	return &pb.CmdResp{}, nil
+	return &pb.PlayerFetchHistoryMsgResp{
+		TotalPage:   in.Page,
+		CurrentPage: in.Page,
+		List:        list,
+	}, nil
 }

+ 27 - 3
apis/cmd/internal/logic/playerfetchmsglogic.go

@@ -2,6 +2,9 @@ package logic
 
 import (
 	"context"
+	"github.com/pkg/errors"
+	"google.golang.org/protobuf/types/known/structpb"
+	"ylink/ext/result"
 
 	"ylink/apis/cmd/internal/svc"
 	"ylink/apis/cmd/pb"
@@ -23,8 +26,29 @@ func NewPlayerFetchMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Pl
 	}
 }
 
-func (l *PlayerFetchMsgLogic) PlayerFetchMsg(in *pb.PlayerFetchMsgReq) (*pb.CmdResp, error) {
-	// todo: add your logic here and delete this line
+func (l *PlayerFetchMsgLogic) PlayerFetchMsg(in *pb.PlayerFetchMsgReq) (*pb.PlayerFetchMsgResp, error) {
+	// todo 全量取出自己收件箱下的信息
+	list, err := structpb.NewList([]interface{}{
+		map[string]interface{}{
+			"content":     "你好呀,我是玩家",
+			"pic":         "https://www.baidu.com",
+			"send_id":     in.PlayerId,
+			"receiver_id": "cs1231",
+			"create_time": "2022-04-27 14:47:50",
+		},
+		map[string]interface{}{
+			"content":     "你好呀,我是客服",
+			"pic":         "",
+			"send_id":     "cs1231",
+			"receiver_id": in.PlayerId,
+			"create_time": "2022-04-27 14:47:50",
+		},
+	})
+	if err != nil {
+		return nil, errors.Wrap(result.NewErrMsg("fetch message list error"), "")
+	}
 
-	return &pb.CmdResp{}, nil
+	return &pb.PlayerFetchMsgResp{
+		List: list,
+	}, nil
 }

+ 4 - 3
apis/cmd/internal/logic/playersendmsglogic.go

@@ -23,8 +23,9 @@ func NewPlayerSendMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Pla
 	}
 }
 
-func (l *PlayerSendMsgLogic) PlayerSendMsg(in *pb.PlayerSendMsgReq) (*pb.CmdResp, error) {
-	// todo: add your logic here and delete this line
+func (l *PlayerSendMsgLogic) PlayerSendMsg(in *pb.PlayerSendMsgReq) (*pb.PlayerSendMsgResp, error) {
+	// todo 投递到对应客服的收件箱
+	// todo 写入db
 
-	return &pb.CmdResp{}, nil
+	return &pb.PlayerSendMsgResp{}, nil
 }

+ 11 - 11
apis/cmd/internal/server/cmdserver.go

@@ -22,57 +22,57 @@ func NewCmdServer(svcCtx *svc.ServiceContext) *CmdServer {
 	}
 }
 
-func (s *CmdServer) PlayerFetchCsInfo(ctx context.Context, in *pb.PlayerFetchCsInfoReq) (*pb.CmdResp, error) {
+func (s *CmdServer) PlayerFetchCsInfo(ctx context.Context, in *pb.PlayerFetchCsInfoReq) (*pb.PlayerFetchCsInfoResp, error) {
 	l := logic.NewPlayerFetchCsInfoLogic(ctx, s.svcCtx)
 	return l.PlayerFetchCsInfo(in)
 }
 
-func (s *CmdServer) PlayerFetchHistoryMsg(ctx context.Context, in *pb.PlayerFetchHistoryMsgReq) (*pb.CmdResp, error) {
+func (s *CmdServer) PlayerFetchHistoryMsg(ctx context.Context, in *pb.PlayerFetchHistoryMsgReq) (*pb.PlayerFetchHistoryMsgResp, error) {
 	l := logic.NewPlayerFetchHistoryMsgLogic(ctx, s.svcCtx)
 	return l.PlayerFetchHistoryMsg(in)
 }
 
-func (s *CmdServer) PlayerFetchMsg(ctx context.Context, in *pb.PlayerFetchMsgReq) (*pb.CmdResp, error) {
+func (s *CmdServer) PlayerFetchMsg(ctx context.Context, in *pb.PlayerFetchMsgReq) (*pb.PlayerFetchMsgResp, error) {
 	l := logic.NewPlayerFetchMsgLogic(ctx, s.svcCtx)
 	return l.PlayerFetchMsg(in)
 }
 
-func (s *CmdServer) PlayerSendMsg(ctx context.Context, in *pb.PlayerSendMsgReq) (*pb.CmdResp, error) {
+func (s *CmdServer) PlayerSendMsg(ctx context.Context, in *pb.PlayerSendMsgReq) (*pb.PlayerSendMsgResp, error) {
 	l := logic.NewPlayerSendMsgLogic(ctx, s.svcCtx)
 	return l.PlayerSendMsg(in)
 }
 
-func (s *CmdServer) PlayerDisconnect(ctx context.Context, in *pb.PlayerDisconnectReq) (*pb.CmdResp, error) {
+func (s *CmdServer) PlayerDisconnect(ctx context.Context, in *pb.PlayerDisconnectReq) (*pb.PlayerDisconnectResp, error) {
 	l := logic.NewPlayerDisconnectLogic(ctx, s.svcCtx)
 	return l.PlayerDisconnect(in)
 }
 
-func (s *CmdServer) CsFetchPlayerQueue(ctx context.Context, in *pb.CsFetchPlayerQueueReq) (*pb.CmdResp, error) {
+func (s *CmdServer) CsFetchPlayerQueue(ctx context.Context, in *pb.CsFetchPlayerQueueReq) (*pb.CsFetchPlayerQueueResp, error) {
 	l := logic.NewCsFetchPlayerQueueLogic(ctx, s.svcCtx)
 	return l.CsFetchPlayerQueue(in)
 }
 
-func (s *CmdServer) CsConnectPlayer(ctx context.Context, in *pb.CsConnectPlayerReq) (*pb.CmdResp, error) {
+func (s *CmdServer) CsConnectPlayer(ctx context.Context, in *pb.CsConnectPlayerReq) (*pb.CsConnectPlayerResp, error) {
 	l := logic.NewCsConnectPlayerLogic(ctx, s.svcCtx)
 	return l.CsConnectPlayer(in)
 }
 
-func (s *CmdServer) CsFetchHistoryChat(ctx context.Context, in *pb.CsFetchHistoryChatReq) (*pb.CmdResp, error) {
+func (s *CmdServer) CsFetchHistoryChat(ctx context.Context, in *pb.CsFetchHistoryChatReq) (*pb.CsFetchHistoryChatResp, error) {
 	l := logic.NewCsFetchHistoryChatLogic(ctx, s.svcCtx)
 	return l.CsFetchHistoryChat(in)
 }
 
-func (s *CmdServer) CsFetchHistoryMsg(ctx context.Context, in *pb.CsFetchHistoryMsgReq) (*pb.CmdResp, error) {
+func (s *CmdServer) CsFetchHistoryMsg(ctx context.Context, in *pb.CsFetchHistoryMsgReq) (*pb.CsFetchHistoryMsgResp, error) {
 	l := logic.NewCsFetchHistoryMsgLogic(ctx, s.svcCtx)
 	return l.CsFetchHistoryMsg(in)
 }
 
-func (s *CmdServer) CsFetchMsg(ctx context.Context, in *pb.CsFetchMsgReq) (*pb.CmdResp, error) {
+func (s *CmdServer) CsFetchMsg(ctx context.Context, in *pb.CsFetchMsgReq) (*pb.CsFetchMsgResp, error) {
 	l := logic.NewCsFetchMsgLogic(ctx, s.svcCtx)
 	return l.CsFetchMsg(in)
 }
 
-func (s *CmdServer) CsSendMsg(ctx context.Context, in *pb.CsSendMsgReq) (*pb.CmdResp, error) {
+func (s *CmdServer) CsSendMsg(ctx context.Context, in *pb.CsSendMsgReq) (*pb.CsSendMsgResp, error) {
 	l := logic.NewCsSendMsgLogic(ctx, s.svcCtx)
 	return l.CsSendMsg(in)
 }

File diff suppressed because it is too large
+ 739 - 133
apis/cmd/pb/cmd.pb.go


+ 97 - 32
apis/cmd/pb/cmd.proto

@@ -16,22 +16,56 @@ message CmdResp{
 Player Command Request Bean
  */
 message PlayerFetchCsInfoReq{
+  string player_id = 1;
+  string game_id = 2;
+  string cs_id = 3;
+}
+
+message PlayerFetchCsInfoResp{
   string cs_id = 1;
+  string cs_nickname = 2;
+  string cs_avatar_url = 3;
+  string cs_signature = 4;
+  int64 online_status = 5;
 }
 
 message PlayerFetchHistoryMsgReq{
-  int64 page = 1;
-  int64 limit = 2;
+  string player_id = 1;
+  string game_id = 2;
+  int64 page = 3;
+  int64 limit = 4;
+}
+
+message PlayerFetchHistoryMsgResp{
+  int64 total_page = 1;
+  int64 current_page = 2;
+  google.protobuf.ListValue list = 3;
+}
+
+message PlayerFetchMsgReq{
+  string player_id = 1;
+  string game_id = 2;
 }
 
-message PlayerFetchMsgReq{}
+message PlayerFetchMsgResp{
+  google.protobuf.ListValue list = 1;
+}
 
 message PlayerSendMsgReq{
-  string content = 1;
-  string pic = 2;
+  string player_id = 1;
+  string game_id = 2;
+  string content = 4;
+  string pic = 5;
+}
+
+message PlayerSendMsgResp{}
+
+message PlayerDisconnectReq{
+  string player_id = 1;
+  string game_id = 2;
 }
 
-message PlayerDisconnectReq{}
+message PlayerDisconnectResp{}
 
 /**
 Cs Command Request Bean
@@ -40,46 +74,77 @@ message CsFetchPlayerQueueReq{
   int64 limit = 1;
 }
 
+message CsFetchPlayerQueueResp{
+  int64 total = 1;
+  google.protobuf.ListValue list = 2;
+}
+
 message CsConnectPlayerReq{
-  string player_id = 1;
-  string game_id = 2;
+  string cs_id = 1;
+  string player_id = 2;
+  string game_id = 3;
 }
 
+message CsConnectPlayerResp{}
+
 message CsFetchHistoryChatReq{
-  int64 page = 1;
-  int64 limit = 2;
+  string cs_id = 1;
+  int64 page = 2;
+  int64 limit = 3;
+}
+
+message CsFetchHistoryChatResp{
+  int64 total_page = 1;
+  int64 current_page = 2;
+  google.protobuf.ListValue list = 3;
 }
 
 message CsFetchHistoryMsgReq{
-  string player_id = 1;
-  string game_id = 2;
-  int64 page = 3;
-  int64 limit = 4;
+  string cs_id = 1;
+  string player_id = 2;
+  string game_id = 3;
+  int64 page = 4;
+  int64 limit = 5;
+}
+
+message CsFetchHistoryMsgResp{
+  string cs_id = 1;
+  int64 total_page = 2;
+  int64 current_page = 3;
+  google.protobuf.ListValue list = 4;
 }
 
 message CsFetchMsgReq{
-  string player_id = 1;
-  string game_id = 2;
+  string cs_id = 1;
+  string player_id = 2;
+  string game_id = 3;
+}
+
+message CsFetchMsgResp{
+  google.protobuf.ListValue list = 4;
 }
 
 message CsSendMsgReq{
-  string player_id = 1;
-  string game_id = 2;
-  string content = 3;
-  string pic = 4;
+  string cs_id = 1;
+  string player_id = 2;
+  string game_id = 3;
+  string content = 4;
+  string pic = 5;
 }
 
+message CsSendMsgResp{}
+
 service Cmd {
-  rpc playerFetchCsInfo (PlayerFetchCsInfoReq) returns (CmdResp);
-  rpc playerFetchHistoryMsg (PlayerFetchHistoryMsgReq) returns (CmdResp);
-  rpc playerFetchMsg (PlayerFetchMsgReq) returns (CmdResp);
-  rpc playerSendMsg (PlayerSendMsgReq) returns (CmdResp);
-  rpc playerDisconnect (PlayerDisconnectReq) returns (CmdResp);
-
-  rpc csFetchPlayerQueue (CsFetchPlayerQueueReq) returns (CmdResp);
-  rpc csConnectPlayer (CsConnectPlayerReq) returns (CmdResp);
-  rpc csFetchHistoryChat (CsFetchHistoryChatReq) returns (CmdResp);
-  rpc csFetchHistoryMsg (CsFetchHistoryMsgReq) returns (CmdResp);
-  rpc csFetchMsg (CsFetchMsgReq) returns (CmdResp);
-  rpc csSendMsg (CsSendMsgReq) returns (CmdResp);
+  rpc playerFetchCsInfo (PlayerFetchCsInfoReq) returns (PlayerFetchCsInfoResp);
+  rpc playerFetchHistoryMsg (PlayerFetchHistoryMsgReq) returns (PlayerFetchHistoryMsgResp);
+  rpc playerFetchMsg (PlayerFetchMsgReq) returns (PlayerFetchMsgResp);
+  rpc playerSendMsg (PlayerSendMsgReq) returns (PlayerSendMsgResp);
+  rpc playerDisconnect (PlayerDisconnectReq) returns (PlayerDisconnectResp);
+
+  rpc csFetchPlayerQueue (CsFetchPlayerQueueReq) returns (CsFetchPlayerQueueResp);
+  rpc csConnectPlayer (CsConnectPlayerReq) returns (CsConnectPlayerResp);
+  rpc csFetchHistoryChat (CsFetchHistoryChatReq) returns (CsFetchHistoryChatResp);
+  rpc csFetchHistoryMsg (CsFetchHistoryMsgReq) returns (CsFetchHistoryMsgResp);
+  rpc csFetchMsg (CsFetchMsgReq) returns (CsFetchMsgResp);
+  rpc csSendMsg (CsSendMsgReq) returns (CsSendMsgResp);
 }

+ 55 - 55
apis/cmd/pb/cmd_grpc.pb.go

@@ -22,17 +22,17 @@ const _ = grpc.SupportPackageIsVersion7
 //
 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
 type CmdClient interface {
-	PlayerFetchCsInfo(ctx context.Context, in *PlayerFetchCsInfoReq, opts ...grpc.CallOption) (*CmdResp, error)
-	PlayerFetchHistoryMsg(ctx context.Context, in *PlayerFetchHistoryMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
-	PlayerFetchMsg(ctx context.Context, in *PlayerFetchMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
-	PlayerSendMsg(ctx context.Context, in *PlayerSendMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
-	PlayerDisconnect(ctx context.Context, in *PlayerDisconnectReq, opts ...grpc.CallOption) (*CmdResp, error)
-	CsFetchPlayerQueue(ctx context.Context, in *CsFetchPlayerQueueReq, opts ...grpc.CallOption) (*CmdResp, error)
-	CsConnectPlayer(ctx context.Context, in *CsConnectPlayerReq, opts ...grpc.CallOption) (*CmdResp, error)
-	CsFetchHistoryChat(ctx context.Context, in *CsFetchHistoryChatReq, opts ...grpc.CallOption) (*CmdResp, error)
-	CsFetchHistoryMsg(ctx context.Context, in *CsFetchHistoryMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
-	CsFetchMsg(ctx context.Context, in *CsFetchMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
-	CsSendMsg(ctx context.Context, in *CsSendMsgReq, opts ...grpc.CallOption) (*CmdResp, error)
+	PlayerFetchCsInfo(ctx context.Context, in *PlayerFetchCsInfoReq, opts ...grpc.CallOption) (*PlayerFetchCsInfoResp, error)
+	PlayerFetchHistoryMsg(ctx context.Context, in *PlayerFetchHistoryMsgReq, opts ...grpc.CallOption) (*PlayerFetchHistoryMsgResp, error)
+	PlayerFetchMsg(ctx context.Context, in *PlayerFetchMsgReq, opts ...grpc.CallOption) (*PlayerFetchMsgResp, error)
+	PlayerSendMsg(ctx context.Context, in *PlayerSendMsgReq, opts ...grpc.CallOption) (*PlayerSendMsgResp, error)
+	PlayerDisconnect(ctx context.Context, in *PlayerDisconnectReq, opts ...grpc.CallOption) (*PlayerDisconnectResp, error)
+	CsFetchPlayerQueue(ctx context.Context, in *CsFetchPlayerQueueReq, opts ...grpc.CallOption) (*CsFetchPlayerQueueResp, error)
+	CsConnectPlayer(ctx context.Context, in *CsConnectPlayerReq, opts ...grpc.CallOption) (*CsConnectPlayerResp, error)
+	CsFetchHistoryChat(ctx context.Context, in *CsFetchHistoryChatReq, opts ...grpc.CallOption) (*CsFetchHistoryChatResp, error)
+	CsFetchHistoryMsg(ctx context.Context, in *CsFetchHistoryMsgReq, opts ...grpc.CallOption) (*CsFetchHistoryMsgResp, error)
+	CsFetchMsg(ctx context.Context, in *CsFetchMsgReq, opts ...grpc.CallOption) (*CsFetchMsgResp, error)
+	CsSendMsg(ctx context.Context, in *CsSendMsgReq, opts ...grpc.CallOption) (*CsSendMsgResp, error)
 }
 
 type cmdClient struct {
@@ -43,8 +43,8 @@ func NewCmdClient(cc grpc.ClientConnInterface) CmdClient {
 	return &cmdClient{cc}
 }
 
-func (c *cmdClient) PlayerFetchCsInfo(ctx context.Context, in *PlayerFetchCsInfoReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) PlayerFetchCsInfo(ctx context.Context, in *PlayerFetchCsInfoReq, opts ...grpc.CallOption) (*PlayerFetchCsInfoResp, error) {
+	out := new(PlayerFetchCsInfoResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/playerFetchCsInfo", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -52,8 +52,8 @@ func (c *cmdClient) PlayerFetchCsInfo(ctx context.Context, in *PlayerFetchCsInfo
 	return out, nil
 }
 
-func (c *cmdClient) PlayerFetchHistoryMsg(ctx context.Context, in *PlayerFetchHistoryMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) PlayerFetchHistoryMsg(ctx context.Context, in *PlayerFetchHistoryMsgReq, opts ...grpc.CallOption) (*PlayerFetchHistoryMsgResp, error) {
+	out := new(PlayerFetchHistoryMsgResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/playerFetchHistoryMsg", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -61,8 +61,8 @@ func (c *cmdClient) PlayerFetchHistoryMsg(ctx context.Context, in *PlayerFetchHi
 	return out, nil
 }
 
-func (c *cmdClient) PlayerFetchMsg(ctx context.Context, in *PlayerFetchMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) PlayerFetchMsg(ctx context.Context, in *PlayerFetchMsgReq, opts ...grpc.CallOption) (*PlayerFetchMsgResp, error) {
+	out := new(PlayerFetchMsgResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/playerFetchMsg", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -70,8 +70,8 @@ func (c *cmdClient) PlayerFetchMsg(ctx context.Context, in *PlayerFetchMsgReq, o
 	return out, nil
 }
 
-func (c *cmdClient) PlayerSendMsg(ctx context.Context, in *PlayerSendMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) PlayerSendMsg(ctx context.Context, in *PlayerSendMsgReq, opts ...grpc.CallOption) (*PlayerSendMsgResp, error) {
+	out := new(PlayerSendMsgResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/playerSendMsg", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -79,8 +79,8 @@ func (c *cmdClient) PlayerSendMsg(ctx context.Context, in *PlayerSendMsgReq, opt
 	return out, nil
 }
 
-func (c *cmdClient) PlayerDisconnect(ctx context.Context, in *PlayerDisconnectReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) PlayerDisconnect(ctx context.Context, in *PlayerDisconnectReq, opts ...grpc.CallOption) (*PlayerDisconnectResp, error) {
+	out := new(PlayerDisconnectResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/playerDisconnect", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -88,8 +88,8 @@ func (c *cmdClient) PlayerDisconnect(ctx context.Context, in *PlayerDisconnectRe
 	return out, nil
 }
 
-func (c *cmdClient) CsFetchPlayerQueue(ctx context.Context, in *CsFetchPlayerQueueReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) CsFetchPlayerQueue(ctx context.Context, in *CsFetchPlayerQueueReq, opts ...grpc.CallOption) (*CsFetchPlayerQueueResp, error) {
+	out := new(CsFetchPlayerQueueResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/csFetchPlayerQueue", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -97,8 +97,8 @@ func (c *cmdClient) CsFetchPlayerQueue(ctx context.Context, in *CsFetchPlayerQue
 	return out, nil
 }
 
-func (c *cmdClient) CsConnectPlayer(ctx context.Context, in *CsConnectPlayerReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) CsConnectPlayer(ctx context.Context, in *CsConnectPlayerReq, opts ...grpc.CallOption) (*CsConnectPlayerResp, error) {
+	out := new(CsConnectPlayerResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/csConnectPlayer", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -106,8 +106,8 @@ func (c *cmdClient) CsConnectPlayer(ctx context.Context, in *CsConnectPlayerReq,
 	return out, nil
 }
 
-func (c *cmdClient) CsFetchHistoryChat(ctx context.Context, in *CsFetchHistoryChatReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) CsFetchHistoryChat(ctx context.Context, in *CsFetchHistoryChatReq, opts ...grpc.CallOption) (*CsFetchHistoryChatResp, error) {
+	out := new(CsFetchHistoryChatResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/csFetchHistoryChat", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -115,8 +115,8 @@ func (c *cmdClient) CsFetchHistoryChat(ctx context.Context, in *CsFetchHistoryCh
 	return out, nil
 }
 
-func (c *cmdClient) CsFetchHistoryMsg(ctx context.Context, in *CsFetchHistoryMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) CsFetchHistoryMsg(ctx context.Context, in *CsFetchHistoryMsgReq, opts ...grpc.CallOption) (*CsFetchHistoryMsgResp, error) {
+	out := new(CsFetchHistoryMsgResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/csFetchHistoryMsg", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -124,8 +124,8 @@ func (c *cmdClient) CsFetchHistoryMsg(ctx context.Context, in *CsFetchHistoryMsg
 	return out, nil
 }
 
-func (c *cmdClient) CsFetchMsg(ctx context.Context, in *CsFetchMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) CsFetchMsg(ctx context.Context, in *CsFetchMsgReq, opts ...grpc.CallOption) (*CsFetchMsgResp, error) {
+	out := new(CsFetchMsgResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/csFetchMsg", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -133,8 +133,8 @@ func (c *cmdClient) CsFetchMsg(ctx context.Context, in *CsFetchMsgReq, opts ...g
 	return out, nil
 }
 
-func (c *cmdClient) CsSendMsg(ctx context.Context, in *CsSendMsgReq, opts ...grpc.CallOption) (*CmdResp, error) {
-	out := new(CmdResp)
+func (c *cmdClient) CsSendMsg(ctx context.Context, in *CsSendMsgReq, opts ...grpc.CallOption) (*CsSendMsgResp, error) {
+	out := new(CsSendMsgResp)
 	err := c.cc.Invoke(ctx, "/pb.Cmd/csSendMsg", in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -146,17 +146,17 @@ func (c *cmdClient) CsSendMsg(ctx context.Context, in *CsSendMsgReq, opts ...grp
 // All implementations must embed UnimplementedCmdServer
 // for forward compatibility
 type CmdServer interface {
-	PlayerFetchCsInfo(context.Context, *PlayerFetchCsInfoReq) (*CmdResp, error)
-	PlayerFetchHistoryMsg(context.Context, *PlayerFetchHistoryMsgReq) (*CmdResp, error)
-	PlayerFetchMsg(context.Context, *PlayerFetchMsgReq) (*CmdResp, error)
-	PlayerSendMsg(context.Context, *PlayerSendMsgReq) (*CmdResp, error)
-	PlayerDisconnect(context.Context, *PlayerDisconnectReq) (*CmdResp, error)
-	CsFetchPlayerQueue(context.Context, *CsFetchPlayerQueueReq) (*CmdResp, error)
-	CsConnectPlayer(context.Context, *CsConnectPlayerReq) (*CmdResp, error)
-	CsFetchHistoryChat(context.Context, *CsFetchHistoryChatReq) (*CmdResp, error)
-	CsFetchHistoryMsg(context.Context, *CsFetchHistoryMsgReq) (*CmdResp, error)
-	CsFetchMsg(context.Context, *CsFetchMsgReq) (*CmdResp, error)
-	CsSendMsg(context.Context, *CsSendMsgReq) (*CmdResp, error)
+	PlayerFetchCsInfo(context.Context, *PlayerFetchCsInfoReq) (*PlayerFetchCsInfoResp, error)
+	PlayerFetchHistoryMsg(context.Context, *PlayerFetchHistoryMsgReq) (*PlayerFetchHistoryMsgResp, error)
+	PlayerFetchMsg(context.Context, *PlayerFetchMsgReq) (*PlayerFetchMsgResp, error)
+	PlayerSendMsg(context.Context, *PlayerSendMsgReq) (*PlayerSendMsgResp, error)
+	PlayerDisconnect(context.Context, *PlayerDisconnectReq) (*PlayerDisconnectResp, error)
+	CsFetchPlayerQueue(context.Context, *CsFetchPlayerQueueReq) (*CsFetchPlayerQueueResp, error)
+	CsConnectPlayer(context.Context, *CsConnectPlayerReq) (*CsConnectPlayerResp, error)
+	CsFetchHistoryChat(context.Context, *CsFetchHistoryChatReq) (*CsFetchHistoryChatResp, error)
+	CsFetchHistoryMsg(context.Context, *CsFetchHistoryMsgReq) (*CsFetchHistoryMsgResp, error)
+	CsFetchMsg(context.Context, *CsFetchMsgReq) (*CsFetchMsgResp, error)
+	CsSendMsg(context.Context, *CsSendMsgReq) (*CsSendMsgResp, error)
 	mustEmbedUnimplementedCmdServer()
 }
 
@@ -164,37 +164,37 @@ type CmdServer interface {
 type UnimplementedCmdServer struct {
 }
 
-func (UnimplementedCmdServer) PlayerFetchCsInfo(context.Context, *PlayerFetchCsInfoReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) PlayerFetchCsInfo(context.Context, *PlayerFetchCsInfoReq) (*PlayerFetchCsInfoResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method PlayerFetchCsInfo not implemented")
 }
-func (UnimplementedCmdServer) PlayerFetchHistoryMsg(context.Context, *PlayerFetchHistoryMsgReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) PlayerFetchHistoryMsg(context.Context, *PlayerFetchHistoryMsgReq) (*PlayerFetchHistoryMsgResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method PlayerFetchHistoryMsg not implemented")
 }
-func (UnimplementedCmdServer) PlayerFetchMsg(context.Context, *PlayerFetchMsgReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) PlayerFetchMsg(context.Context, *PlayerFetchMsgReq) (*PlayerFetchMsgResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method PlayerFetchMsg not implemented")
 }
-func (UnimplementedCmdServer) PlayerSendMsg(context.Context, *PlayerSendMsgReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) PlayerSendMsg(context.Context, *PlayerSendMsgReq) (*PlayerSendMsgResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method PlayerSendMsg not implemented")
 }
-func (UnimplementedCmdServer) PlayerDisconnect(context.Context, *PlayerDisconnectReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) PlayerDisconnect(context.Context, *PlayerDisconnectReq) (*PlayerDisconnectResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method PlayerDisconnect not implemented")
 }
-func (UnimplementedCmdServer) CsFetchPlayerQueue(context.Context, *CsFetchPlayerQueueReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) CsFetchPlayerQueue(context.Context, *CsFetchPlayerQueueReq) (*CsFetchPlayerQueueResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method CsFetchPlayerQueue not implemented")
 }
-func (UnimplementedCmdServer) CsConnectPlayer(context.Context, *CsConnectPlayerReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) CsConnectPlayer(context.Context, *CsConnectPlayerReq) (*CsConnectPlayerResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method CsConnectPlayer not implemented")
 }
-func (UnimplementedCmdServer) CsFetchHistoryChat(context.Context, *CsFetchHistoryChatReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) CsFetchHistoryChat(context.Context, *CsFetchHistoryChatReq) (*CsFetchHistoryChatResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method CsFetchHistoryChat not implemented")
 }
-func (UnimplementedCmdServer) CsFetchHistoryMsg(context.Context, *CsFetchHistoryMsgReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) CsFetchHistoryMsg(context.Context, *CsFetchHistoryMsgReq) (*CsFetchHistoryMsgResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method CsFetchHistoryMsg not implemented")
 }
-func (UnimplementedCmdServer) CsFetchMsg(context.Context, *CsFetchMsgReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) CsFetchMsg(context.Context, *CsFetchMsgReq) (*CsFetchMsgResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method CsFetchMsg not implemented")
 }
-func (UnimplementedCmdServer) CsSendMsg(context.Context, *CsSendMsgReq) (*CmdResp, error) {
+func (UnimplementedCmdServer) CsSendMsg(context.Context, *CsSendMsgReq) (*CsSendMsgResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method CsSendMsg not implemented")
 }
 func (UnimplementedCmdServer) mustEmbedUnimplementedCmdServer() {}

+ 0 - 1
bff/apibff/apibff.go

@@ -3,7 +3,6 @@ package main
 import (
 	"flag"
 	"fmt"
-
 	"ylink/bff/apibff/internal/config"
 	"ylink/bff/apibff/internal/handler"
 	"ylink/bff/apibff/internal/svc"

+ 12 - 11
bff/apibff/desc/apibff.api

@@ -15,27 +15,28 @@ import (
 	group: player/cmd
 	prefix: api/v1
 	jwt: JwtAuth
+	middleware: Player2Ctx
 )
 service apibff {
 	@doc "玩家获取客服信息"
 	@handler playerFetchCsInfo
-	post /player/fetch_cs_info (PlayerFetchCsInfoReq) returns (CommResp)
+	post /player/fetch-cs-info (PlayerFetchCsInfoReq) returns (PlayerFetchCsInfoResp)
 	
 	@doc "玩家获取历史消息"
 	@handler playerFetchHistoryMsg
-	post /player/fetch_history_msg (PlayerFetchHistoryMsgReq) returns (CommResp)
+	post /player/fetch-history-msg (PlayerFetchHistoryMsgReq) returns (PlayerFetchHistoryMsgResp)
 	
 	@doc "玩家获取消息"
 	@handler playerFetchMsg
-	post /player/fetch_msg returns (CommResp)
+	post /player/fetch-msg returns (PlayerFetchMsgResp)
 	
 	@doc "玩家发送消息"
 	@handler playerSendMsg
-	post /player/send_msg (PlayerSendMsgReq) returns (CommResp)
+	post /player/send-msg (PlayerSendMsgReq)
 	
 	@doc "玩家断开连接客服"
 	@handler playerDisconnect
-	post /player/disconnect returns (CommResp)
+	post /player/disconnect
 }
 
 @server(
@@ -46,25 +47,25 @@ service apibff {
 service apibff {
 	@doc "客服获取玩家等待队列"
 	@handler csFetchPlayerQueue
-	post /cs/fetch_player_queue (CsFetchPlayerQueueReq) returns (CommResp)
+	post /cs/fetch-player-queue (CsFetchPlayerQueueReq) returns (CsFetchPlayerQueueResp)
 	
 	@doc "客服连接玩家"
 	@handler csConnectPlayer
-	post /cs/connect_player (CsConnectPlayerReq) returns (CommResp)
+	post /cs/connect-player (CsConnectPlayerReq)
 	
 	@doc "客服获取历史会话列表"
 	@handler csFetchHistoryList
-	post /cs/fetch_history_list (CsFetchHistoryChatReq) returns (CommResp)
+	post /cs/fetch-history-list (CsFetchHistoryChatReq) returns (CsFetchHistoryChatResp)
 	
 	@doc "客服获取历史消息"
 	@handler csFetchHistoryMsg
-	post /cs/fetch_history_msg (CsFetchHistoryMsgReq) returns (CommResp)
+	post /cs/fetch-history-msg (CsFetchHistoryMsgReq) returns (CsFetchHistoryMsgResp)
 	
 	@doc "客服获取消息"
 	@handler csFetchMsg
-	post /cs/fetch_msg (CsFetchMsgReq) returns (CommResp)
+	post /cs/fetch-msg (CsFetchMsgReq) returns (CsFetchMsgResp)
 	
 	@doc "客服发送消息"
 	@handler csSendMsg
-	post /cs/send_msg (CsSendMsgReq) returns (CommResp)
+	post /cs/send-msg (CsSendMsgReq)
 }

+ 40 - 9
bff/apibff/desc/bean.api

@@ -6,21 +6,32 @@ info(
     author: "#Suyghur"
 )
 
-
-type CommResp {
-    Code int64 `json:"code"`
-    Msg string `json:"msg"`
-    Data interface{} `json:"data"`
-}
-
 type (
     PlayerFetchCsInfoReq {
         CsId string `json:"cs_id"`
     }
 
+    PlayerFetchCsInfoResp {
+        CsId string `json:"cs_id"`
+        CsNickname string `json:"cs_nickname"`
+        CsAvatarUrl string `json:"cs_avatar_url"`
+        CsSignature string `json:"cs_signature"`
+        OnlineStatus int64 `json:"online_status"`
+    }
+
     PlayerFetchHistoryMsgReq {
-        Page int `json:"page"`
-        Limit int `json:"limit"`
+        Page int64 `json:"page"`
+        Limit int64 `json:"limit"`
+    }
+
+    PlayerFetchHistoryMsgResp {
+        TotalPage int64 `json:"total_page"`
+        CurrentPage int64 `json:"current_page"`
+        List []interface{} `json:"list"`
+    }
+
+    PlayerFetchMsgResp {
+        List []interface{} `json:"list"`
     }
 
     PlayerSendMsgReq {
@@ -34,6 +45,10 @@ type (
         Limit int `json:"limit"`
     }
 
+    CsFetchPlayerQueueResp {
+        List []interface{} `json:"list"`
+    }
+
     CsConnectPlayerReq {
         PlayerId string `json:"player_id"`
         GameId string `json:"game_id"`
@@ -44,6 +59,12 @@ type (
         Limit int `json:"limit"`
     }
 
+    CsFetchHistoryChatResp {
+        TotalPage int64 `json:"total_page"`
+        CurrentPage int64 `json:"current_page"`
+        List []interface{} `json:"list"`
+    }
+
     CsFetchHistoryMsgReq {
         PlayerId string `json:"player_id"`
         GameId string `json:"game_id"`
@@ -51,11 +72,21 @@ type (
         Limit int `json:"limit"`
     }
 
+    CsFetchHistoryMsgResp {
+        TotalPage int64 `json:"total_page"`
+        CurrentPage int64 `json:"current_page"`
+        List []interface{} `json:"list"`
+    }
+
     CsFetchMsgReq {
         PlayerId string `json:"player_id"`
         GameId string `json:"game_id"`
     }
 
+    CsFetchMsgResp {
+        List []interface{} `json:"list"`
+    }
+
     CsSendMsgReq {
         PlayerId string `json:"player_id"`
         GameId string `json:"game_id"`

+ 1 - 1
bff/apibff/etc/apibff.yaml

@@ -10,4 +10,4 @@ CmdRpc:
 
 JwtAuth:
   AccessSecret: ylink2022
-  AccessExpire: 86400
+  AccessExpire: 604800

+ 4 - 8
bff/apibff/internal/handler/cs/cmd/csconnectplayerhandler.go

@@ -2,6 +2,7 @@ package cmd
 
 import (
 	"net/http"
+	"ylink/ext/result"
 
 	"github.com/zeromicro/go-zero/rest/httpx"
 	"ylink/bff/apibff/internal/logic/cs/cmd"
@@ -13,16 +14,11 @@ func CsConnectPlayerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		var req types.CsConnectPlayerReq
 		if err := httpx.Parse(r, &req); err != nil {
-			httpx.Error(w, err)
-			return
+			result.ParamErrorResult(r, w, err)
 		}
 
 		l := cmd.NewCsConnectPlayerLogic(r.Context(), svcCtx)
-		resp, err := l.CsConnectPlayer(&req)
-		if err != nil {
-			httpx.Error(w, err)
-		} else {
-			httpx.OkJson(w, resp)
-		}
+		err := l.CsConnectPlayer(&req)
+		result.HttpResult(r, w, nil, err)
 	}
 }

+ 2 - 2
bff/apibff/internal/handler/cs/cmd/cssendmsghandler.go

@@ -18,11 +18,11 @@ func CsSendMsgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 		}
 
 		l := cmd.NewCsSendMsgLogic(r.Context(), svcCtx)
-		resp, err := l.CsSendMsg(&req)
+		err := l.CsSendMsg(&req)
 		if err != nil {
 			httpx.Error(w, err)
 		} else {
-			httpx.OkJson(w, resp)
+			httpx.Ok(w)
 		}
 	}
 }

+ 3 - 7
bff/apibff/internal/handler/player/cmd/playerdisconnecthandler.go

@@ -2,8 +2,8 @@ package cmd
 
 import (
 	"net/http"
+	"ylink/ext/result"
 
-	"github.com/zeromicro/go-zero/rest/httpx"
 	"ylink/bff/apibff/internal/logic/player/cmd"
 	"ylink/bff/apibff/internal/svc"
 )
@@ -11,11 +11,7 @@ import (
 func PlayerDisconnectHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		l := cmd.NewPlayerDisconnectLogic(r.Context(), svcCtx)
-		resp, err := l.PlayerDisconnect()
-		if err != nil {
-			httpx.Error(w, err)
-		} else {
-			httpx.OkJson(w, resp)
-		}
+		err := l.PlayerDisconnect()
+		result.HttpResult(r, w, nil, err)
 	}
 }

+ 3 - 7
bff/apibff/internal/handler/player/cmd/playerfetchcsinfohandler.go

@@ -2,6 +2,7 @@ package cmd
 
 import (
 	"net/http"
+	"ylink/ext/result"
 
 	"github.com/zeromicro/go-zero/rest/httpx"
 	"ylink/bff/apibff/internal/logic/player/cmd"
@@ -13,16 +14,11 @@ func PlayerFetchCsInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		var req types.PlayerFetchCsInfoReq
 		if err := httpx.Parse(r, &req); err != nil {
-			httpx.Error(w, err)
-			return
+			result.ParamErrorResult(r, w, err)
 		}
 
 		l := cmd.NewPlayerFetchCsInfoLogic(r.Context(), svcCtx)
 		resp, err := l.PlayerFetchCsInfo(&req)
-		if err != nil {
-			httpx.Error(w, err)
-		} else {
-			httpx.OkJson(w, resp)
-		}
+		result.HttpResult(r, w, resp, err)
 	}
 }

+ 3 - 7
bff/apibff/internal/handler/player/cmd/playerfetchhistorymsghandler.go

@@ -2,6 +2,7 @@ package cmd
 
 import (
 	"net/http"
+	"ylink/ext/result"
 
 	"github.com/zeromicro/go-zero/rest/httpx"
 	"ylink/bff/apibff/internal/logic/player/cmd"
@@ -13,16 +14,11 @@ func PlayerFetchHistoryMsgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		var req types.PlayerFetchHistoryMsgReq
 		if err := httpx.Parse(r, &req); err != nil {
-			httpx.Error(w, err)
-			return
+			result.ParamErrorResult(r, w, err)
 		}
 
 		l := cmd.NewPlayerFetchHistoryMsgLogic(r.Context(), svcCtx)
 		resp, err := l.PlayerFetchHistoryMsg(&req)
-		if err != nil {
-			httpx.Error(w, err)
-		} else {
-			httpx.OkJson(w, resp)
-		}
+		result.HttpResult(r, w, resp, err)
 	}
 }

+ 2 - 6
bff/apibff/internal/handler/player/cmd/playerfetchmsghandler.go

@@ -2,8 +2,8 @@ package cmd
 
 import (
 	"net/http"
+	"ylink/ext/result"
 
-	"github.com/zeromicro/go-zero/rest/httpx"
 	"ylink/bff/apibff/internal/logic/player/cmd"
 	"ylink/bff/apibff/internal/svc"
 )
@@ -12,10 +12,6 @@ func PlayerFetchMsgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		l := cmd.NewPlayerFetchMsgLogic(r.Context(), svcCtx)
 		resp, err := l.PlayerFetchMsg()
-		if err != nil {
-			httpx.Error(w, err)
-		} else {
-			httpx.OkJson(w, resp)
-		}
+		result.HttpResult(r, w, resp, err)
 	}
 }

+ 4 - 8
bff/apibff/internal/handler/player/cmd/playersendmsghandler.go

@@ -2,6 +2,7 @@ package cmd
 
 import (
 	"net/http"
+	"ylink/ext/result"
 
 	"github.com/zeromicro/go-zero/rest/httpx"
 	"ylink/bff/apibff/internal/logic/player/cmd"
@@ -13,16 +14,11 @@ func PlayerSendMsgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		var req types.PlayerSendMsgReq
 		if err := httpx.Parse(r, &req); err != nil {
-			httpx.Error(w, err)
-			return
+			result.ParamErrorResult(r, w, err)
 		}
 
 		l := cmd.NewPlayerSendMsgLogic(r.Context(), svcCtx)
-		resp, err := l.PlayerSendMsg(&req)
-		if err != nil {
-			httpx.Error(w, err)
-		} else {
-			httpx.OkJson(w, resp)
-		}
+		err := l.PlayerSendMsg(&req)
+		result.HttpResult(r, w, nil, err)
 	}
 }

+ 36 - 33
bff/apibff/internal/handler/routes.go

@@ -13,33 +13,36 @@ import (
 
 func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	server.AddRoutes(
-		[]rest.Route{
-			{
-				Method:  http.MethodPost,
-				Path:    "/player/fetch_cs_info",
-				Handler: playercmd.PlayerFetchCsInfoHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/player/fetch_history_msg",
-				Handler: playercmd.PlayerFetchHistoryMsgHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/player/fetch_msg",
-				Handler: playercmd.PlayerFetchMsgHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/player/send_msg",
-				Handler: playercmd.PlayerSendMsgHandler(serverCtx),
-			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/player/disconnect",
-				Handler: playercmd.PlayerDisconnectHandler(serverCtx),
-			},
-		},
+		rest.WithMiddlewares(
+			[]rest.Middleware{serverCtx.Player2Ctx},
+			[]rest.Route{
+				{
+					Method:  http.MethodPost,
+					Path:    "/player/fetch-cs-info",
+					Handler: playercmd.PlayerFetchCsInfoHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/player/fetch-history-msg",
+					Handler: playercmd.PlayerFetchHistoryMsgHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/player/fetch-msg",
+					Handler: playercmd.PlayerFetchMsgHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/player/send-msg",
+					Handler: playercmd.PlayerSendMsgHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/player/disconnect",
+					Handler: playercmd.PlayerDisconnectHandler(serverCtx),
+				},
+			}...,
+		),
 		rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
 		rest.WithPrefix("/api/v1"),
 	)
@@ -48,32 +51,32 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 		[]rest.Route{
 			{
 				Method:  http.MethodPost,
-				Path:    "/cs/fetch_player_queue",
+				Path:    "/cs/fetch-player-queue",
 				Handler: cscmd.CsFetchPlayerQueueHandler(serverCtx),
 			},
 			{
 				Method:  http.MethodPost,
-				Path:    "/cs/connect_player",
+				Path:    "/cs/connect-player",
 				Handler: cscmd.CsConnectPlayerHandler(serverCtx),
 			},
 			{
 				Method:  http.MethodPost,
-				Path:    "/cs/fetch_history_list",
+				Path:    "/cs/fetch-history-list",
 				Handler: cscmd.CsFetchHistoryListHandler(serverCtx),
 			},
 			{
 				Method:  http.MethodPost,
-				Path:    "/cs/fetch_history_msg",
+				Path:    "/cs/fetch-history-msg",
 				Handler: cscmd.CsFetchHistoryMsgHandler(serverCtx),
 			},
 			{
 				Method:  http.MethodPost,
-				Path:    "/cs/fetch_msg",
+				Path:    "/cs/fetch-msg",
 				Handler: cscmd.CsFetchMsgHandler(serverCtx),
 			},
 			{
 				Method:  http.MethodPost,
-				Path:    "/cs/send_msg",
+				Path:    "/cs/send-msg",
 				Handler: cscmd.CsSendMsgHandler(serverCtx),
 			},
 		},

+ 11 - 4
bff/apibff/internal/logic/cs/cmd/csconnectplayerlogic.go

@@ -2,6 +2,7 @@ package cmd
 
 import (
 	"context"
+	"ylink/apis/cmd/pb"
 
 	"ylink/bff/apibff/internal/svc"
 	"ylink/bff/apibff/internal/types"
@@ -23,8 +24,14 @@ func NewCsConnectPlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
 	}
 }
 
-func (l *CsConnectPlayerLogic) CsConnectPlayer(req *types.CsConnectPlayerReq) (resp *types.CommResp, err error) {
-	// todo: add your logic here and delete this line
-
-	return
+func (l *CsConnectPlayerLogic) CsConnectPlayer(req *types.CsConnectPlayerReq) error {
+	_, err := l.svcCtx.CmdRpc.CsConnectPlayer(l.ctx, &pb.CsConnectPlayerReq{
+		PlayerId: req.PlayerId,
+		GameId:   req.GameId,
+		CsId:     "",
+	})
+	if err != nil {
+		return err
+	}
+	return nil
 }

+ 1 - 1
bff/apibff/internal/logic/cs/cmd/csfetchhistorylistlogic.go

@@ -23,7 +23,7 @@ func NewCsFetchHistoryListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 	}
 }
 
-func (l *CsFetchHistoryListLogic) CsFetchHistoryList(req *types.CsFetchHistoryChatReq) (resp *types.CommResp, err error) {
+func (l *CsFetchHistoryListLogic) CsFetchHistoryList(req *types.CsFetchHistoryChatReq) (resp *types.CsFetchHistoryChatResp, err error) {
 	// todo: add your logic here and delete this line
 
 	return

+ 1 - 1
bff/apibff/internal/logic/cs/cmd/csfetchhistorymsglogic.go

@@ -23,7 +23,7 @@ func NewCsFetchHistoryMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 	}
 }
 
-func (l *CsFetchHistoryMsgLogic) CsFetchHistoryMsg(req *types.CsFetchHistoryMsgReq) (resp *types.CommResp, err error) {
+func (l *CsFetchHistoryMsgLogic) CsFetchHistoryMsg(req *types.CsFetchHistoryMsgReq) (resp *types.CsFetchHistoryMsgResp, err error) {
 	// todo: add your logic here and delete this line
 
 	return

+ 1 - 1
bff/apibff/internal/logic/cs/cmd/csfetchmsglogic.go

@@ -23,7 +23,7 @@ func NewCsFetchMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CsFetc
 	}
 }
 
-func (l *CsFetchMsgLogic) CsFetchMsg(req *types.CsFetchMsgReq) (resp *types.CommResp, err error) {
+func (l *CsFetchMsgLogic) CsFetchMsg(req *types.CsFetchMsgReq) (resp *types.CsFetchMsgResp, err error) {
 	// todo: add your logic here and delete this line
 
 	return

+ 1 - 1
bff/apibff/internal/logic/cs/cmd/csfetchplayerqueuelogic.go

@@ -23,7 +23,7 @@ func NewCsFetchPlayerQueueLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 	}
 }
 
-func (l *CsFetchPlayerQueueLogic) CsFetchPlayerQueue(req *types.CsFetchPlayerQueueReq) (resp *types.CommResp, err error) {
+func (l *CsFetchPlayerQueueLogic) CsFetchPlayerQueue(req *types.CsFetchPlayerQueueReq) (resp *types.CsFetchPlayerQueueResp, err error) {
 	// todo: add your logic here and delete this line
 
 	return

+ 2 - 2
bff/apibff/internal/logic/cs/cmd/cssendmsglogic.go

@@ -23,8 +23,8 @@ func NewCsSendMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CsSendM
 	}
 }
 
-func (l *CsSendMsgLogic) CsSendMsg(req *types.CsSendMsgReq) (resp *types.CommResp, err error) {
+func (l *CsSendMsgLogic) CsSendMsg(req *types.CsSendMsgReq) error {
 	// todo: add your logic here and delete this line
 
-	return
+	return nil
 }

+ 11 - 7
bff/apibff/internal/logic/player/cmd/playerdisconnectlogic.go

@@ -2,11 +2,11 @@ package cmd
 
 import (
 	"context"
-
-	"ylink/bff/apibff/internal/svc"
-	"ylink/bff/apibff/internal/types"
+	"ylink/apis/cmd/pb"
+	"ylink/ext/ctxdata"
 
 	"github.com/zeromicro/go-zero/core/logx"
+	"ylink/bff/apibff/internal/svc"
 )
 
 type PlayerDisconnectLogic struct {
@@ -23,8 +23,12 @@ func NewPlayerDisconnectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 	}
 }
 
-func (l *PlayerDisconnectLogic) PlayerDisconnect() (resp *types.CommResp, err error) {
-	// todo: add your logic here and delete this line
-
-	return
+func (l *PlayerDisconnectLogic) PlayerDisconnect() error {
+	playerId := ctxdata.GetPlayerIdFromCtx(l.ctx)
+	gameId := ctxdata.GetGameIdFromCtx(l.ctx)
+	_, err := l.svcCtx.CmdRpc.PlayerDisconnect(l.ctx, &pb.PlayerDisconnectReq{
+		PlayerId: playerId,
+		GameId:   gameId,
+	})
+	return err
 }

+ 7 - 6
bff/apibff/internal/logic/player/cmd/playerfetchcsinfologic.go

@@ -24,17 +24,18 @@ func NewPlayerFetchCsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 	}
 }
 
-func (l *PlayerFetchCsInfoLogic) PlayerFetchCsInfo(req *types.PlayerFetchCsInfoReq) (resp *types.CommResp, err error) {
+func (l *PlayerFetchCsInfoLogic) PlayerFetchCsInfo(req *types.PlayerFetchCsInfoReq) (resp *types.PlayerFetchCsInfoResp, err error) {
 	cmdResp, err := l.svcCtx.CmdRpc.PlayerFetchCsInfo(l.ctx, &pb.PlayerFetchCsInfoReq{
 		CsId: req.CsId,
 	})
 	if err != nil {
 		return nil, err
 	}
-
-	return &types.CommResp{
-		Code: cmdResp.Code,
-		Msg:  cmdResp.Msg,
-		Data: cmdResp.Data,
+	return &types.PlayerFetchCsInfoResp{
+		CsId:         cmdResp.CsId,
+		CsNickname:   cmdResp.CsNickname,
+		CsAvatarUrl:  cmdResp.CsAvatarUrl,
+		CsSignature:  cmdResp.CsSignature,
+		OnlineStatus: cmdResp.OnlineStatus,
 	}, nil
 }

+ 19 - 5
bff/apibff/internal/logic/player/cmd/playerfetchhistorymsglogic.go

@@ -2,9 +2,10 @@ package cmd
 
 import (
 	"context"
-
+	"ylink/apis/cmd/pb"
 	"ylink/bff/apibff/internal/svc"
 	"ylink/bff/apibff/internal/types"
+	"ylink/ext/ctxdata"
 
 	"github.com/zeromicro/go-zero/core/logx"
 )
@@ -23,8 +24,21 @@ func NewPlayerFetchHistoryMsgLogic(ctx context.Context, svcCtx *svc.ServiceConte
 	}
 }
 
-func (l *PlayerFetchHistoryMsgLogic) PlayerFetchHistoryMsg(req *types.PlayerFetchHistoryMsgReq) (resp *types.CommResp, err error) {
-	// todo: add your logic here and delete this line
-
-	return
+func (l *PlayerFetchHistoryMsgLogic) PlayerFetchHistoryMsg(req *types.PlayerFetchHistoryMsgReq) (resp *types.PlayerFetchHistoryMsgResp, err error) {
+	playerId := ctxdata.GetPlayerIdFromCtx(l.ctx)
+	gameId := ctxdata.GetGameIdFromCtx(l.ctx)
+	cmdResp, err := l.svcCtx.CmdRpc.PlayerFetchHistoryMsg(l.ctx, &pb.PlayerFetchHistoryMsgReq{
+		PlayerId: playerId,
+		GameId:   gameId,
+		Page:     req.Page,
+		Limit:    req.Limit,
+	})
+	if err != nil {
+		return nil, err
+	}
+	return &types.PlayerFetchHistoryMsgResp{
+		TotalPage:   cmdResp.TotalPage,
+		CurrentPage: cmdResp.CurrentPage,
+		List:        cmdResp.List.AsSlice(),
+	}, nil
 }

+ 15 - 4
bff/apibff/internal/logic/player/cmd/playerfetchmsglogic.go

@@ -2,6 +2,8 @@ package cmd
 
 import (
 	"context"
+	"ylink/apis/cmd/pb"
+	"ylink/ext/ctxdata"
 
 	"ylink/bff/apibff/internal/svc"
 	"ylink/bff/apibff/internal/types"
@@ -23,8 +25,17 @@ func NewPlayerFetchMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Pl
 	}
 }
 
-func (l *PlayerFetchMsgLogic) PlayerFetchMsg() (resp *types.CommResp, err error) {
-	// todo: add your logic here and delete this line
-
-	return
+func (l *PlayerFetchMsgLogic) PlayerFetchMsg() (resp *types.PlayerFetchMsgResp, err error) {
+	playerId := ctxdata.GetGameIdFromCtx(l.ctx)
+	gameId := ctxdata.GetGameIdFromCtx(l.ctx)
+	cmdResp, err := l.svcCtx.CmdRpc.PlayerFetchMsg(l.ctx, &pb.PlayerFetchMsgReq{
+		PlayerId: playerId,
+		GameId:   gameId,
+	})
+	if err != nil {
+		return nil, err
+	}
+	return &types.PlayerFetchMsgResp{
+		List: cmdResp.List.AsSlice(),
+	}, nil
 }

+ 12 - 4
bff/apibff/internal/logic/player/cmd/playersendmsglogic.go

@@ -2,6 +2,8 @@ package cmd
 
 import (
 	"context"
+	"ylink/apis/cmd/pb"
+	"ylink/ext/ctxdata"
 
 	"ylink/bff/apibff/internal/svc"
 	"ylink/bff/apibff/internal/types"
@@ -23,8 +25,14 @@ func NewPlayerSendMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Pla
 	}
 }
 
-func (l *PlayerSendMsgLogic) PlayerSendMsg(req *types.PlayerSendMsgReq) (resp *types.CommResp, err error) {
-	// todo: add your logic here and delete this line
-
-	return
+func (l *PlayerSendMsgLogic) PlayerSendMsg(req *types.PlayerSendMsgReq) error {
+	playerId := ctxdata.GetPlayerIdFromCtx(l.ctx)
+	gameId := ctxdata.GetGameIdFromCtx(l.ctx)
+	_, err := l.svcCtx.CmdRpc.PlayerSendMsg(l.ctx, &pb.PlayerSendMsgReq{
+		PlayerId: playerId,
+		GameId:   gameId,
+		Content:  req.Content,
+		Pic:      req.Pic,
+	})
+	return err
 }

+ 33 - 0
bff/apibff/internal/middleware/player2ctxmiddleware.go

@@ -0,0 +1,33 @@
+package middleware
+
+import (
+	"context"
+	"github.com/golang-jwt/jwt/v4"
+	"net/http"
+	"ylink/ext/globalkey"
+	"ylink/ext/jwtdata"
+)
+
+type Player2CtxMiddleware struct {
+}
+
+func NewPlayer2CtxMiddleware() *Player2CtxMiddleware {
+	return &Player2CtxMiddleware{}
+}
+
+func (m *Player2CtxMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		accessToken := r.Header.Get("Authorization")
+		ctx := r.Context()
+		token, _ := jwt.Parse(accessToken, func(token *jwt.Token) (i interface{}, err error) {
+			return []byte(globalkey.AccessSecret), nil
+		})
+		// 将获取的token中的Claims强转为MapClaims
+		claims, _ := token.Claims.(jwt.MapClaims)
+		playerId := claims[jwtdata.JwtKeyPlayerId]
+		gameId := claims[jwtdata.JwtKeyGameId]
+		ctx = context.WithValue(ctx, jwtdata.JwtKeyPlayerId, playerId)
+		ctx = context.WithValue(ctx, jwtdata.JwtKeyGameId, gameId)
+		next(w, r.WithContext(ctx))
+	}
+}

+ 11 - 4
bff/apibff/internal/svc/servicecontext.go

@@ -1,19 +1,26 @@
 package svc
 
 import (
+	"github.com/zeromicro/go-zero/rest"
 	"github.com/zeromicro/go-zero/zrpc"
 	"ylink/apis/cmd/cmd"
 	"ylink/bff/apibff/internal/config"
+	"ylink/bff/apibff/internal/middleware"
+	"ylink/ext/globalkey"
 )
 
 type ServiceContext struct {
-	Config config.Config
-	CmdRpc cmd.Cmd
+	Config     config.Config
+	CmdRpc     cmd.Cmd
+	Player2Ctx rest.Middleware
 }
 
 func NewServiceContext(c config.Config) *ServiceContext {
+	globalkey.AccessSecret = c.JwtAuth.AccessSecret
+	globalkey.AccessExpire = c.JwtAuth.AccessExpire
 	return &ServiceContext{
-		Config: c,
-		CmdRpc: cmd.NewCmd(zrpc.MustNewClient(c.CmdRpc)),
+		Config:     c,
+		CmdRpc:     cmd.NewCmd(zrpc.MustNewClient(c.CmdRpc)),
+		Player2Ctx: middleware.NewPlayer2CtxMiddleware().Handle,
 	}
 }

+ 40 - 8
bff/apibff/internal/types/types.go

@@ -1,19 +1,31 @@
 // Code generated by goctl. DO NOT EDIT.
 package types
 
-type CommResp struct {
-	Code int64       `json:"code"`
-	Msg  string      `json:"msg"`
-	Data interface{} `json:"data"`
-}
-
 type PlayerFetchCsInfoReq struct {
 	CsId string `json:"cs_id"`
 }
 
+type PlayerFetchCsInfoResp struct {
+	CsId         string `json:"cs_id"`
+	CsNickname   string `json:"cs_nickname"`
+	CsAvatarUrl  string `json:"cs_avatar_url"`
+	CsSignature  string `json:"cs_signature"`
+	OnlineStatus int64  `json:"online_status"`
+}
+
 type PlayerFetchHistoryMsgReq struct {
-	Page  int `json:"page"`
-	Limit int `json:"limit"`
+	Page  int64 `json:"page"`
+	Limit int64 `json:"limit"`
+}
+
+type PlayerFetchHistoryMsgResp struct {
+	TotalPage   int64         `json:"total_page"`
+	CurrentPage int64         `json:"current_page"`
+	List        []interface{} `json:"list"`
+}
+
+type PlayerFetchMsgResp struct {
+	List []interface{} `json:"list"`
 }
 
 type PlayerSendMsgReq struct {
@@ -25,6 +37,10 @@ type CsFetchPlayerQueueReq struct {
 	Limit int `json:"limit"`
 }
 
+type CsFetchPlayerQueueResp struct {
+	List []interface{} `json:"list"`
+}
+
 type CsConnectPlayerReq struct {
 	PlayerId string `json:"player_id"`
 	GameId   string `json:"game_id"`
@@ -35,6 +51,12 @@ type CsFetchHistoryChatReq struct {
 	Limit int `json:"limit"`
 }
 
+type CsFetchHistoryChatResp struct {
+	TotalPage   int64         `json:"total_page"`
+	CurrentPage int64         `json:"current_page"`
+	List        []interface{} `json:"list"`
+}
+
 type CsFetchHistoryMsgReq struct {
 	PlayerId string `json:"player_id"`
 	GameId   string `json:"game_id"`
@@ -42,11 +64,21 @@ type CsFetchHistoryMsgReq struct {
 	Limit    int    `json:"limit"`
 }
 
+type CsFetchHistoryMsgResp struct {
+	TotalPage   int64         `json:"total_page"`
+	CurrentPage int64         `json:"current_page"`
+	List        []interface{} `json:"list"`
+}
+
 type CsFetchMsgReq struct {
 	PlayerId string `json:"player_id"`
 	GameId   string `json:"game_id"`
 }
 
+type CsFetchMsgResp struct {
+	List []interface{} `json:"list"`
+}
+
 type CsSendMsgReq struct {
 	PlayerId string `json:"player_id"`
 	GameId   string `json:"game_id"`

+ 25 - 0
ext/ctxdata/ctxdata.go

@@ -0,0 +1,25 @@
+//@File     ctxdata.go
+//@Time     2022/04/27
+//@Author   #Suyghur,
+
+package ctxdata
+
+import (
+	"context"
+	"ylink/ext/jwtdata"
+)
+
+func GetPlayerIdFromCtx(ctx context.Context) string {
+	playerId, _ := ctx.Value(jwtdata.JwtKeyPlayerId).(string)
+	return playerId
+}
+
+func GetGameIdFromCtx(ctx context.Context) string {
+	gameId, _ := ctx.Value(jwtdata.JwtKeyGameId).(string)
+	return gameId
+}
+
+func GetCsIdFromJwt(ctx context.Context) string {
+	csId, _ := ctx.Value(jwtdata.JwtKeyCsId).(string)
+	return csId
+}

+ 2 - 3
ext/globalkey/rediskey.go

@@ -4,6 +4,5 @@
 
 package globalkey
 
-const (
-	CacheTokenKey = "token:%s"
-)
+var AccessSecret string
+var AccessExpire int64

+ 0 - 17
ext/jwtdata/jwtdata.go

@@ -4,25 +4,8 @@
 
 package jwtdata
 
-import "context"
-
 const (
 	JwtKeyPlayerId = "jwt_player_id"
 	JwtKeyGameId   = "jwt_game_id"
 	JwtKeyCsId     = "jwt_cs_id"
 )
-
-func GetPlayerIdFromJwt(ctx context.Context) string {
-	playerId, _ := ctx.Value(JwtKeyPlayerId).(string)
-	return playerId
-}
-
-func GetGameIdFromJwt(ctx context.Context) string {
-	gameId, _ := ctx.Value(JwtKeyGameId).(string)
-	return gameId
-}
-
-func GetCsIdFromJwt(ctx context.Context) string {
-	csId, _ := ctx.Value(JwtKeyCsId).(string)
-	return csId
-}

+ 39 - 0
ext/result/err.go

@@ -0,0 +1,39 @@
+//@File     err.go
+//@Time     2022/04/26
+//@Author   #Suyghur,
+
+package result
+
+import "fmt"
+
+/**
+常用通用固定错误
+*/
+
+type CodeError struct {
+	errCode int64
+	errMsg  string
+}
+
+func (e *CodeError) GetErrCode() int64 {
+	return e.errCode
+}
+
+func (e *CodeError) GetErrMsg() string {
+	return e.errMsg
+}
+
+func (e *CodeError) Error() string {
+	return fmt.Sprintf("code:%d,msg:%s", e.errCode, e.errMsg)
+}
+
+func NewErrCodeMsg(code int64, msg string) *CodeError {
+	return &CodeError{errCode: code, errMsg: msg}
+}
+func NewErrCode(errCode int64) *CodeError {
+	return &CodeError{errCode: errCode, errMsg: MapErrMsg(errCode)}
+}
+
+func NewErrMsg(errMsg string) *CodeError {
+	return &CodeError{errCode: ServerCommonError, errMsg: errMsg}
+}

+ 20 - 0
ext/result/errcode.go

@@ -0,0 +1,20 @@
+//@File     errcode.go
+//@Time     2022/04/26
+//@Author   #Suyghur,
+
+package result
+
+const (
+	Ok                 int64 = 0
+	ServerCommonError  int64 = 10001
+	RequestParamError  int64 = 10002
+	TokenExpireError   int64 = 10003
+	TokenParseError    int64 = 10004
+	TokenGenerateError int64 = 10005
+	DbError            int64 = 10006
+)
+
+/**
+前2位代表业务,后3位代表具体功能
+**/
+const ()

+ 33 - 0
ext/result/errmsg.go

@@ -0,0 +1,33 @@
+//@File     errmsg.go
+//@Time     2022/04/26
+//@Author   #Suyghur,
+
+package result
+
+var message map[int64]string
+
+func init() {
+	message = make(map[int64]string)
+	message[Ok] = "success"
+	message[ServerCommonError] = "some unknown error has occurred"
+	message[RequestParamError] = "request params error"
+	message[TokenExpireError] = "the token is invalid, please re-authenticate"
+	message[TokenGenerateError] = "failed to generate token"
+	message[DbError] = "database is busy, please try again late"
+}
+
+func MapErrMsg(code int64) string {
+	if msg, ok := message[code]; ok {
+		return msg
+	} else {
+		return "some unknown error has occurred"
+	}
+}
+
+func IsCodeErr(code int64) bool {
+	if _, ok := message[code]; ok {
+		return true
+	} else {
+		return false
+	}
+}

+ 49 - 0
ext/result/httpresult.go

@@ -0,0 +1,49 @@
+//@File     httpresult.go
+//@Time     2022/04/26
+//@Author   #Suyghur,
+
+package result
+
+import (
+	"fmt"
+	"github.com/pkg/errors"
+	"github.com/zeromicro/go-zero/core/logx"
+	"github.com/zeromicro/go-zero/rest/httpx"
+	"google.golang.org/grpc/status"
+	"net/http"
+)
+
+func HttpResult(r *http.Request, w http.ResponseWriter, resp interface{}, err error) {
+	if err == nil {
+		// 成功返回
+		result := Success(resp)
+		httpx.WriteJson(w, http.StatusOK, result)
+	} else {
+		code := ServerCommonError
+		msg := "some unknown error has occurred"
+
+		cause := errors.Cause(err)
+		if e, ok := cause.(*CodeError); ok {
+			code = e.GetErrCode()
+			msg = e.GetErrMsg()
+		} else {
+			if gStatus, ok := status.FromError(cause); ok {
+				grpcCode := int64(gStatus.Code())
+				if IsCodeErr(grpcCode) {
+					code = grpcCode
+					msg = gStatus.Message()
+				} else {
+
+				}
+			}
+		}
+
+		logx.WithContext(r.Context()).Errorf("[API ERROR] : %+v", err)
+		httpx.WriteJson(w, http.StatusBadRequest, Error(code, msg))
+	}
+}
+
+func ParamErrorResult(r *http.Request, w http.ResponseWriter, err error) {
+	msg := fmt.Sprintf("%s ,%s", MapErrMsg(RequestParamError), err.Error())
+	httpx.WriteJson(w, http.StatusBadRequest, Error(RequestParamError, msg))
+}

+ 22 - 0
ext/result/responsebean.go

@@ -0,0 +1,22 @@
+//@File     responsebean.go
+//@Time     2022/04/26
+//@Author   #Suyghur,
+
+package result
+
+type ResponseBean struct {
+	Code int64       `json:"code"`
+	Msg  string      `json:"msg"`
+	Data interface{} `json:"data"`
+}
+
+func Success(data interface{}) *ResponseBean {
+	if data == nil {
+		data = map[string]interface{}{}
+	}
+	return &ResponseBean{0, "success", data}
+}
+
+func Error(code int64, msg string) *ResponseBean {
+	return &ResponseBean{code, msg, map[string]interface{}{}}
+}

+ 3 - 2
go.mod

@@ -1,8 +1,10 @@
 module ylink
 
-go 1.17
+go 1.18
 
 require (
+	github.com/golang-jwt/jwt/v4 v4.2.0
+	github.com/pkg/errors v0.9.1
 	github.com/zeromicro/go-zero v1.3.1
 	google.golang.org/grpc v1.44.0
 	google.golang.org/protobuf v1.27.1
@@ -19,7 +21,6 @@ require (
 	github.com/go-logr/stdr v1.2.2 // indirect
 	github.com/go-redis/redis/v8 v8.11.4 // indirect
 	github.com/gogo/protobuf v1.3.2 // indirect
-	github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
 	github.com/golang/mock v1.6.0 // indirect
 	github.com/golang/protobuf v1.5.2 // indirect
 	github.com/google/go-cmp v0.5.6 // indirect

Some files were not shown because too many files changed in this diff