Ejemplo n.º 1
0
        /// <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());
        }
Ejemplo n.º 2
0
        public ApiResult SendAudioMessage(BLL.Sys.DTOs.Request.RequestSendAudioDTO request)
        {
            var fileIndexService = new SysFileIndexService(CurrentOperatorUserID);
            var fileIndex        = fileIndexService.Single <SysFileIndex>(a => a.MD5 == request.FileMD5);

            if (fileIndex != null)
            {
                using (XuHos.EventBus.MQChannel channel = new EventBus.MQChannel())
                {
                    return(channel.Publish <EventBus.Events.ChannelSendGroupMsgEvent <ResponseUserFileDTO> >(new EventBus.Events.ChannelSendGroupMsgEvent <ResponseUserFileDTO>()
                    {
                        ChannelID = request.ChannelID,
                        FromAccount = CurrentOperatorUserIdentifier,
                        Msg = new ResponseUserFileDTO()
                        {
                            FileUrl = $"{fileIndex.FileType}/{fileIndex.FileUrl}",
                            FileID = fileIndex.MD5,
                            FileName = fileIndex.FileUrl,
                            FileType = 2,
                            OutID = "",
                            Remark = ""
                        }
                    }).ToApiResultForBoolean());
                }
            }
            else
            {
                return(EnumApiStatus.BizError.ToApiResultForApiStatus());
            }
        }
Ejemplo n.º 3
0
        public ApiResult SendImageMessage(BLL.Sys.DTOs.Request.RequestSendImageDTO request)
        {
            XuHos.Integration.QQCloudy.IMHelper bll = new XuHos.Integration.QQCloudy.IMHelper();
            SysFileIndexService fileIndexService    = new SysFileIndexService(CurrentOperatorUserID);
            var file = fileIndexService.Single <SysFileIndex>(a => a.MD5 == request.FileMD5);

            if (CurrentOperatorUserIdentifier <= 0)
            {
                throw new ArgumentException($"user {CurrentOperatorUserID} Identifier<=0");
            }

            using (XuHos.EventBus.MQChannel channel = new EventBus.MQChannel())
            {
                return(channel.Publish <EventBus.Events.ChannelSendGroupMsgEvent <ResponseUserFileDTO> >(new EventBus.Events.ChannelSendGroupMsgEvent <ResponseUserFileDTO>()
                {
                    ChannelID = request.ChannelID,
                    FromAccount = CurrentOperatorUserIdentifier,
                    Msg = new ResponseUserFileDTO()
                    {
                        FileUrl = $"{file.FileType}/{file.FileUrl}",
                        FileID = file.MD5,
                        FileName = file.FileUrl,
                        FileType = 0,
                        OutID = "",
                        Remark = ""
                    }
                }).ToApiResultForBoolean());
            }
        }
Ejemplo n.º 4
0
 public ApiResult SendEnterRoomNotify([FromBody] RequestSendEnterRoomNotifyDTO request)
 {
     using (XuHos.EventBus.MQChannel channel = new EventBus.MQChannel())
     {
         return(channel.Publish <EventBus.Events.ChannelEnteredEvent>(new EventBus.Events.ChannelEnteredEvent()
         {
             ChannelID = request.ChannelID,
             UserID = CurrentOperatorUserID
         }, 0, 600000).ToApiResultForBoolean());
     }
 }
Ejemplo n.º 5
0
 public ApiResult SendTextMessage(BLL.Sys.DTOs.Request.RequestSendTextDTO request)
 {
     using (XuHos.EventBus.MQChannel channel = new EventBus.MQChannel())
     {
         return(channel.Publish <EventBus.Events.ChannelSendGroupMsgEvent <string> >(new EventBus.Events.ChannelSendGroupMsgEvent <string>()
         {
             ChannelID = request.ChanndlID,
             FromAccount = CurrentOperatorUserIdentifier,
             Msg = request.Content
         }).ToApiResultForBoolean());
     }
 }
Ejemplo n.º 6
0
 public ApiResult Add([FromBody] BLL.Doctor.DTOs.Request.RequestServiceEvaluationDTO request)
 {
     using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
     {
         return(mqChannel.Publish(new EventBus.Events.OrderEvaluationEvent()
         {
             Content = request.Content,
             EvaluationTags = request.EvaluationTags,
             OuterID = request.OuterID,
             Score = request.Score,
             CreateUserID = CurrentOperatorUserID
         }).ToApiResultForBoolean());
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 更新微信支付状态

        /// 日期:2016年6月25日
        /// </summary>
        /// <param name="OrderNo">订单编号</param>
        /// <returns></returns>
        bool updateWxPayStatus(string OrderNo, string SellerID)
        {
            XuHos.BLL.OrderService service = new OrderService(CurrentOperatorUserID);

            var result = XuHos.Common.Pay.WxPay.OrderQuery.Run("", OrderNo, SellerID);

            if (result.GetValue("result_code").ToString() == "SUCCESS")
            {
                var trade_state = result.GetValue("trade_state").ToString();//订单状态

                //尚未支付
                if (trade_state == "NOTPAY")
                {
                    return(false);
                }

                var transaction_id = result.GetValue("transaction_id").ToString();             //交易编号
                var total_fee      = int.Parse(result.GetValue("total_fee").ToString()) * 100; //转化成元

                //已支付
                if (trade_state == "SUCCESS")
                {
                    using (XuHos.EventBus.MQChannel mqChanne = new EventBus.MQChannel())
                    {
                        return(mqChanne.Publish <EventBus.Events.OrderPayNotifyEvent>(new EventBus.Events.OrderPayNotifyEvent()
                        {
                            OrderNo = OrderNo,
                            TradeNo = transaction_id,
                            PayType = EnumPayType.WxPay,
                            SelllerID = SellerID
                        }));
                    }
                }

                return(false);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
        void PublishEvent()
        {
            if (AttachEvents.Count > 0)
            {
                try
                {
                    using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                    {
                        var dict = AttachEvents.ToDictionary(a => a.EventID, a => new Dictionary <string, string>()
                        {
                            { "Body", a.EventObject },
                            { "EventTypeName", a.RouteKey }
                        });

                        mqChannel.Publish(dict, (EventIds) =>
                        {
                            this.SysEvents.Where(a => !a.Enqueued && EventIds.Contains(a.EventID)).Update(a => new SysEvent()
                            {
                                Enqueued = true
                            });
                        }, (EventIds) =>
                        {
                            this.SysEvents.Where(a => !a.Enqueued && EventIds.Contains(a.EventID)).Update(a => new SysEvent()
                            {
                                Enqueued = false
                            });
                        }, (EventIds) =>
                        {
                            this.SysEvents.Where(a => !a.Enqueued && EventIds.Contains(a.EventID)).Update(a => new SysEvent()
                            {
                                Enqueued = false
                            });
                        });
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 用户注册(新)
        /// </summary>
        /// <param name="model"></param>
        public bool RegisterUser(XuHos.Entity.User model, out string Reason,
                                 string openid = null, string appid = null)
        {
            Reason = "注册失败";
            var password = model.Password;
            var result   = true;

            try
            {
                #region 检查是否支持此类型的用户注册
                if (model.UserType != EnumUserType.Doctor && model.UserType != EnumUserType.User &&
                    model.UserType != EnumUserType.SysAdmin)
                {
                    Reason = "不支持的用户类型";
                    return(false);
                }
                #endregion


                using (DBEntities db = new DBEntities())
                {
                    #region 用户信息
                    if (string.IsNullOrEmpty(model.UserID))
                    {
                        model.UserID = Guid.NewGuid().ToString("N");
                    }

                    //密码
                    model.Password = StringEncrypt.EncryptWithMD5(model.Password);
                    //用户状态
                    model.UserState = EnumUserState.Disabled;

                    db.Users.Add(model);

                    UserExtend userExtend = new UserExtend();
                    userExtend.UserID   = model.UserID;
                    userExtend.LastTime = DateTime.Now;

                    db.UserExtends.Add(userExtend);

                    if (!string.IsNullOrEmpty(openid))
                    {
                        UserWechatMap userWechatMap = new UserWechatMap();
                        userWechatMap.UserID = model.UserID;
                        userWechatMap.OpenID = openid;
                        userWechatMap.AppID  = appid;
                        db.UserWechatMaps.Add(userWechatMap);
                    }

                    #endregion

                    #region 家庭成员
                    UserMember userMember = null;
                    if (model.UserType == EnumUserType.User)
                    {
                        userMember          = new UserMember();
                        userMember.MemberID = Guid.NewGuid().ToString("N");

                        if (!string.IsNullOrEmpty(model.Mobile))
                        {
                            userMember.Mobile = model.Mobile;
                        }
                        else
                        {
                            userMember.Mobile = "";
                        }

                        userMember.UserID     = model.UserID;
                        userMember.IDType     = EnumUserCardType.IDCard;
                        userMember.Address    = "";
                        userMember.Birthday   = "";
                        userMember.Email      = "";
                        userMember.Gender     = EnumUserGender.Other;
                        userMember.IsDefault  = true;
                        userMember.Marriage   = EnumUserMaritalStatus.Other;
                        userMember.MemberName = model.UserCNName;
                        userMember.PostCode   = "";
                        userMember.Relation   = EnumUserRelation.MySelf;
                        db.UserMembers.Add(userMember);
                    }
                    #endregion

                    #region 用户标识
                    db.ConversationIMUids.Add(new ConversationIMUid()
                    {
                        Identifier = Convert.ToInt32(WaterNoService.GetWaterNo(EnumWaterNoType.Identify)),
                        Enable     = false,
                        IsDeleted  = false,
                        CreateTime = DateTime.Now,
                        UserID     = model.UserID
                    });
                    #endregion

                    if (db.SaveChanges() >= 0)
                    {
                        #region 将注册消息写入队列,队列中发送短信和注册云通信
                        using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                        {
                            mqChannel.Publish <EventBus.Events.UserRegisteredEvent>(new EventBus.Events.UserRegisteredEvent()
                            {
                                UserAccount  = model.UserAccount,
                                UserID       = model.UserID,
                                UserPassword = password,
                                UserType     = model.UserType,
                                OrgCode      = model.OrgCode,
                                Mobile       = model.Mobile,
                            });
                        }
                        #endregion

                        result = true;
                        Reason = "注册成功";
                    }
                    else
                    {
                        Reason = "注册失败";
                    }
                }
            }
            catch (Exception ex)
            {
                Reason = "系统错误";
                result = false;
                throw ex;
            }
            return(result);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 创建聊天的房间
        /// </summary>
        /// <param name="OPDRegisterID"></param>
        /// <returns></returns>
        public bool CreateIMRoom(string OPDRegisterID)
        {
            try
            {
                using (DAL.EF.DBEntities db = new DBEntities())
                {
                    var model = (from opd in db.UserOpdRegisters.Where(a => a.OPDRegisterID == OPDRegisterID)
                                 join user in db.Users on opd.UserID equals user.UserID
                                 join member in db.UserMembers on opd.MemberID equals member.MemberID
                                 select new
                    {
                        OPDType = opd.OPDType,
                        DoctorID = opd.DoctorID,             //opd.DoctorID,
                        UserID = opd.UserID,
                        MemberID = opd.MemberID,
                        member.MemberName,
                        user.PhotoUrl,
                        user.UserCNName,
                        user.UserENName
                    }).FirstOrDefault();


                    if (model != null)
                    {
                        #region 创建IM群组
                        XuHos.Integration.QQCloudy.IMHelper imservice    = new XuHos.Integration.QQCloudy.IMHelper();
                        ConversationIMUidService            imUidService = new ConversationIMUidService(CurrentOperatorUserID);
                        var roomService = new BLL.Sys.Implements.ConversationRoomService();

                        BLL.Doctor.Implements.DoctorService doctorService = new Doctor.Implements.DoctorService();

                        //房间信息
                        var room = roomService.GetChannelInfo(OPDRegisterID);

                        if (room != null)
                        {
                            var GroupName      = model.OPDType.GetEnumDescript();
                            var Introduction   = "";
                            var Notification   = "";
                            var groupMembers   = new List <int>();
                            var channelMembers = new List <RequestChannelMemberDTO>();

                            //患者信息
                            var userIdentifier = imUidService.GetUserIMUid(model.UserID);
                            if (userIdentifier > 0)
                            {
                                groupMembers.Add(userIdentifier);
                                channelMembers.Add(new RequestChannelMemberDTO()
                                {
                                    Identifier   = userIdentifier,
                                    UserType     = EnumUserType.User,
                                    UserID       = model.UserID,
                                    UserMemberID = model.MemberID,
                                    PhotoUrl     = model.PhotoUrl,
                                    UserCNName   = model.MemberName,
                                    UserENName   = model.MemberName
                                });
                            }

                            //获取医生信息(如果走导诊系统,此时还未分配医生,分诊后才会把分诊医生加入到IM组)
                            if (!string.IsNullOrEmpty(model.DoctorID))
                            {
                                var doctorInfo       = doctorService.GetDoctorInfo(model.DoctorID);
                                var doctorIdentifier = imUidService.GetDoctorIMUid(model.DoctorID);
                                if (doctorIdentifier > 0)
                                {
                                    groupMembers.Add(doctorIdentifier);
                                    channelMembers.Add(new RequestChannelMemberDTO()
                                    {
                                        Identifier   = doctorIdentifier,
                                        UserID       = doctorInfo.UserID,
                                        UserType     = EnumUserType.Doctor,
                                        UserMemberID = doctorInfo.User.MemberID,
                                        PhotoUrl     = doctorInfo.User._PhotoUrl,//DTO已经进行了路径转换,这里需要使用没有转换之前的数据
                                        UserENName   = doctorInfo.DoctorEnName,
                                        UserCNName   = doctorInfo.DoctorName
                                    });
                                }
                            }

                            if (room.Enable)
                            {
                                if (imservice.AddGroupMember(room.ChannelID, groupMembers))
                                {
                                    return(roomService.InsertChannelMembers(room.ChannelID, channelMembers));
                                }
                            }
                            else
                            {
                                //创建裙子成功
                                if (imservice.CreateGroup(room.ChannelID, GroupName, model.OPDType, groupMembers, Introduction, Notification))
                                {
                                    using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                                    {
                                        if (mqChannel.Publish <EventBus.Events.ChannelCreatedEvent>(new EventBus.Events.ChannelCreatedEvent()
                                        {
                                            ChannelID = room.ChannelID,
                                            ServiceID = room.ServiceID,
                                            ServiceType = room.ServiceType
                                        }))
                                        {
                                            room.Enable = true;

                                            if (roomService.CompareAndSetChannelInfo(room))
                                            {
                                                return(roomService.InsertChannelMembers(room.ChannelID, channelMembers));
                                            }
                                        }
                                        else
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            return(true);
                        }

                        #endregion
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            //出现数据库并发更新异常需要重试
            catch (DbUpdateConcurrencyException ex)
            {
                return(CreateIMRoom(OPDRegisterID));
            }

            return(false);
        }
Ejemplo n.º 12
0
        public bool Handle(EventBus.Events.OrderPayCompletedEvent evt)
        {
            var LockName = $"{typeof(SendBizNotice)}:{evt.OrderNo}";

            var lockValue = Guid.NewGuid().ToString("N");

            //获取分布式锁,获取锁失败时进行锁等待(锁超时时间5秒)
            if (LockName.Lock(lockValue, TimeSpan.FromSeconds(5)))
            {
                try
                {
                    #region 发送业务通知
                    var opd = opdService.Single(evt.OrderOutID);
                    #region 需分诊的订单,等分诊后再处理
                    if (opd.DoctorTriage.IsToGuidance == true)
                    {
                        return(true);
                    }
                    #endregion

                    if (opd != null)
                    {
                        var noticeType  = EnumNoticeSecondType.AllNotice;
                        var ServiceType = EnumDoctorServiceType.VidServiceType;

                        //图文消息
                        if (evt.OrderType == EnumProductType.ImageText)
                        {
                            noticeType  = EnumNoticeSecondType.DoctorPicNotice;
                            ServiceType = EnumDoctorServiceType.PicServiceType;
                        }
                        //家庭医生
                        else if (evt.OrderType == EnumProductType.FamilyDoctor)
                        {
                            noticeType  = EnumNoticeSecondType.DoctorFamilyNotice;
                            ServiceType = EnumDoctorServiceType.FamilyDoctor;
                        }
                        //语音或视频咨询
                        else if (evt.OrderType == EnumProductType.video)
                        {
                            noticeType  = EnumNoticeSecondType.DoctorVidNotice;
                            ServiceType = EnumDoctorServiceType.VidServiceType;
                        }
                        //语音或视频咨询
                        else if (evt.OrderType == EnumProductType.Phone)
                        {
                            noticeType  = EnumNoticeSecondType.DoctorVidNotice;
                            ServiceType = EnumDoctorServiceType.AudServiceType;
                        }
                        //远程会诊
                        else if (evt.OrderType == EnumProductType.Consultation)
                        {
                            noticeType  = EnumNoticeSecondType.DoctorConsulNotice;
                            ServiceType = EnumDoctorServiceType.Consultation;
                        }


                        using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                        {
                            return(mqChannel.Publish <EventBus.Events.UserNoticeEvent>(new EventBus.Events.UserNoticeEvent()
                            {
                                NoticeType = noticeType,
                                ServiceID = evt.OrderOutID,
                                ServiceType = ServiceType
                            }));
                        }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    Common.LogHelper.WriteError(ex);
                    return(false);
                }
                finally
                {
                    LockName.UnLock(lockValue);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 13
0
        public HttpResponseMessage NotifyUrl()
        {
            var Request = System.Web.HttpContext.Current.Request;
            var content = "";

            try
            {
                LogHelper.WriteDebug("Cashier/AliPay/NotifyUrl", Request.Params.ToJson());
                SortedDictionary <string, string> sPara = GetRequestPost();

                if (sPara.Count > 0)//判断是否有带返回参数
                {
                    //通知编号
                    string seller_id = Request.Form["seller_id"];
                    //商户订单号
                    string out_trade_no = Request.Form["out_trade_no"];
                    //支付宝交易号
                    string trade_no = Request.Form["trade_no"];
                    //交易状态
                    string trade_status = Request.Form["trade_status"];
                    //总金额
                    string total_fee = Request["total_fee"];
                    //通知编号
                    string notify_id = Request.Form["notify_id"];

                    //签名
                    string sign = Request.Form["sign"];

                    var alipay = new WebPay(seller_id);

                    if ((trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS") && alipay.VerifySign(sPara, notify_id, sign))//验证成功
                    {
                        using (XuHos.EventBus.MQChannel mqChanne = new EventBus.MQChannel())
                        {
                            if (mqChanne.Publish <EventBus.Events.OrderPayNotifyEvent>(new EventBus.Events.OrderPayNotifyEvent()
                            {
                                OrderNo = out_trade_no,
                                TradeNo = trade_no,
                                PayType = EnumPayType.AliPay,
                                SelllerID = seller_id
                            }))
                            {
                                content = "success";
                            }
                        }
                    }
                }

                content = "fail";
            }
            catch (Exception E)
            {
                LogHelper.WriteError(E);
                content = "fail";
            }

            //返回处理结果
            return(new HttpResponseMessage
            {
                Content = new StringContent(content, Encoding.GetEncoding("UTF-8"), "text/plain")
            });
        }
Ejemplo n.º 14
0
        public void ListernHeartBeat()
        {
            var userTypes = Enum.GetNames(typeof(EnumUserType));

            //订阅缓存过期
            XuHos.Common.Cache.Manager.Instance.Subscribe($"__keyevent@{getDbNum(userOnLineStateDbNum)}__:expired", cacheKey =>
            {
                var service = new XuHos.BLL.Sys.Implements.HeartbeatService();
                XuHos.Common.LogHelper.WriteDebug("缓存过期:" + cacheKey);

                var key = cacheKey.ToString();


                System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(
                    $".*:" + XuHos.Common.Cache.Keys.StringCacheKeyType.Heartbeat_Web + ":(?<UserID>.*)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                var match = reg.Match(key);
                if (match?.Success == true)
                {
                    XuHos.Common.LogHelper.WriteInfo("用户心跳缓存过期:" + key);
                    if (match.Groups["UserID"].Success)
                    {
                        var UserID = match.Groups["UserID"].Value;
                        foreach (var userType in userTypes)
                        {
                            Manager.Instance.SetRemove(new XuHos.Common.Cache.Keys.StringCacheKey(StringCacheKeyType.Heartbeat_Web, $"OnlineSet:{userType}").KeyName, UserID);
                            Manager.Instance.SetRemove(new XuHos.Common.Cache.Keys.StringCacheKey(StringCacheKeyType.Heartbeat_App, $"OnlineSet:{userType}").KeyName, UserID);
                        }
                    }
                }
            });

            //订阅缓存过期 __keyevent@0__:expired
            XuHos.Common.Cache.Manager.Instance.Subscribe($"__keyevent@{getDbNum(userTypeStateDbNum)}__:expired", cacheKey =>
            {
                try
                {
                    var service = new XuHos.BLL.Sys.Implements.HeartbeatService();
                    XuHos.Common.LogHelper.WriteDebug("缓存过期:" + cacheKey);

                    var key = cacheKey.ToString();


                    System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(
                        $".*:" + XuHos.Common.Cache.Keys.StringCacheKeyType.Heartbeat_Web + ":(?<UserID>.*):(?<Type>.*):(?<ChannelID>.*)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

                    if (reg.IsMatch(key))
                    {
                        var group = reg.Match(key);

                        XuHos.Common.LogHelper.WriteInfo("用户心跳缓存过期:" + key);

                        if (group.Groups.Count >= 3)
                        {
                            //匹配成功
                            if (group.Groups["UserID"].Success && group.Groups["Type"].Success && group.Groups["ChannelID"].Success)
                            {
                                var UserID    = group.Groups["UserID"].Value;
                                var Type      = group.Groups["Type"].Value;
                                var ChannelID = group.Groups["ChannelID"].Value;

                                using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                                {
                                    mqChannel.Publish <EventBus.Events.ChannelStateChangedEvent>(new EventBus.Events.ChannelStateChangedEvent()
                                    {
                                        ChannelID    = int.Parse(ChannelID),
                                        FromUserID   = UserID,
                                        FromPlatform = "WEB",
                                        State        = EnumRoomState.Disconnection
                                    });
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteError(ex);
                }
            });
        }
Ejemplo n.º 15
0
        public dynamic CallBack(
            string SdkAppid,
            string CallbackCommand,
            string ClientIP,
            string OptPlatform,
            [FromBody] dynamic model)
        {
            try
            {
                //发单聊消息之前回调 https://www.qcloud.com/doc/product/269/1632
                if (CallbackCommand == "C2C.CallbackBeforeSendMsg")
                {
                    /*{
                     *  "CallbackCommand": "C2C.CallbackBeforeSendMsg",  // 回调命令
                     *  "From_Account": "jared",  // 发送者
                     *  "To_Account": "Jonh",  // 接收者
                     *  "MsgBody": [  // 消息体,参见TIMMessage消息对象
                     *      {
                     *          "MsgType": "TIMTextElem", // 文本
                     *          "MsgContent": {
                     *              "Text": "red packet"
                     *          }
                     *      }
                     *  ]
                     * }*/

                    //TODO:过滤垃圾消息,修改用户的消息,记录日志
                }
                //发单聊消息之后回调 https://www.qcloud.com/doc/product/269/2716
                else if (CallbackCommand == "C2C.CallbackAfterSendMsg")
                {
                    /*{
                     *  "CallbackCommand": "C2C.CallbackAfterSendMsg",  // 回调命令
                     *  "From_Account": "jared",  // 发送者
                     *  "To_Account": "Jonh",  // 接收者
                     *  "MsgBody": [  // 消息体,参见TIMMessage消息对象
                     *      {
                     *          "MsgType": "TIMTextElem", // 文本
                     *          "MsgContent": {
                     *              "Text": "red packet"
                     *          }
                     *      }
                     *  ]
                     * }*/
                }
                //群内发言之前回调 https://www.qcloud.com/doc/product/269/1619
                else if (CallbackCommand == "Group.CallbackBeforeSendMsg")
                {
                    #region 群内发言之前回调

                    /*{
                     *  "CallbackCommand": "Group.CallbackBeforeSendMsg",  // 回调命令
                     *  "GroupId": "@TGS#2J4SZEAEL",  // 群组ID
                     *  "Type": "Public",  // 群组类型
                     *  "From_Account": "jared",  // 发送者
                     *  "Operator_Account":"admin", //请求的发起者
                     *  "Random": 123456,  // 随机数
                     *  "MsgBody": [  // 消息体,参见TIMMessage消息对象
                     *      {
                     *          "MsgType": "TIMTextElem", // 文本
                     *          "MsgContent": {
                     *              "Text": "red packet"
                     *          }
                     *      }
                     *  ]
                     * }*/

                    //群组编号
                    int GroupId = model.GroupId;
                    //房间编号
                    int ChannelID = GroupId;
                    //发送者
                    string From_Account = model.From_Account;
                    //消息主题内容
                    dynamic MsgBody = model.MsgBody;

                    string MsgSeq = Guid.NewGuid().ToString("N");

                    if (From_Account != null)
                    {
                        ConversationMessage[] messages = new ConversationMessage[MsgBody.Count];
                        BLL.Sys.Implements.ConversationRoomService bllRoom = new BLL.Sys.Implements.ConversationRoomService();
                        //获取房间
                        var room = bllRoom.GetChannelInfo(ChannelID);

                        if (room != null)
                        {
                            #region 记录聊天日志

                            int i = 0;
                            foreach (var msg in MsgBody)
                            {
                                var msgType = msg.MsgType;
                                var content = Newtonsoft.Json.JsonConvert.SerializeObject(msg);
                                messages[i] = new ConversationMessage();
                                messages[i].ConversationMessageID = Guid.NewGuid().ToString("N");
                                messages[i].ConversationRoomID    = GroupId;      //房间
                                messages[i].MessageContent        = content;      //内容
                                messages[i].MessageState          = 0;            //消息状态
                                messages[i].MessageTime           = DateTime.Now; //消息发送时间
                                messages[i].MessageType           = msgType;      //消息发送类型 TIMTextElem/TIMImageElem/TIMCustomElem
                                messages[i].ServiceID             = room.ServiceID;
                                messages[i].UserID       = From_Account.ToString();
                                messages[i].MessageSeq   = MsgSeq;
                                messages[i].MessageIndex = i;
                                i++;
                            }

                            using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                            {
                                if (mqChannel.Publish <EventBus.Events.ChannelNewMsgEvent>(new EventBus.Events.ChannelNewMsgEvent()
                                {
                                    ChannelID = GroupId,
                                    ServiceID = room.ServiceID,
                                    ServiceType = room.ServiceType,
                                    FromAccount = From_Account,
                                    Messages = messages,
                                    OptPlatform = OptPlatform
                                }))
                                {
                                    // 0为允许发言
                                    return(new { ActionStatus = "OK", ErrorInfo = "", ErrorCode = 0 });
                                }
                                else
                                {
                                    // 0为允许发言
                                    return(new { ActionStatus = "OK", ErrorInfo = "", ErrorCode = 1 });
                                }
                            }

                            #endregion
                        }
                    }

                    #endregion
                }
                //群内发言之后回调 https://www.qcloud.com/doc/product/269/2661
                else if (CallbackCommand == "Group.CallbackAfterSendMsg")
                {
                    /*{
                     *  "CallbackCommand": "Group.CallbackAfterSendMsg",  // 回调命令
                     *  "GroupId": "@TGS#2J4SZEAEL",  // 群组ID
                     *  "Type": "Public",  // 群组类型
                     *  "From_Account": "jared",  // 发送者
                     *  "MsgBody": [  // 消息体,参见TIMMessage消息对象
                     *      {
                     *          "MsgType": "TIMTextElem", // 文本
                     *          "MsgContent": {
                     *              "Text": "red packet"
                     *          }
                     *      }
                     *  ]
                     * }*/
                }
                //状态变更回调 https://www.qcloud.com/doc/product/269/2570
                else if (CallbackCommand == "State.StateChange")
                {
                    /*{
                     *  "CallbackCommand": "State.StateChange",
                     *      "Info": {
                     *          "Action": "Logout",
                     *          "To_Account": "testuser316",
                     *          "Reason": "Unregister"
                     *      }
                     * }
                     */
                    var Action     = model.Info.Action;
                    var To_Account = model.Info.To_Account;

                    using (XuHos.EventBus.MQChannel mqChannel = new EventBus.MQChannel())
                    {
                        if (mqChannel.Publish <EventBus.Events.UserOnlineStateChangedEvent>(new EventBus.Events.UserOnlineStateChangedEvent()
                        {
                            Action = Action,
                            UserID = To_Account,
                        }))
                        {
                            // 0为允许发言
                            return(new { ActionStatus = "OK", ErrorInfo = "", ErrorCode = 0 });
                        }
                        else
                        {
                            // 0为允许发言
                            return(new { ActionStatus = "OK", ErrorInfo = "", ErrorCode = 1 });
                        }
                    }
                }

                //正常返回
                return(new { ActionStatus = "OK", ErrorInfo = "", ErrorCode = 0 });
            }
            catch (Exception E)
            {
                LogHelper.WriteError(E.GetDetailException());

                return(new { ActionStatus = "OK", ErrorInfo = E.GetDetailException().StackTrace, ErrorCode = 0 });
            }
        }
Ejemplo n.º 16
0
        public ApiResult SetRoomState([FromBody] BLL.Sys.DTOs.Request.RequestConversationRoomSetStateDTO request)
        {
            try
            {
                var roomService = new BLL.Sys.Implements.ConversationRoomService();
                var room        = roomService.GetChannelInfo(request.ChannelID);

                #region 记录操作日志
                EnumUserOperationType?type = null;
                switch (room.ServiceType)
                {
                case EnumDoctorServiceType.VidServiceType:
                    type = EnumUserOperationType.EnterVidService;
                    break;

                case EnumDoctorServiceType.AudServiceType:
                    type = EnumUserOperationType.EnterAudService;
                    break;

                case EnumDoctorServiceType.PicServiceType:
                    type = EnumUserOperationType.EnterPicService;
                    break;
                }
                switch (request.State)
                {
                case EnumRoomState.InMedicalTreatment:
                    break;

                case EnumRoomState.Disconnection:
                    if (type.HasValue)
                    {
                        type = type.Value + 1;
                    }
                    break;

                default:
                    type = null;
                    break;
                }
                if (type.HasValue)
                {
                    using (XuHos.EventBus.MQChannel channel = new EventBus.MQChannel())
                    {
                        channel.Publish <XuHos.EventBus.Events.UserOperatorLogEvent>(new EventBus.Events.UserOperatorLogEvent()
                        {
                            UserID       = CurrentOperatorUserID,
                            OperatorTime = DateTime.Now,
                            UserType     = CurrentOperatorUserType,
                            OperatorType = type.Value,
                            OperatorName = type.Value.GetEnumDescript(),
                            OrgID        = CurrentOperatorOrgID,
                            Remark       = "",
                            ModuleName   = ""
                        });
                    }
                }
                #endregion

                //期望的房间状态
                var ExpectedState = request.ExpectedState.HasValue ? request.ExpectedState.Value: room.RoomState; //如果客户端没有指定期望的状态则系统获取(兼容之前版本)

                //并集并交换房间状态(如果设置失败则返回最新的状态)
                var ret = roomService.CompareAndSetChannelState(request.ChannelID,
                                                                CurrentOperatorUserID,
                                                                request.State,
                                                                request.DisableWebSdkInteroperability,
                                                                ref ExpectedState);

                return(ret.ToApiResultForApiStatus(ExpectedState));
            }
            catch (Exception ex)
            {
                XuHos.Common.LogHelper.WriteError(ex);
                return(EnumApiStatus.BizError.ToApiResultForApiStatus(ex.Message));
            }
        }
Ejemplo n.º 17
0
        /// <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
            }
        }