/// <summary> /// 注销登录 /// </summary> /// <returns></returns> public ApiResult Logout(RequestUserLogoutDTO request) { using (XuHos.EventBus.MQChannel channel = new EventBus.MQChannel()) { channel.BeginTransaction(); channel.Publish <XuHos.EventBus.Events.UserLogoutedEvent>(new EventBus.Events.UserLogoutedEvent() { LogoutTime = DateTime.Now, UserID = CurrentOperatorUserID, ClientName = request != null ?request.ClientName.IfNull(""):"", UserType = CurrentOperatorUserType, ClientSourceType = CurrentOperatorAppSourceType }); channel.Publish <XuHos.EventBus.Events.UserOperatorLogEvent>(new EventBus.Events.UserOperatorLogEvent() { UserID = CurrentOperatorUserID, OperatorTime = DateTime.Now, UserType = CurrentOperatorUserType, OperatorType = EnumUserOperationType.Logout, OperatorName = "", OrgID = CurrentOperatorOrgID, Remark = "", ModuleName = "" }); channel.Commit(); } XuHos.Service.Infrastructure.SecurityHelper.SignOut(); return(EnumApiStatus.BizOK.ToApiResultForApiStatus()); }
/// <summary> /// 用户登录 /// </summary> /// <param name="user"></param> public ApiResult Login(RequestUserLoginDTO dto) { //检查账号和密码时长正确 var user = CheckLogin(dto); //账号和密码正确 if (user != null && !string.IsNullOrEmpty(user.UserID)) { // 如果指定用户角色,则验证用户角色是否正确 if (dto.UserRole.HasValue) { UserService roleService = new UserService(); List <EnumRoleType> roles = roleService.GetUserRoles(user.UserID); if (!roles.Exists(x => x == dto.UserRole.Value)) { return(EnumApiStatus.BizUserLoginAccountOrPwdFail.ToApiResultForApiStatus()); } } //获取服务端票据 UserLoginServerTicketDTO serverTicket = new UserLoginServerTicketDTO() { OpenID = dto.OpenID, UserID = user.UserID, }; if (serverTicket != null) { var clientTicket = new ResponseUserTicketReturnDTO() { Identifier = user.Identifier, Mobile = user.Mobile, UserID = serverTicket.UserID, UserToken = string.IsNullOrEmpty(dto.UserToken) ? Guid.NewGuid().ToString("N") : dto.UserToken, UserCNName = user.UserCNName, PhotoUrl = user.PhotoUrl, }; ApiSecurityService.SetUserTicket(serverTicket, clientTicket.UserToken); using (XuHos.EventBus.MQChannel channel = new EventBus.MQChannel()) { channel.BeginTransaction(); channel.Publish <XuHos.EventBus.Events.UserLoginedEvent>(new EventBus.Events.UserLoginedEvent() { UserID = clientTicket.UserID, LoginTime = DateTime.Now, UserType = clientTicket.UserType, }); channel.Publish <XuHos.EventBus.Events.UserOperatorLogEvent>(new EventBus.Events.UserOperatorLogEvent() { UserID = clientTicket.UserID, OperatorTime = DateTime.Now, UserType = clientTicket.UserType, OperatorType = EnumUserOperationType.Login, OperatorName = "", OrgID = CurrentOperatorOrgID, Remark = "", ModuleName = "" }); channel.Commit(); } AddUserLoginLog(serverTicket, dto.UserLoginType, dto.Mobile); return(clientTicket.ToApiResultForObject()); } else { return(EnumApiStatus.BizError.ToApiResultForApiStatus("LoginTicket Is Null")); } } else { return(EnumApiStatus.BizUserLoginAccountOrPwdFail.ToApiResultForApiStatus()); #endregion } }
public bool Handle(EventBus.Events.ChannelC2CCreateEvent evt) { try { if (evt == null) { return(true); } if (string.IsNullOrEmpty(evt.FromUserID)) { return(true); } if (evt.AddFriendItem == null || evt.AddFriendItem.Count <= 0) { return(true); } //获取当前用户信息 var FromUserInfo = userService.GetUserInfoByUserId(evt.FromUserID); //用户存在 if (FromUserInfo != null) { var ToUserInfos = new Dictionary <string, ResponseUserDTO>(); //创建房间请求参数 var createC2CChannelRequest = new BLL.Sys.DTOs.Request.RequestConversactionApplyAddFriendDTO() { FromUserIdentifier = FromUserInfo.identifier, FromUserMemberID = FromUserInfo.MemberID, FromUserType = FromUserInfo.UserType, FromUserID = FromUserInfo.UserID, FromUserName = FromUserInfo.UserCNName, AddFriendItem = new List <BLL.Sys.DTOs.Request.RequestConversactionApplyAddFriendDTO.AddFriendAccount>() }; //添加群组请求参数 var requestParamsCreateGroup = new List <int>() { FromUserInfo.identifier }; //添加好友请求参数 var requestParamsApplyAddFriend = new List <XuHos.Integration.QQCloudy.Models.AddFriendAccount>(); //循环好友项 evt.AddFriendItem.ForEach(a => { //好友好友的信息 var ToUserInfo = userService.GetUserInfoByUserId(a.ToUserID); //好友存在 if (ToUserInfo != null) { createC2CChannelRequest.AddFriendItem.Add(new BLL.Sys.DTOs.Request.RequestConversactionApplyAddFriendDTO.AddFriendAccount() { AddType = "Add_Type_Both", AddWording = a.AddWording, ForceAddFlags = 1, GroupName = a.GroupName, Remark = a.Remark, ToUserID = ToUserInfo.UserID, ToUserIdentifier = ToUserInfo.identifier, ToUserMemberID = ToUserInfo.MemberID, ToUserType = ToUserInfo.UserType, ToUserName = ToUserInfo.UserCNName }); requestParamsApplyAddFriend.Add(new XuHos.Integration.QQCloudy.Models.AddFriendAccount { AddWording = a.AddWording, AddSource = "AddSource_Type_WEB",//需要前缀AddSource_Type_ GroupName = a.GroupName, Remark = a.Remark, To_Account = ToUserInfo.identifier.ToString() }); requestParamsCreateGroup.Add(ToUserInfo.identifier); } }); //写入数据库 var ChannelInfoList = roomService.ApplyAddFriend(createC2CChannelRequest); using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel()) { mqChannel.BeginTransaction(); foreach (var item in ChannelInfoList) { var room = item.Value; //根据Uid 获取好友信息 var friend = requestParamsApplyAddFriend.Find(a => a.To_Account == item.Key.ToString()); //如果房间还未启用才调用请求否则忽略 if (!room.Enable) { //发送好友附言消息 if (!mqChannel.Publish <EventBus.Events.ChannelSendGroupMsgEvent <string> >(new EventBus.Events.ChannelSendGroupMsgEvent <string>() { ChannelID = room.ChannelID, FromAccount = FromUserInfo.identifier, Msg = friend.AddWording })) { return(false); } //发布房间创建完成的领域消息 if (!mqChannel.Publish <EventBus.Events.ChannelCreatedEvent>(new EventBus.Events.ChannelCreatedEvent() { ChannelID = room.ChannelID, ServiceID = room.ServiceID, ServiceType = room.ServiceType })) { return(false); } //新增好友 if (!imHelper.ApplyAddFriend(FromUserInfo.identifier.ToString(), requestParamsApplyAddFriend)) { return(false); } //创建群组 if (!imHelper.CreateGroup(room.ChannelID, room.ChannelID.ToString(), room.ServiceType, requestParamsCreateGroup, "", "")) { return(false); } //设置房间已经启用 room.Enable = true; //更新房间状态 if (!roomService.CompareAndSetChannelInfo(room)) { return(false); } } } mqChannel.Commit(); } return(true); } } catch (Exception E) { LogHelper.WriteError(E); } return(false); }