createchatsessionlogic.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package logic
  2. import (
  3. quitl "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/internal/svc"
  6. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/internal/types"
  7. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/util"
  8. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
  9. "context"
  10. "fmt"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. "net/http"
  13. )
  14. type CreateChatSessionLogic struct {
  15. logx.Logger
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. r *http.Request
  19. }
  20. func NewCreateChatSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request) *CreateChatSessionLogic {
  21. return &CreateChatSessionLogic{
  22. Logger: logx.WithContext(ctx),
  23. ctx: ctx,
  24. svcCtx: svcCtx,
  25. r: r,
  26. }
  27. }
  28. func (l *CreateChatSessionLogic) CreateChatSession(req *types.ChatSessionReq) (*types.CommonRes, error) {
  29. if req.NewUserId == 0 {
  30. r, err := util.GetTouristInfo(l.r, l.svcCtx.Social, l.ctx)
  31. if err != nil || r.BaseUserId == 0 {
  32. return nil, err
  33. }
  34. req.NewUserId = r.BaseUserId
  35. }
  36. chatMession := &messagecenter.ChatSessionReq{}
  37. if req.UserType == 1 {
  38. //客服信息
  39. if req.MsgType == 5 {
  40. fmt.Println(req.EntUserId, req.EntId)
  41. //客服建立连接
  42. chatMession.AppId = req.AppId
  43. chatMession.CustomerServiceId = quitl.Int64All(req.EntUserId)
  44. chatMession.UserId = quitl.Int64All(encrypt.SE.Decode4Hex(quitl.InterfaceToStr(req.ReceiveId)))
  45. chatMession.EntId = req.EntId
  46. }
  47. } else {
  48. //用户建立会话
  49. if req.MsgType == 4 {
  50. //机器人
  51. chatMession.AppId = req.AppId
  52. chatMession.CustomerServiceId = 0
  53. chatMession.UserId = req.NewUserId
  54. chatMession.EntId = quitl.Int64All(encrypt.SE.Decode4Hex(req.ReceiveEntId))
  55. }
  56. }
  57. chatMession.CustomerserviceName = req.CustomerserviceName
  58. resp, err := l.svcCtx.Message.CreateChatSession(l.ctx, chatMession)
  59. if err != nil {
  60. return nil, err
  61. }
  62. return &types.CommonRes{
  63. Error_msg: resp.ErrorMsg,
  64. Error_code: int(resp.ErrorCode),
  65. Data: resp.SessionId,
  66. }, nil
  67. }