Ejemplo n.º 1
0
        protected override void AttachChildControls()
        {
            this.CheckSendRedEnvelope();
            this.hdAppId         = (HiddenField)this.FindControl("hdAppId");
            this.hdTimestamp     = (HiddenField)this.FindControl("hdTimestamp");
            this.hdNonceStr      = (HiddenField)this.FindControl("hdNonceStr");
            this.hdSignature     = (HiddenField)this.FindControl("hdSignature");
            this.hdTitle         = (HiddenField)this.FindControl("hdTitle");
            this.hdDesc          = (HiddenField)this.FindControl("hdDesc");
            this.hdImgUrl        = (HiddenField)this.FindControl("hdImgUrl");
            this.hdLink          = (HiddenField)this.FindControl("hdLink");
            this.hdSendCode      = (HiddenField)this.FindControl("hdSendCode");
            this.hdRedEnvelopeId = (HiddenField)this.FindControl("hdRedEnvelopeId");
            this.hdOrderId       = (HiddenField)this.FindControl("hdOrderId");
            this.hdAppId.Value   = base.site.WeixinAppId;
            string jsApiTicket = base.GetJsApiTicket(true);
            string text        = WAPTemplatedWebControl.GenerateNonceStr();
            string text2       = WAPTemplatedWebControl.GenerateTimeStamp();
            string absoluteUri = this.Page.Request.Url.AbsoluteUri;

            this.hdTimestamp.Value = text2;
            this.hdNonceStr.Value  = text;
            this.hdSignature.Value = base.GetSignature(jsApiTicket, text, text2, absoluteUri);
            WeiXinRedEnvelopeInfo openedWeiXinRedEnvelope = WeiXinRedEnvelopeProcessor.GetOpenedWeiXinRedEnvelope();
            string text3 = this.orderId;
            int    id    = openedWeiXinRedEnvelope.Id;
            RedEnvelopeSendRecord redEnvelopeSendRecord = WeiXinRedEnvelopeProcessor.GetRedEnvelopeSendRecord(text3, id.ToString());
            Guid guid;

            if (redEnvelopeSendRecord != null)
            {
                this.hdRedEnvelopeId.Value = redEnvelopeSendRecord.RedEnvelopeId.ToString();
                this.hdTitle.Value         = openedWeiXinRedEnvelope.Name;
                this.hdDesc.Value          = openedWeiXinRedEnvelope.ShareDetails;
                this.hdImgUrl.Value        = Globals.FullPath(openedWeiXinRedEnvelope.ShareIcon);
                HiddenField hiddenField = this.hdSendCode;
                guid = redEnvelopeSendRecord.SendCode;
                hiddenField.Value    = guid.ToString();
                this.hdLink.Value    = Globals.FullPath("/Vshop/GetRedEnvelope?SendCode=" + this.hdSendCode.Value + "&OrderId=" + this.orderId);
                this.hdOrderId.Value = this.orderId;
            }
            else
            {
                HiddenField hiddenField2 = this.hdRedEnvelopeId;
                id = openedWeiXinRedEnvelope.Id;
                hiddenField2.Value  = id.ToString();
                this.hdTitle.Value  = openedWeiXinRedEnvelope.Name;
                this.hdDesc.Value   = openedWeiXinRedEnvelope.ShareDetails;
                this.hdImgUrl.Value = Globals.FullPath(openedWeiXinRedEnvelope.ShareIcon);
                HiddenField hiddenField3 = this.hdSendCode;
                guid = Guid.NewGuid();
                hiddenField3.Value   = guid.ToString();
                this.hdLink.Value    = Globals.FullPath("/Vshop/GetRedEnvelope?SendCode=" + this.hdSendCode.Value + "&OrderId=" + this.orderId);
                this.hdOrderId.Value = this.orderId;
            }
        }
Ejemplo n.º 2
0
        private bool CheckRedEnvelope(string sendCode, string orderId)
        {
            if (string.IsNullOrEmpty(sendCode))
            {
                this.Page.Response.Redirect("/Vshop/RedEnvelopeError?errorInfo=发送码错误", true);
            }
            if (string.IsNullOrEmpty(orderId))
            {
                NameValueCollection nameValueCollection = new NameValueCollection
                {
                    this.Context.Request.QueryString,
                    this.Context.Request.Form
                };
                nameValueCollection.Add("OrderId1", orderId);
                nameValueCollection.Add("sendCode1", sendCode);
                Globals.AppendLog(nameValueCollection, "", "", "", "CheckRedEnvelope");
                this.Page.Response.Redirect("/Vshop/RedEnvelopeError?errorInfo=订单编号为空", true);
            }
            OrderInfo orderInfo = TradeHelper.GetOrderInfo(orderId);

            if (orderInfo == null)
            {
                this.Page.Response.Redirect("/Vshop/RedEnvelopeError?errorInfo=订单不存在", true);
            }
            RedEnvelopeSendRecord redEnvelopeSendRecord = WeiXinRedEnvelopeProcessor.GetRedEnvelopeSendRecord(Guid.Parse(sendCode), orderId, "");

            if (redEnvelopeSendRecord == null)
            {
                this.Page.Response.Redirect("/Vshop/RedEnvelopeError?errorInfo=发送码不存在", true);
            }
            this.weiXinRedEnvelope = WeiXinRedEnvelopeProcessor.GetWeiXinRedEnvelope(redEnvelopeSendRecord.RedEnvelopeId.Value);
            if (this.weiXinRedEnvelope == null)
            {
                this.Page.Response.Redirect("/Vshop/RedEnvelopeError?errorInfo=红包活动已经被删除", true);
            }
            if (this.weiXinRedEnvelope.State == 0)
            {
                this.Page.Response.Redirect("/Vshop/RedEnvelopeError?errorInfo=红包活动已经关闭", true);
            }
            DateTime now = DateTime.Now;

            if (now > this.weiXinRedEnvelope.ActiveStartTime && this.weiXinRedEnvelope.ActiveEndTime < now)
            {
                this.Page.Response.Redirect("/Vshop/RedEnvelopeError?errorInfo=红包活动没有开始或已过期", true);
            }
            return(true);
        }
Ejemplo n.º 3
0
        protected override void AttachChildControls()
        {
            this.toBuy              = (HtmlAnchor)this.FindControl("toBuy");
            this.toLogin            = (HtmlButton)this.FindControl("toLogin");
            this.divGetList         = (HtmlGenericControl)this.FindControl("divGetList");
            this.toBuy.Visible      = true;
            this.toLogin.Visible    = false;
            this.divGetList.Visible = true;
            string        text          = this.Page.Request["SendCode"];
            string        orderId       = this.Page.Request["OrderId"];
            OAuthUserInfo oAuthUserInfo = this.Context.Session["oAuthUserInfo"] as OAuthUserInfo;

            this.CheckRedEnvelope(text, orderId);
            if (HiContext.Current.UserId > 0 && oAuthUserInfo == null)
            {
                MemberInfo       user             = HiContext.Current.User;
                MemberOpenIdInfo memberOpenIdInfo = user.MemberOpenIds.FirstOrDefault((MemberOpenIdInfo item) => item.OpenIdType.ToLower() == "hishop.plugins.openid.weixin");
                if (memberOpenIdInfo != null)
                {
                    oAuthUserInfo = new OAuthUserInfo();
                    oAuthUserInfo.HeadImageUrl = user.Picture;
                    oAuthUserInfo.IsAttention  = user.IsSubscribe;
                    oAuthUserInfo.NickName     = user.NickName;
                    oAuthUserInfo.OpenId       = memberOpenIdInfo.OpenId;
                    oAuthUserInfo.unionId      = user.UnionId;
                }
            }
            if (oAuthUserInfo == null)
            {
                oAuthUserInfo = base.GetOAuthUserInfo(true);
                if (string.IsNullOrEmpty(oAuthUserInfo.OpenId))
                {
                    Globals.AppendLog("第一次获取用户OpenId失败,错误原因:" + oAuthUserInfo.ErrMsg, "", "", "OAuthUserInfoError");
                    this.Page.Response.Redirect("/Vshop/RedEnvelopeError?errorInfo=授权信息获取失败,请重试", true);
                }
                this.Context.Session["oAuthUserInfo"] = oAuthUserInfo;
            }
            if (string.IsNullOrEmpty(oAuthUserInfo.OpenId))
            {
                this.Page.Response.Redirect("/Vshop/RedEnvelopeError?errorInfo=用户OpenId获取失败,错误原因:" + oAuthUserInfo.ErrMsg, true);
            }
            Guid sendCode = Guid.Parse(text);
            RedEnvelopeGetRecordInfo redEnvelopeGetRecord = this.GetRedEnvelopeGetRecord(oAuthUserInfo, sendCode, orderId);
            int redEnvelopeGetRecordcCount = WeiXinRedEnvelopeProcessor.GetRedEnvelopeGetRecordcCount(this.weiXinRedEnvelope.Id, sendCode, orderId);
            RedEnvelopeGetRecordInfo lastRedEnvelopeGetRecord = WeiXinRedEnvelopeProcessor.GetLastRedEnvelopeGetRecord(oAuthUserInfo.OpenId, sendCode, orderId);
            DateTime dateTime = lastRedEnvelopeGetRecord?.GetTime ?? DateTime.Now.AddDays(-1.0);
            DateTime now      = DateTime.Now;
            bool     flag     = false;
            TimeSpan timeSpan = new TimeSpan(dateTime.Ticks);
            TimeSpan ts       = new TimeSpan(now.Ticks);

            if (timeSpan.Subtract(ts).Duration().TotalSeconds <= 4.0)
            {
                flag = true;
            }
            if (!flag)
            {
                if (redEnvelopeGetRecordcCount >= this.weiXinRedEnvelope.MaxNumber)
                {
                    if (oAuthUserInfo.IsAttention && WeiXinRedEnvelopeProcessor.IsGetInToday(oAuthUserInfo.OpenId, sendCode, true, orderId))
                    {
                        this.Page.Response.Redirect("/Vshop/RedEnvelopePrompt", true);
                    }
                    else
                    {
                        this.Page.Response.Redirect("/Vshop/RedEnvelopeFinish", true);
                    }
                }
                if (WeiXinRedEnvelopeProcessor.IsGetInToday(oAuthUserInfo.OpenId, sendCode, null, orderId))
                {
                    this.Page.Response.Redirect("/Vshop/RedEnvelopePrompt", true);
                }
                if (WeiXinRedEnvelopeProcessor.GetInTodayCount(oAuthUserInfo.OpenId, "", null, "") >= 3)
                {
                    this.Page.Response.Redirect("/Vshop/RedEnvelopePrompt", true);
                }
                if (!oAuthUserInfo.IsAttention)
                {
                    if (!WeiXinRedEnvelopeProcessor.IsGetInToday(oAuthUserInfo.OpenId, sendCode, null, ""))
                    {
                        WeiXinRedEnvelopeProcessor.AddRedEnvelopeGetRecord(redEnvelopeGetRecord);
                        this.AddCouponItemInfo(oAuthUserInfo, redEnvelopeGetRecord);
                    }
                    RedEnvelopeSendRecord redEnvelopeSendRecord = WeiXinRedEnvelopeProcessor.GetRedEnvelopeSendRecord(Guid.Parse(text), "", "");
                    this.Page.Response.Redirect($"AttentionHNYSJY?SendRecordId={redEnvelopeSendRecord.Id}", true);
                }
                else
                {
                    string openId = oAuthUserInfo.OpenId;
                    if (WeiXinRedEnvelopeProcessor.CheckRedEnvelopeGetRecordNoAttentionIsExist(openId))
                    {
                        WeiXinRedEnvelopeProcessor.SetRedEnvelopeGetRecordToAttention(oAuthUserInfo.NickName, oAuthUserInfo.HeadImageUrl, openId);
                    }
                    else
                    {
                        WeiXinRedEnvelopeProcessor.AddRedEnvelopeGetRecord(redEnvelopeGetRecord);
                        this.AddCouponItemInfo(oAuthUserInfo, redEnvelopeGetRecord);
                    }
                }
            }
            this.redEnvelopeAmount       = (Literal)this.FindControl("RedEnvelopeAmount");
            this.redEnvelopeAmount.Text  = (flag ? ((lastRedEnvelopeGetRecord != null) ? lastRedEnvelopeGetRecord.Amount.F2ToString("f2") : "0") : redEnvelopeGetRecord.Amount.F2ToString("f2"));
            this.rptRedEnvelopeGetRecord = (WapTemplatedRepeater)this.FindControl("rptRedEnvelopeGetRecord");
            this.RedEnvelopeGetRecordBind(text);
        }