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); }