Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }