Beispiel #1
0
        public override AbstractResponse OnEvent_ScanRequest(ScanEventRequest scanEventRequest)
        {
            ReplyInfo replyInfo    = ReplyHelper.GetSubscribeReply();
            string    fromUserName = scanEventRequest.FromUserName;

            try
            {
                MemberProcessor.UpdateWXUserIsSubscribeStatus(fromUserName, true);
            }
            catch (Exception ex)
            {
                IDictionary <string, string> dictionary = new Dictionary <string, string>();
                dictionary.Add("openId", fromUserName);
                Globals.WriteExceptionLog(ex, dictionary, "UpdateWXUserIsSubscribeStatus");
            }
            if (replyInfo == null)
            {
                replyInfo = new ReplyInfo();
            }
            replyInfo.Keys = "登录";
            if (scanEventRequest != null && !string.IsNullOrEmpty(scanEventRequest.EventKey) && scanEventRequest.EventKey.Split('_').Length >= 2)
            {
                string text = scanEventRequest.EventKey.Split('_')[1];
                if (text == "referralregister")
                {
                    replyInfo.Keys = "分销注册";
                }
                else if (text.Contains("referraluserid"))
                {
                    if (text.Split(':').Length == 2)
                    {
                        int referralUserId = text.Split(':')[1].ToInt(0);
                        MemberWXReferralInfo wXReferral = VShopHelper.GetWXReferral(scanEventRequest.FromUserName);
                        if (wXReferral != null && wXReferral.Id > 0)
                        {
                            VShopHelper.UpdateWXReferral(scanEventRequest.FromUserName, referralUserId);
                        }
                        else
                        {
                            VShopHelper.AddWXReferral(scanEventRequest.FromUserName, referralUserId);
                        }
                    }
                }
                else if (text.Contains("shoppingguiderid") && text.Split(':').Length == 2)
                {
                    int shoppingGuiderId = text.Split(':')[1].ToInt(0);
                    MemberWXShoppingGuiderInfo memberWXShoppingGuider = MemberHelper.GetMemberWXShoppingGuider(scanEventRequest.FromUserName);
                    if (memberWXShoppingGuider != null && memberWXShoppingGuider.Id > 0)
                    {
                        MemberHelper.UpdateWXShoppingGuider(scanEventRequest.FromUserName, shoppingGuiderId);
                    }
                    else
                    {
                        MemberHelper.AddWXShoppingGuider(scanEventRequest.FromUserName, shoppingGuiderId);
                    }
                }
            }
            AbstractResponse response = this.GetResponse(replyInfo, scanEventRequest.FromUserName, scanEventRequest);

            if (response == null)
            {
                return(this.GotoManyCustomerService(scanEventRequest));
            }
            response.ToUserName   = scanEventRequest.FromUserName;
            response.FromUserName = scanEventRequest.ToUserName;
            return(response);
        }
Beispiel #2
0
        protected int SkipWeixinOpenId(string openId, string weixinNickName, string unionId, string headimgurl, string ReferralUserId, bool isSubscribe)
        {
            int        num        = 1;
            MemberInfo memberInfo = MemberProcessor.GetMemberByOpenId("hishop.plugins.openid.weixin", openId);
            bool       flag       = false;

            if (memberInfo == null)
            {
                memberInfo = MemberProcessor.GetMemberByUnionId(unionId);
                flag       = true;
            }
            SiteSettings     masterSettings     = SettingsManager.GetMasterSettings();
            ShoppingCartInfo cookieShoppingCart = ShoppingCartProcessor.GetCookieShoppingCart();
            bool             flag2 = false;

            if (memberInfo != null)
            {
                num = 2;
                if (memberInfo.IsSubscribe != isSubscribe)
                {
                    memberInfo.IsSubscribe = isSubscribe;
                    flag2 = true;
                }
                bool flag3 = MemberProcessor.IsBindedWeixin(memberInfo.UserId, "hishop.plugins.openid.weixin");
                memberInfo.Picture = headimgurl;
                if (!string.IsNullOrEmpty(unionId) && memberInfo.UnionId != unionId && !flag)
                {
                    memberInfo.UnionId = unionId;
                    flag2 = true;
                }
                if (flag)
                {
                    if (!flag3)
                    {
                        MemberOpenIdInfo memberOpenIdInfo = new MemberOpenIdInfo();
                        memberOpenIdInfo.UserId     = memberInfo.UserId;
                        memberOpenIdInfo.OpenIdType = "hishop.plugins.openid.weixin";
                        memberOpenIdInfo.OpenId     = openId;
                        MemberProcessor.AddMemberOpenId(memberOpenIdInfo);
                        memberInfo.IsQuickLogin = true;
                        flag2 = true;
                    }
                    else
                    {
                        MemberOpenIdInfo memberOpenIdInfo2 = new MemberOpenIdInfo();
                        memberOpenIdInfo2.UserId     = memberInfo.UserId;
                        memberOpenIdInfo2.OpenIdType = "hishop.plugins.openid.weixin";
                        memberOpenIdInfo2.OpenId     = openId;
                        MemberProcessor.UpdateMemberOpenId(memberOpenIdInfo2);
                    }
                }
                if (flag2)
                {
                    MemberProcessor.UpdateMember(memberInfo);
                }
                Users.SetCurrentUser(memberInfo.UserId, 30, true, false);
                HiContext.Current.User = memberInfo;
                if (cookieShoppingCart != null)
                {
                    ShoppingCartProcessor.ConvertShoppingCartToDataBase(cookieShoppingCart);
                    ShoppingCartProcessor.ClearCookieShoppingCart();
                }
                if (!string.IsNullOrEmpty(openId))
                {
                    HttpCookie httpCookie = new HttpCookie("openId");
                    httpCookie.HttpOnly = true;
                    httpCookie.Value    = openId;
                    httpCookie.Expires  = DateTime.MaxValue;
                    HttpContext.Current.Response.Cookies.Add(httpCookie);
                }
                lock (this.lockCopyRedEnvelope)
                {
                    this.CopyRedEnvelope(openId, memberInfo);
                }
                return(num);
            }
            memberInfo             = new MemberInfo();
            memberInfo.Picture     = headimgurl;
            memberInfo.IsSubscribe = isSubscribe;
            int num2 = 0;

            if (ReferralUserId.ToInt(0) > 0)
            {
                memberInfo.ReferralUserId = ReferralUserId.ToInt(0);
            }
            MemberWXReferralInfo wXReferral = VShopHelper.GetWXReferral(openId.Trim());

            if (wXReferral != null)
            {
                VShopHelper.DeleteWXReferral(openId.Trim());
            }
            memberInfo.GradeId = MemberProcessor.GetDefaultMemberGrade();
            if (!string.IsNullOrEmpty(weixinNickName))
            {
                MemberInfo memberInfo2 = memberInfo;
                MemberInfo memberInfo3 = memberInfo;
                string     text3       = memberInfo2.UserName = (memberInfo3.NickName = HttpUtility.UrlDecode(weixinNickName));
            }
            if (string.IsNullOrEmpty(memberInfo.UserName))
            {
                memberInfo.UserName = "******" + this.GenerateUsername(8);
            }
            if (MemberProcessor.FindMemberByUsername(memberInfo.UserName) != null)
            {
                memberInfo.UserName = "******" + this.GenerateUsername(9);
                if (MemberProcessor.FindMemberByUsername(memberInfo.UserName) != null)
                {
                    memberInfo.UserName = this.GenerateUsername();
                    if (MemberProcessor.FindMemberByUsername(memberInfo.UserName) != null)
                    {
                        num = -1;
                    }
                }
            }
            if (num == 1)
            {
                string text4 = this.GeneratePassword();
                string text5 = "Open";
                string text6 = text4;
                text4 = (memberInfo.Password = Users.EncodePassword(text4, text5));
                memberInfo.PasswordSalt     = text5;
                memberInfo.RegisteredSource = 3;
                memberInfo.CreateDate       = DateTime.Now;
                memberInfo.IsQuickLogin     = true;
                memberInfo.IsLogined        = true;
                memberInfo.UnionId          = unionId;
                num2 = MemberProcessor.CreateMember(memberInfo);
                if (num2 <= 0)
                {
                    num = -1;
                }
            }
            if (num == 1)
            {
                memberInfo.UserId   = num2;
                memberInfo.UserName = MemberHelper.GetUserName(memberInfo.UserId);
                MemberHelper.Update(memberInfo, true);
                Users.SetCurrentUser(memberInfo.UserId, 30, false, false);
                HiContext.Current.User = memberInfo;
                if (cookieShoppingCart != null)
                {
                    ShoppingCartProcessor.ConvertShoppingCartToDataBase(cookieShoppingCart);
                    ShoppingCartProcessor.ClearCookieShoppingCart();
                }
                if (!string.IsNullOrEmpty(openId))
                {
                    MemberOpenIdInfo memberOpenIdInfo3 = new MemberOpenIdInfo();
                    memberOpenIdInfo3.UserId     = memberInfo.UserId;
                    memberOpenIdInfo3.OpenIdType = "hishop.plugins.openid.weixin";
                    memberOpenIdInfo3.OpenId     = openId;
                    if (MemberProcessor.GetMemberByOpenId(memberOpenIdInfo3.OpenIdType, openId) == null)
                    {
                        MemberProcessor.AddMemberOpenId(memberOpenIdInfo3);
                    }
                    if (!string.IsNullOrEmpty(openId))
                    {
                        HttpCookie httpCookie2 = new HttpCookie("openId");
                        httpCookie2.HttpOnly = true;
                        httpCookie2.Value    = openId;
                        httpCookie2.Expires  = DateTime.MaxValue;
                        HttpContext.Current.Response.Cookies.Add(httpCookie2);
                    }
                    lock (this.lockCopyRedEnvelope)
                    {
                        this.CopyRedEnvelope(openId, memberInfo);
                    }
                }
            }
            return(num);
        }