Exemplo n.º 1
0
        /// <summary>
        /// 邀请码进入
        /// </summary>
        private void InviteQRHandler()
        {
            try
            {
                //教师邀请
                if (_EventKey.StartsWith(WxConfig.QR_Invite_TecPre))
                {
                    var wxUser = WXApi.GetWXUserInfo(_wxMessage.FromUserName);
                    var user   = _UserSrv.AddOrUpdateFromWXUser(wxUser);
                    _TecSrv.NewTecFromUser(user);
                    _ResultMsg = _wxMessage.toText(WXReplyContent.NewTec(user.Name));
                }
                else if (_EventKey.StartsWith(WxConfig.QR_Invite_User))
                {
                    var ownOpenId = _EventKey.Split("_")[2];

                    var user = _BusinessSrv.InvitedUserComing(_wxMessage.FromUserName, ownOpenId);

                    _ResultMsg = _wxMessage.toText(WXReplyContent.NewUserAdd(user.Name));
                }
            }
            catch (Exception ex)
            {
                NLogHelper.ErrorTxt($"[InviteQRHandler]-FromUserName:{_wxMessage.FromUserName}| 信息:{ex.Message}");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 被邀请用户首次进入公众号,绑定关系
        /// wxUser 因为获取方式不同
        /// </summary>
        /// <param name="wxMessage"></param>
        /// <param name="ownOpenId"></param>
        /// <returns></returns>
        public EUserInfo InvitedUserComing(string InvitedOpenId, string ownOpenId, WXUserInfo wxUser = null)
        {
            UserSrv   userSrv  = new UserSrv(_dbContext);
            SalesSrv  salesSrv = new SalesSrv(_dbContext);
            EUserInfo user     = null;

            try
            {
                if (wxUser == null)
                {
                    wxUser = WXApi.GetWXUserInfo(InvitedOpenId);
                }
            }
            catch (Exception ex)
            {
                NLogHelper.ErrorTxt($"businessSrv-[InvitedUserComing] -GetWXUserInfo Error:{ex.Message}");
                throw ex;
            }


            EUserInfo owner = null;

            try
            {
                //如果是老用户,不能绑定邀请
                if (!userSrv.IsExistUser(InvitedOpenId))
                {
                    owner = salesSrv.BindUser(ownOpenId, InvitedOpenId);
                }
            }
            catch (Exception ex)
            {
                NLogHelper.ErrorTxt($"businessSrv-[InvitedUserComing] -BindUser Error:{ex.Message}");
                throw ex;
            }

            try
            {
                user = userSrv.AddOrUpdateFromWXUser(wxUser, owner, false);
            }
            catch (Exception ex)
            {
                NLogHelper.ErrorTxt($"businessSrv-[InvitedUserComing] -AddOrUpdateFromWXUser Error:{ex.Message}");
                throw ex;
            }


            _dbContext.SaveChanges();
            return(user);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 关注
        /// </summary>
        private void SubscribeHandler()
        {
            NLogHelper.InfoTxt("SubscribeHandler In");
            EUserInfo ui = _UserSrv.GetUserInfo(_wxMessage.FromUserName);

            if (ui == null)
            {
                var wxUser = WXApi.GetWXUserInfo(_wxMessage.FromUserName);
                ui = _UserSrv.AddOrUpdateFromWXUser(wxUser);

                _ResultMsg = _wxMessage.toText(WXReplyContent.NewUserAdd(ui.wx_Name));
            }
            else
            {
                _ResultMsg = _wxMessage.toText(WXReplyContent.UserComing(ui.wx_Name));
            }
        }