123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package logic
- import (
- quitl "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/encrypt"
- "context"
- "fmt"
- "github.com/zeromicro/go-zero/core/logx"
- "messagecenter/api/messagecenter/internal/svc"
- "messagecenter/api/messagecenter/internal/types"
- "messagecenter/rpc/messagecenter/messagecenter"
- )
- type CreateChatSessionLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewCreateChatSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateChatSessionLogic {
- return &CreateChatSessionLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
- func (l *CreateChatSessionLogic) CreateChatSession(req *types.ChatSessionReq) (*types.CommonRes, error) {
- chatMession := &messagecenter.ChatSessionReq{}
- if req.UserType == 1 {
- //客服信息
- if req.MsgType == 5 {
- fmt.Println(req.EntUserId, req.EntId)
- //客服建立连接
- chatMession.AppId = req.AppId
- chatMession.CustomerServiceId = quitl.Int64All(req.EntUserId)
- chatMession.UserId = quitl.Int64All(encrypt.SE.Decode4Hex(quitl.InterfaceToStr(req.ReceiveId)))
- chatMession.EntId = req.EntId
- }
- } else {
- //用户建立会话
- if req.MsgType == 4 {
- //机器人
- chatMession.AppId = req.AppId
- chatMession.CustomerServiceId = 0
- chatMession.UserId = req.NewUserId
- chatMession.EntId = quitl.Int64All(encrypt.SE.Decode4Hex(req.ReceiveEntId))
- }
- }
- chatMession.CustomerserviceName = req.CustomerserviceName
- resp, err := l.svcCtx.Message.CreateChatSession(l.ctx, chatMession)
- if err != nil {
- return nil, err
- }
- return &types.CommonRes{
- Error_msg: resp.ErrorMsg,
- Error_code: int(resp.ErrorCode),
- Data: resp.SessionId,
- }, nil
- }
|