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); }
public override AbstractResponse OnEvent_SubscribeRequest(SubscribeEventRequest subscribeEventRequest) { string fromUserName = subscribeEventRequest.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"); } ReplyInfo replyInfo = ReplyHelper.GetSubscribeReply(); if (replyInfo == null) { replyInfo = new ReplyInfo(); } replyInfo.Keys = "登录"; if (WeiXinRedEnvelopeProcessor.CheckRedEnvelopeGetRecordNoAttentionIsExist(subscribeEventRequest.FromUserName)) { replyInfo.Keys = "红包"; } if (subscribeEventRequest != null && !string.IsNullOrEmpty(subscribeEventRequest.EventKey) && subscribeEventRequest.EventKey.Split('_').Length == 2) { string text = subscribeEventRequest.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(subscribeEventRequest.FromUserName); if (wXReferral != null && wXReferral.Id > 0) { VShopHelper.UpdateWXReferral(subscribeEventRequest.FromUserName, referralUserId); } else { VShopHelper.AddWXReferral(subscribeEventRequest.FromUserName, referralUserId); } } } else if (text.Contains("shoppingguiderid")) { if (text.Split(':').Length == 2) { int shoppingGuiderId = text.Split(':')[1].ToInt(0); MemberWXShoppingGuiderInfo memberWXShoppingGuider = MemberHelper.GetMemberWXShoppingGuider(subscribeEventRequest.FromUserName); if (memberWXShoppingGuider != null && memberWXShoppingGuider.Id > 0) { MemberHelper.UpdateWXShoppingGuider(subscribeEventRequest.FromUserName, shoppingGuiderId); } else { MemberHelper.AddWXShoppingGuider(subscribeEventRequest.FromUserName, shoppingGuiderId); } } } else { int num = text.ToInt(0); if (num > 0) { RedEnvelopeSendRecord redEnvelopeSendRecordById = WeiXinRedEnvelopeProcessor.GetRedEnvelopeSendRecordById(num); if (redEnvelopeSendRecordById != null && WeiXinRedEnvelopeProcessor.IsGetInToday(subscribeEventRequest.FromUserName, redEnvelopeSendRecordById.SendCode, true, "")) { replyInfo.Keys = "今日已领红包"; } } } } AbstractResponse response = this.GetResponse(replyInfo, subscribeEventRequest.FromUserName, subscribeEventRequest); if (response == null) { return(this.GotoManyCustomerService(subscribeEventRequest)); } response.ToUserName = subscribeEventRequest.FromUserName; response.FromUserName = subscribeEventRequest.ToUserName; return(response); }