public AbstractResponse GetResponse(ReplyInfo reply, string openId, AbstractRequest bstractRequest = null) { if (reply.MessageType == MessageType.Text) { TextReplyInfo textReplyInfo = reply as TextReplyInfo; TextResponse textResponse = new TextResponse(); textResponse.CreateTime = DateTime.Now; if (textReplyInfo != null && !string.IsNullOrEmpty(textReplyInfo.Text)) { textResponse.Content = textReplyInfo.Text; } if (reply.Keys == "登录") { string arg = $"http://{HttpContext.Current.Request.Url.Host}/Vshop/MemberCenter.aspx?SessionId={openId}"; textResponse.Content = textResponse.Content.Replace("$login$", $"<a href=\"{arg}\">一键登录</a>"); } if (reply.Keys == "红包") { string value = ((SubscribeEventRequest)bstractRequest).EventKey.Split('_')[1]; RedEnvelopeSendRecord redEnvelopeSendRecordById = WeiXinRedEnvelopeProcessor.GetRedEnvelopeSendRecordById(Convert.ToInt32(value)); if (redEnvelopeSendRecordById != null) { string arg2 = $"http://{HttpContext.Current.Request.Url.Host}/Vshop/GetRedEnvelope?SendCode={redEnvelopeSendRecordById.SendCode}&OrderId={redEnvelopeSendRecordById.OrderId}"; textResponse.Content += $"<a href=\"{arg2}\">立即领取红包</a>"; } } if (reply.Keys == "今日已领红包") { string arg3 = $"http://{HttpContext.Current.Request.Url.Host}/Vshop/Default.aspx"; textResponse.Content += $"<a href=\"{arg3}\">你今日已领取过了,立即购物</a>"; } if (reply.Keys == "分销注册") { string arg4 = $"http://{HttpContext.Current.Request.Url.Host}/Vshop/ReferralRegister.aspx?again=1"; textResponse.Content += $"感谢您的关注。点击<a href=\"{arg4}\">注册</a>成为本商城分销员,赚取丰厚奖励!"; } return(textResponse); } HttpContext current = HttpContext.Current; NewsResponse newsResponse = new NewsResponse(); newsResponse.CreateTime = DateTime.Now; newsResponse.Articles = new List <Article>(); foreach (NewsMsgInfo item2 in (reply as NewsReplyInfo).NewsMsg) { Article item = new Article { Description = item2.Description, PicUrl = $"{Globals.GetProtocal(current)}://{HttpContext.Current.Request.Url.Host}{item2.PicUrl}", Title = item2.Title, Url = (string.IsNullOrEmpty(item2.Url) ? $"{Globals.GetProtocal(current)}://{HttpContext.Current.Request.Url.Host}/Vshop/ImageTextDetails.aspx?messageId={item2.Id}" : item2.Url) }; newsResponse.Articles.Add(item); } return(newsResponse); }
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; } }
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); }
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); }
public static bool AddRedEnvelopeSendRecord(RedEnvelopeSendRecord redEnvelopeSendRecord) { return(new RedEnvelopeSendRecordDao().Add(redEnvelopeSendRecord, null) > 0); }