diff --git a/config/config.yaml b/config/config.yaml index 0485fab9c..4f1c79279 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -72,6 +72,7 @@ endpoints: rpc_statistic: openim_rpc_statistic rpc_admin_cms: openim_rpc_admin_cms rpc_message_cms: openim_rpc_admin_cms + rpc_office: openim_rpc_office api: openImApiPort: [ 10000 ] #api服务端口,默认即可,需要开放此端口或做nginx转发 @@ -106,6 +107,7 @@ rpcport: #rpc服务端口 默认即可 openImStatisticsPort: [ 10800 ] openImMessageCmsPort: [ 10900 ] openImAdminCmsPort: [ 11000 ] + openImOfficePort: [ 11100 ] c2c: callbackBeforeSendMsg: switch: false @@ -127,6 +129,7 @@ rpcregistername: #rpc注册服务名,默认即可 OpenImStatisticsName: Statistics OpenImMessageCMSName: MessageCMS openImAdminCMSName: AdminCMS + openImOfficeName: Office log: storageLocation: ../logs/ diff --git a/internal/api/office/tag.go b/internal/api/office/tag.go index 23b5d2e54..2491e9f7a 100644 --- a/internal/api/office/tag.go +++ b/internal/api/office/tag.go @@ -4,8 +4,10 @@ import ( apistruct "Open_IM/pkg/base_info" "Open_IM/pkg/common/config" "Open_IM/pkg/common/log" + "Open_IM/pkg/common/token_verify" "Open_IM/pkg/grpc-etcdv3/getcdv3" pbOffice "Open_IM/pkg/proto/office" + pbCommon "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" "context" "github.com/gin-gonic/gin" @@ -25,9 +27,14 @@ func GetUserTags(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()}) return } - if err := utils.CopyStructFields(&reqPb, req); err != nil { - log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) + ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + if !ok { + log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) + return } + reqPb.UserID = userID + reqPb.OperationID = req.OperationID etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName) client := pbOffice.NewOfficeServiceClient(etcdConn) respPb, err := client.GetUserTags(context.Background(), &reqPb) @@ -58,6 +65,13 @@ func CreateTag(c *gin.Context) { if err := utils.CopyStructFields(&reqPb, req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } + ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + if !ok { + log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) + return + } + reqPb.UserID = userID etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName) client := pbOffice.NewOfficeServiceClient(etcdConn) respPb, err := client.CreateTag(context.Background(), &reqPb) @@ -87,6 +101,13 @@ func DeleteTag(c *gin.Context) { if err := utils.CopyStructFields(&reqPb, req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } + ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + if !ok { + log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) + return + } + reqPb.UserID = userID etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName) client := pbOffice.NewOfficeServiceClient(etcdConn) respPb, err := client.DeleteTag(context.Background(), &reqPb) @@ -116,6 +137,13 @@ func SetTag(c *gin.Context) { if err := utils.CopyStructFields(&reqPb, req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } + ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + if !ok { + log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) + return + } + reqPb.UserID = userID etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName) client := pbOffice.NewOfficeServiceClient(etcdConn) respPb, err := client.SetTag(context.Background(), &reqPb) @@ -145,6 +173,13 @@ func SendMsg2Tag(c *gin.Context) { if err := utils.CopyStructFields(&reqPb, req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } + ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + if !ok { + log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) + return + } + reqPb.SendID = userID etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName) client := pbOffice.NewOfficeServiceClient(etcdConn) respPb, err := client.SendMsg2Tag(context.Background(), &reqPb) @@ -171,8 +206,17 @@ func GetTagSendLogs(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()}) return } - if err := utils.CopyStructFields(&reqPb, req); err != nil { - log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) + ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + if !ok { + log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) + return + } + reqPb.UserID = userID + reqPb.OperationID = req.OperationID + reqPb.Pagination = &pbCommon.RequestPagination{ + PageNumber: req.PageNumber, + ShowNumber: req.ShowNumber, } etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName) client := pbOffice.NewOfficeServiceClient(etcdConn) diff --git a/pkg/base_info/office_struct.go b/pkg/base_info/office_struct.go index 85cb86090..154ab89f1 100644 --- a/pkg/base_info/office_struct.go +++ b/pkg/base_info/office_struct.go @@ -2,11 +2,10 @@ package base_info import ( pbOffice "Open_IM/pkg/proto/office" - server_api_params "Open_IM/pkg/proto/sdk_ws" ) type GetUserTagsReq struct { - pbOffice.GetUserTagsReq + OperationID string `json:"operationID"` } type GetUserTagsResp struct { @@ -17,7 +16,9 @@ type GetUserTagsResp struct { } type CreateTagReq struct { - pbOffice.CreateTagReq + TagName string `json:"tagName" binding:"required"` + UserIDList []string `json:"userIDList" binding:"required"` + OperationID string `json:"operationID" binding:"required"` } type CreateTagResp struct { @@ -25,7 +26,8 @@ type CreateTagResp struct { } type DeleteTagReq struct { - pbOffice.DeleteTagReq + TagID string `json:"tagID" binding:"required"` + OperationID string `json:"operationID" binding:"required"` } type DeleteTagResp struct { @@ -33,7 +35,11 @@ type DeleteTagResp struct { } type SetTagReq struct { - pbOffice.SetTagReq + TagID string `json:"tagID" binding:"required"` + NewName string `json:"newName" binding:"required"` + IncreaseUserIDList []string `json:"increaseUserIDList" binding:"required"` + ReduceUserIDList []string `json:"reduceUserIDList" binding:"required"` + OperationID string `json:"operationID" binding:"required"` } type SetTagResp struct { @@ -41,7 +47,11 @@ type SetTagResp struct { } type SendMsg2TagReq struct { - pbOffice.SendMsg2TagReq + TagID string `json:"tagID" binding:"required"` + SenderPlatformID int32 `json:"senderPlatformID" binding:"required"` + Content string `json:"content" binding:"required"` + ContentType int32 `json:"contentType" binding:"required"` + OperationID string `json:"operationID" binding:"required"` } type SendMsg2TagResp struct { @@ -49,9 +59,9 @@ type SendMsg2TagResp struct { } type GetTagSendLogsReq struct { - server_api_params.RequestPagination - UserID string `json:"userID"` - OperationID string `json:"operationID"` + PageNumber int32 `json:"pageNumber" binding:"required"` + ShowNumber int32 `json:"showNumber" binding:"required"` + OperationID string `json:"operationID" binding:"required"` } type GetTagSendLogsResp struct {