예제 #1
0
        public IResponseMessageBase UnsubscribeRequest(AppCtx ctx, RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage <ResponseMessageText>(requestMessage);

            responseMessage.Content = "感谢您的关注,欢迎有空再来";
            return(responseMessage);
        }
예제 #2
0
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseUnScript = base.CreateResponseMessage <ResponseMessageText>();

            responseUnScript.Content = "走了,不送。";
            return(responseUnScript);
        }
        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage(requestMessage, ResponseMsgType.Text) as ResponseMessageText;

            responseMessage.Content = "有空再来";
            return(responseMessage);
        }
        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            AppCtx ctx = AppCtx.Current;

            ctx.SetContextHandler(this);
            return(ctx.GetHandler().UnsubscribeRequest(ctx, requestMessage));
        }
        /// <summary>
        /// 处理取消关注事件
        /// </summary>
        /// <param name="requestMessage">请求消息</param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            SubscribeService ss = new SubscribeService();

            ss.UnSubscribe(requestMessage);
            return(null);
        }
예제 #6
0
        /// <summary>
        /// Event事件类型请求之unsubscribe
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = this.CreateResponseMessage <ResponseMessageText>();

            responseMessage.Content = "感谢您的使用,拜拜!-DSX用于测试的消息";
            return(responseMessage);
        }
        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = base.CreateResponseMessage <ResponseMessageText>();

            responseMessage.Content = "有空再来";
            return(responseMessage);
        }
        /// <summary>
        /// 取消关注
        /// </summary>
        /// <param nickname="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            debug.log("取消关注事件0", requestMessage.FromUserName);
            var result = JULONG.TRAIN.WEB.Models.AccountHelper.WxCancelAttend(requestMessage.FromUserName);

            //debug.log("取消关注事件1", requestMessage.FromUserName);
            return(base.OnEvent_UnsubscribeRequest(requestMessage));
        }
        /// <summary>
        /// 取消关注时间
        /// </summary>
        /// <param name="requestMessage"></param>

        public void UnSubscribe(RequestMessageEvent_Unsubscribe requestMessage)
        {
            OfficialAccount_BLL obll  = new OfficialAccount_BLL();
            OfficialAccount     model = obll.Get(a => a.OriginalID == requestMessage.ToUserName);

            Subscriber_BLL sbll = new Subscriber_BLL();

            if (sbll.GetCount(a => a.OpenID == requestMessage.FromUserName && a.AccountID == model.AccountID) > 0)
            {
                Subscriber sub = sbll.Get(a => a.OpenID == requestMessage.FromUserName && a.AccountID == model.AccountID);
                sub.IsOK            = false;
                sub.UnSubscribeTime = DateTime.Now;
                if (sub.UnSubscribeCount != null)
                {
                    sub.UnSubscribeCount += 1;
                }
                else
                {
                    sub.UnSubscribeCount = 1;
                }
                sub.Score = 0;
                sbll.Update(sub);



                if (sub.FromOpenID != null)
                {
                    //if (sub.UnSubscribeCount > 1)
                    //{


                    Subscriber sup = sbll.Get(a => a.OpenID == sub.FromOpenID && a.AccountID == model.AccountID);

                    if (sup.IsOK == true)
                    {
                        sup.Score -= model.UnSubscribeReduceScore;


                        sup.DirectScore -= model.UnSubscribeReduceScore;


                        sbll.Update(sup);

                        StringBuilder sbparent = new StringBuilder();
                        sbparent.Append("您好,你的粉丝【" + sub.NickName + "】取消关注了本公众号!\n");


                        sbparent.Append("减少积分:" + model.UnSubscribeReduceScore + "分,累计积分:" + sup.Score.ToString() +
                                        "分\n");
                        CustomApi.SendText(model.AppID, sup.OpenID, sbparent.ToString());
                    }



                    //}
                }
            }
        }
예제 #10
0
        /// <summary>
        /// 退订事件
        /// </summary>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = base.CreateResponseMessage <ResponseMessageText>();

            responseMessage.Content = "有空再来";
            return(responseMessage);

            return(new Common.MessageFunction().EventSubscribe(7, requestMessage));
        }
예제 #11
0
        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = base.CreateResponseMessage <ResponseMessageText>();

            var msgUrl    = WebConfigurationManager.AppSettings["URL"];
            var msgResult = Utils.GetRemoteData(msgUrl, "POST", this.RequestDocument.ToString());

            responseMessage.Content = "有空再来";
            return(responseMessage);
        }
예제 #12
0
        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = base.CreateResponseMessage <ResponseMessageText>();

            /* DoraemonYu 2014-10-28:
             * Here:当用户取消关注的时候,是否应该移除数据库的对应关系?
             */

            return(responseMessage);
        }
예제 #13
0
        /// <summary>
        /// 取消关注
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var user = _userService.GetUserById(requestMessage.FromUserName);

            if (user != null)
            {
                user.Subscribe = 0;
                this._userService.UpdateUser(user);
            }
            return(base.OnEvent_UnsubscribeRequest(requestMessage));
        }
        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = base.CreateResponseMessage <ResponseMessageText>();

            //tb_User user = Bll_User.GetUserInfoForOpenId(requestMessage.FromUserName);
            //user.Attach();
            //user.State = 2;
            //Bll_User.UpdateUser(user);
            responseMessage.Content = "有空再来";
            return(responseMessage);
        }
예제 #15
0
        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = base.CreateResponseMessage <ResponseMessageText>();

            responseMessage.Content = "有空再来";
            //记录取消关注用户到数据
            WxUserService wxUserService = new WxUserService();

            wxUserService.Unsubscribe(requestMessage.ToUserName, requestMessage.FromUserName, responseMessage.CreateTime.DateTime);
            return(responseMessage);
        }
예제 #16
0
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = base.CreateResponseMessage <ResponseMessageText>();

            responseMessage.Content = "取消关注";
            var ubll   = new Wx.BLL.UserBLL();
            var openId = requestMessage.FromUserName;

            ubll.Unsubscribe(openId);

            return(responseMessage);
        }
예제 #17
0
        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            MpUser fromUser = MpUserService.GetByOpenID(requestMessage.FromUserName);

            if (fromUser != null)
            {
                fromUser.IsSubscribe   = false;
                fromUser.LastVisitDate = DateTime.Now;
                MpUserService.Update(fromUser);
            }
            return(null);
        }
        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var opid   = requestMessage.FromUserName;
            var entity = entities.Set <MpFans>().Where(c => c.MpID == account.ID && c.OpenID == opid).FirstOrDefault();

            if (entity != null)
            {
                entity.IsFans     = "0";
                entity.UpdateTime = DateTime.Now;
                entities.SaveChanges();
            }
            return(null);
        }
예제 #19
0
 /// <summary>
 ///     退订
 ///     实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
 ///     unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
 /// </summary>
 /// <returns></returns>
 public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
 {
     //更新粉丝信息
     using (var db = new AppDbContext())
     {
         var user = db.WeiChat_Users.FirstOrDefault(p => p.OpenId == requestMessage.FromUserName);
         if (user != null)
         {
             user.Subscribe = false;
             db.SaveChanges();
         }
         //TODO:增加取消关注的日志记录
     }
     return(null);
 }
예제 #20
0
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = base.CreateResponseMessage <ResponseMessageText>();

            responseMessage.Content = "有空再来";
            try
            {
                CrmMemberModel cdb = new CrmMemberModel();
                cdb.DiscardMember(requestMessage.FromUserName, Constants.CompanyId.ToString());
            }
            catch (Exception ex)
            {
                LogException(ex);
            }
            return(responseMessage);
        }
        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var openId   = requestMessage.FromUserName;//获取OpenId
            var userInfo = wx_userService.LoadEntities(u => u.gzh_openid == openId).FirstOrDefault();

            if (userInfo != null)
            {
                userInfo.state            = (int)WXUserState.取消关注;//取消关注
                userInfo.unsubscribe_time = DateTime.Now;
                wx_userService.EditEntity(userInfo);
            }
            var responseMessage = base.CreateResponseMessage <ResponseMessageText>();

            responseMessage.Content = "有空再来";
            return(responseMessage);
        }
예제 #22
0
 /// <summary>
 /// 退订
 /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
 /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
 /// </summary>
 /// <returns></returns>
 public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
 {
     try
     {
         LogHelper.LogInfo(string.Format("退订事件【FromUserName:{0}, Event:{1}】", requestMessage.FromUserName, requestMessage.Event));
         using (var db = data.Entities.NewInstance)
         {
             var tbevent = db.tbevents.Where(p => p.from_username == requestMessage.FromUserName).OrderByDescending(p => p.create_time).FirstOrDefault();
             if (tbevent != null)
             {
                 tbevent.unsubscribe_time = DateTime.Now.Ticks;
             }
             db.SaveChanges();
         }
     }
     catch (Exception es)
     {
         LogHelper.LogError(es);
     }
     return(base.OnEvent_UnsubscribeRequest(requestMessage));;
 }
 /// <summary>
 /// 取消关注
 /// </summary>
 private void MessageHandler_OnUnsubscribe(object sender, RequestMessageEvent_Unsubscribe e)
 {
     AsyncHelper.RunSync(async() =>
     {
         try
         {
             var user = await _wechatUserRepository.GetAll().Where(w => w.OpenId == e.FromUserName).FirstOrDefaultAsync();
             if (user != null)//修改状态
             {
                 user.BindStatus = BindStatus.取消关注;
                 user.UnBindTime = DateTime.Now;
                 await _wechatUserRepository.UpdateAsync(user);
                 await CurrentUnitOfWork.SaveChangesAsync();
             }
         }
         catch (Exception ex)
         {
             Logger.ErrorFormat("取消关注公众号异常:{0}", ex);
         }
     });
 }
예제 #24
0
 /// <summary>
 /// 退订
 /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
 /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
 /// </summary>
 /// <returns></returns>
 public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
 {
     return(EventProcess(7, requestMessage));
 }
예제 #25
0
 //<?xml version="1.0" encoding="utf-8"?>
 //<xml>
 //  <ToUserName><![CDATA[gh_a96a4a619366]]></ToUserName>
 //  <FromUserName><![CDATA[olPjZjsXuQPJoV0HlruZkNzKc91E]]></FromUserName>
 //  <CreateTime>1357986928</CreateTime>
 //  <MsgType><![CDATA[text]]></MsgType>
 //  <Content><![CDATA[中文]]></Content>
 //  <MsgId>5832509444155992350</MsgId>
 //</xml>
 /// <summary>
 /// 获取XDocument转换后的IRequestMessageBase实例。
 /// 如果MsgType不存在,抛出UnknownRequestMsgTypeException异常
 /// </summary>
 /// <returns></returns>
 public static IRequestMessageBase GetRequestEntity(XDocument doc)
 {
     RequestMessageBase requestMessage = null;
     RequestMsgType msgType;
     try
     {
         msgType = MsgTypeHelper.GetRequestMsgType(doc);
         switch (msgType)
         {
             case RequestMsgType.Text:
                 requestMessage = new RequestMessageText();
                 break;
             case RequestMsgType.Location:
                 requestMessage = new RequestMessageLocation();
                 break;
             case RequestMsgType.Image:
                 requestMessage = new RequestMessageImage();
                 break;
             case RequestMsgType.Voice:
                 requestMessage = new RequestMessageVoice();
                 break;
             case RequestMsgType.Video:
                 requestMessage = new RequestMessageVideo();
                 break;
             case RequestMsgType.Link:
                 requestMessage = new RequestMessageLink();
                 break;
             case RequestMsgType.Event:
                 //判断Event类型
                 switch (doc.Root.Element("Event").Value.ToUpper())
                 {
                     case "ENTER"://进入会话
                         requestMessage = new RequestMessageEvent_Enter();
                         break;
                     case "LOCATION"://地理位置
                         requestMessage = new RequestMessageEvent_Location();
                         break;
                     case "SUBSCRIBE"://订阅(关注)
                         requestMessage = new RequestMessageEvent_Subscribe();
                         break;
                     case "UNSUBSCRIBE"://取消订阅(关注)
                         requestMessage = new RequestMessageEvent_Unsubscribe();
                         break;
                     case "CLICK"://菜单点击
                         requestMessage = new RequestMessageEvent_Click();
                         break;
                     case "SCAN"://二维码扫描
                         requestMessage = new RequestMessageEvent_Scan();
                         break;
                     case "VIEW"://URL跳转
                         requestMessage = new RequestMessageEvent_View();
                         break;
                     case "MASSSENDJOBFINISH":
                         requestMessage = new RequestMessageEvent_MassSendJobFinish();
                         break;
                     default://其他意外类型(也可以选择抛出异常)
                         requestMessage = new RequestMessageEventBase();
                         break;
                 }
                 break;
             default:
                 throw new UnknownRequestMsgTypeException(string.Format("MsgType:{0} 在RequestMessageFactory中没有对应的处理程序!", msgType), new ArgumentOutOfRangeException());//为了能够对类型变动最大程度容错(如微信目前还可以对公众账号suscribe等未知类型,但API没有开放),建议在使用的时候catch这个异常
         }
         EntityHelper.FillEntityWithXml(requestMessage, doc);
     }
     catch (ArgumentException ex)
     {
         throw new WXException(string.Format("RequestMessage转换出错!可能是MsgType不存在!,XML:{0}", doc.ToString()), ex);
     }
     return requestMessage;
 }
예제 #26
0
        /// <summary>
        /// 获取请求XML
        /// </summary>
        /// <returns></returns>
        private XDocument GetrequestMessaageDoc(string url, string token, RequestMsgType requestType, Event? eventType)
        {
            RequestMessageBase requestMessaage = null;
            switch (requestType)
            {
                case RequestMsgType.Text:
                    requestMessaage = new RequestMessageText()
                    {
                        Content = Request.Form["Content"],
                    };
                    break;
                case RequestMsgType.Location:
                    requestMessaage = new RequestMessageLocation()
                    {
                        Label = Request.Form["Label"],
                        Location_X = double.Parse(Request.Form["Location_X"]),
                        Location_Y = double.Parse(Request.Form["Location_Y"]),
                        Scale = int.Parse(Request.Form["Scale"])
                    };
                    break;
                case RequestMsgType.Image:
                    requestMessaage = new RequestMessageImage()
                    {
                        PicUrl = Request.Form["PicUrl"],
                    };
                    break;
                case RequestMsgType.Voice:
                    requestMessaage = new RequestMessageVoice()
                    {
                        Format = Request.Form["Format"],
                        Recognition = Request.Form["Recognition"],
                    };
                    break;
                case RequestMsgType.Video:
                    requestMessaage = new RequestMessageVideo()
                    {
                        MsgId = long.Parse(Request.Form["MsgId"]),
                        ThumbMediaId = Request.Form["ThumbMediaId"],
                    };
                    break;
                //case RequestMsgType.Link:
                //    break;
                case RequestMsgType.Event:
                    if (eventType.HasValue)
                    {
                        RequestMessageEventBase requestMessageEvent = null;
                        switch (eventType.Value)
                        {
                            //case Event.ENTER:
                            //    break;
                            case Event.LOCATION:
                                requestMessageEvent = new RequestMessageEvent_Location()
                                {
                                    Latitude = long.Parse(Request.Form["Event.Latitude"]),
                                    Longitude = long.Parse(Request.Form["Event.Longitude"]),
                                    Precision = double.Parse(Request.Form["Event.Precision"])
                                };
                                break;
                            case Event.subscribe:
                                requestMessageEvent = new RequestMessageEvent_Subscribe()
                                {
                                    EventKey = Request.Form["Event.EventKey"],
                                    Ticket = Request.Form["Event.Ticket"]
                                };
                                break;
                            case Event.unsubscribe:
                                requestMessageEvent = new RequestMessageEvent_Unsubscribe();
                                break;
                            case Event.CLICK:
                                requestMessageEvent = new RequestMessageEvent_Click()
                                   {
                                       EventKey = Request.Form["Event.EventKey"]
                                   };
                                break;
                            case Event.scan:
                                requestMessageEvent = new RequestMessageEvent_Scan()
                                 {
                                     EventKey = Request.Form["Event.EventKey"],
                                     Ticket = Request.Form["Event.Ticket"]
                                 }; break;
                            case Event.VIEW:
                                requestMessageEvent = new RequestMessageEvent_View()
                                 {
                                     EventKey = Request.Form["Event.EventKey"]
                                 }; break;
                            case Event.MASSSENDJOBFINISH:
                                requestMessageEvent = new RequestMessageEvent_MassSendJobFinish()
                                {
                                    FromUserName = "******",//系统指定
                                    ErrorCount = int.Parse(Request.Form["Event.ErrorCount"]),
                                    FilterCount = int.Parse(Request.Form["Event.FilterCount"]),
                                    SentCount = int.Parse(Request.Form["Event.SentCount"]),
                                    Status = Request.Form["Event.Status"],
                                    TotalCount = int.Parse(Request.Form["Event.TotalCount"])
                                }; break;
                            case Event.TEMPLATESENDJOBFINISH:
                                requestMessageEvent = new RequestMessageEvent_TemplateSendJobFinish()
                                {
                                    FromUserName = "******",//系统指定
                                    MsgID = long.Parse(Request.Form["Event.MsgID"]),
                                    Status = Request.Form["Event.Status"],
                                }; break;
                            case Event.scancode_push:
                                requestMessageEvent = new RequestMessageEvent_Scancode_Push()
                                {
                                    FromUserName = "******",//系统指定
                                    EventKey = Request.Form["Event.EventKey"],
                                    ScanCodeInfo = new ScanCodeInfo()
                                        {
                                            ScanResult = Request.Form["Event.ScanResult"],
                                            ScanType = Request.Form["Event.ScanType"],
                                        }
                                }; break;
                            case Event.scancode_waitmsg:
                                requestMessageEvent = new RequestMessageEvent_Scancode_Waitmsg()
                                {
                                    FromUserName = "******",//系统指定
                                    EventKey = Request.Form["Event.EventKey"],
                                    ScanCodeInfo = new ScanCodeInfo()
                                    {
                                        ScanResult = Request.Form["Event.ScanResult"],
                                        ScanType = Request.Form["Event.ScanType"],
                                    }
                                }; break;
                            case Event.pic_sysphoto:
                                var sysphotoPicMd5Sum = Request.Form["Event.PicMd5Sum"];
                                PicItem sysphotoPicItem = new PicItem()
                                    {
                                        item = new Md5Sum()
                                            {
                                                PicMd5Sum = sysphotoPicMd5Sum
                                            }
                                    };
                                List<PicItem> sysphotoPicItems = new List<PicItem>();
                                sysphotoPicItems.Add(sysphotoPicItem);
                                requestMessageEvent = new RequestMessageEvent_Pic_Sysphoto()
                            {
                                FromUserName = "******",//系统指定
                                EventKey = Request.Form["Event.EventKey"],
                                SendPicsInfo = new SendPicsInfo()
                                {
                                    Count = Request.Form["Event.Count"],
                                    PicList = sysphotoPicItems
                                }
                            }; break;
                            case Event.pic_photo_or_album:
                                var photoOrAlbumPicMd5Sum = Request.Form["Event.PicMd5Sum"];
                                PicItem photoOrAlbumPicItem = new PicItem()
                                {
                                    item = new Md5Sum()
                                    {
                                        PicMd5Sum = photoOrAlbumPicMd5Sum
                                    }
                                };
                                List<PicItem> photoOrAlbumPicItems = new List<PicItem>();
                                photoOrAlbumPicItems.Add(photoOrAlbumPicItem);
                                requestMessageEvent = new RequestMessageEvent_Pic_Sysphoto()
                                {
                                    FromUserName = "******",//系统指定
                                    EventKey = Request.Form["Event.EventKey"],
                                    SendPicsInfo = new SendPicsInfo()
                                    {
                                        Count = Request.Form["Event.Count"],
                                        PicList = photoOrAlbumPicItems
                                    }
                                }; break;
                            case Event.pic_weixin:
                                var weixinPicMd5Sum = Request.Form["Event.PicMd5Sum"];
                                PicItem weixinPicItem = new PicItem()
                                {
                                    item = new Md5Sum()
                                    {
                                        PicMd5Sum = weixinPicMd5Sum
                                    }
                                };
                                List<PicItem> weixinPicItems = new List<PicItem>();
                                weixinPicItems.Add(weixinPicItem);
                                requestMessageEvent = new RequestMessageEvent_Pic_Sysphoto()
                                {
                                    FromUserName = "******",//系统指定
                                    EventKey = Request.Form["Event.EventKey"],
                                    SendPicsInfo = new SendPicsInfo()
                                    {
                                        Count = Request.Form["Event.Count"],
                                        PicList = weixinPicItems
                                    }
                                }; break;
                            case Event.location_select:
                                requestMessageEvent = new RequestMessageEvent_Location_Select()
                                {
                                    FromUserName = "******",//系统指定
                                    EventKey = Request.Form["Event.EventKey"],
                                    SendLocationInfo = new SendLocationInfo()
                                        {
                                            Label = Request.Form["Event.Label"],
                                            Location_X = Request.Form["Event.Location_X"],
                                            Location_Y = Request.Form["Event.Location_Y"],
                                            Poiname = Request.Form["Event.Poiname"],
                                            Scale = Request.Form["Event.Scale"],
                                        }
                                }; break;
                            default:
                                throw new ArgumentOutOfRangeException("eventType");
                        }
                        requestMessaage = requestMessageEvent;
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("eventType");
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException("requestType");
            }

            requestMessaage.MsgId = long.Parse(Request.Form["MsgId"]);
            requestMessaage.CreateTime = DateTime.Now;
            requestMessaage.FromUserName = requestMessaage.FromUserName ?? "FromUserName(OpenId)";//用于区别不同的请求用户
            requestMessaage.ToUserName = "******";

            return requestMessaage.ConvertEntityToXml();
        }
예제 #27
0
        //<?xml version="1.0" encoding="utf-8"?>
        //<xml>
        //  <ToUserName><![CDATA[gh_a96a4a619366]]></ToUserName>
        //  <FromUserName><![CDATA[olPjZjsXuQPJoV0HlruZkNzKc91E]]></FromUserName>
        //  <CreateTime>1357986928</CreateTime>
        //  <MsgType><![CDATA[text]]></MsgType>
        //  <Content><![CDATA[中文]]></Content>
        //  <MsgId>5832509444155992350</MsgId>
        //</xml>

        /// <summary>
        /// 获取XDocument转换后的IRequestMessageBase实例。
        /// 如果MsgType不存在,抛出UnknownRequestMsgTypeException异常
        /// </summary>
        /// <returns></returns>
        public static IRequestMessageBase GetRequestEntity(XDocument doc, PostModel postModel = null)
        {
            RequestMessageBase requestMessage = null;
            RequestMsgType     msgType;

            try
            {
                msgType = MsgTypeHelper.GetRequestMsgType(doc);
                switch (msgType)
                {
                case RequestMsgType.Text:
                    requestMessage = new RequestMessageText();
                    break;

                case RequestMsgType.Location:
                    requestMessage = new RequestMessageLocation();
                    break;

                case RequestMsgType.Image:
                    requestMessage = new RequestMessageImage();
                    break;

                case RequestMsgType.Voice:
                    requestMessage = new RequestMessageVoice();
                    break;

                case RequestMsgType.Video:
                    requestMessage = new RequestMessageVideo();
                    break;

                case RequestMsgType.Link:
                    requestMessage = new RequestMessageLink();
                    break;

                case RequestMsgType.ShortVideo:
                    requestMessage = new RequestMessageShortVideo();
                    break;

                case RequestMsgType.File:
                    requestMessage = new RequestMessageFile();
                    break;

                case RequestMsgType.NeuChar:
                    requestMessage = new RequestMessageNeuChar();
                    break;

                case RequestMsgType.Event:
                    //判断Event类型
                    switch (doc.Root.Element("Event").Value.ToUpper())
                    {
                    case "ENTER":        //进入会话
                        requestMessage = new RequestMessageEvent_Enter();
                        break;

                    case "LOCATION":        //地理位置
                        requestMessage = new RequestMessageEvent_Location();
                        break;

                    case "SUBSCRIBE":        //订阅(关注)
                        requestMessage = new RequestMessageEvent_Subscribe();
                        break;

                    case "UNSUBSCRIBE":        //取消订阅(关注)
                        requestMessage = new RequestMessageEvent_Unsubscribe();
                        break;

                    case "CLICK":        //菜单点击
                        requestMessage = new RequestMessageEvent_Click();
                        break;

                    case "SCAN":        //二维码扫描
                        requestMessage = new RequestMessageEvent_Scan();
                        break;

                    case "VIEW":        //URL跳转
                        requestMessage = new RequestMessageEvent_View();
                        break;

                    case "MASSSENDJOBFINISH":
                        requestMessage = new RequestMessageEvent_MassSendJobFinish();
                        break;

                    case "TEMPLATESENDJOBFINISH":        //模板信息
                        requestMessage = new RequestMessageEvent_TemplateSendJobFinish();
                        break;

                    case "SCANCODE_PUSH":        //扫码推事件(scancode_push)
                        requestMessage = new RequestMessageEvent_Scancode_Push();
                        break;

                    case "SCANCODE_WAITMSG":        //扫码推事件且弹出“消息接收中”提示框(scancode_waitmsg)
                        requestMessage = new RequestMessageEvent_Scancode_Waitmsg();
                        break;

                    case "PIC_SYSPHOTO":        //弹出系统拍照发图(pic_sysphoto)
                        requestMessage = new RequestMessageEvent_Pic_Sysphoto();
                        break;

                    case "PIC_PHOTO_OR_ALBUM":        //弹出拍照或者相册发图(pic_photo_or_album)
                        requestMessage = new RequestMessageEvent_Pic_Photo_Or_Album();
                        break;

                    case "PIC_WEIXIN":        //弹出微信相册发图器(pic_weixin)
                        requestMessage = new RequestMessageEvent_Pic_Weixin();
                        break;

                    case "LOCATION_SELECT":        //弹出地理位置选择器(location_select)
                        requestMessage = new RequestMessageEvent_Location_Select();
                        break;

                    case "CARD_PASS_CHECK":        //卡券通过审核
                        requestMessage = new RequestMessageEvent_Card_Pass_Check();
                        break;

                    case "CARD_NOT_PASS_CHECK":        //卡券未通过审核
                        requestMessage = new RequestMessageEvent_Card_Not_Pass_Check();
                        break;

                    case "USER_GET_CARD":        //领取卡券
                        requestMessage = new RequestMessageEvent_User_Get_Card();
                        break;

                    case "USER_DEL_CARD":        //删除卡券
                        requestMessage = new RequestMessageEvent_User_Del_Card();
                        break;

                    case "KF_CREATE_SESSION":        //多客服接入会话
                        requestMessage = new RequestMessageEvent_Kf_Create_Session();
                        break;

                    case "KF_CLOSE_SESSION":        //多客服关闭会话
                        requestMessage = new RequestMessageEvent_Kf_Close_Session();
                        break;

                    case "KF_SWITCH_SESSION":        //多客服转接会话
                        requestMessage = new RequestMessageEvent_Kf_Switch_Session();
                        break;

                    case "POI_CHECK_NOTIFY":        //审核结果事件推送
                        requestMessage = new RequestMessageEvent_Poi_Check_Notify();
                        break;

                    case "WIFICONNECTED":        //Wi-Fi连网成功事件
                        requestMessage = new RequestMessageEvent_WifiConnected();
                        break;

                    case "USER_CONSUME_CARD":        //卡券核销
                        requestMessage = new RequestMessageEvent_User_Consume_Card();
                        break;

                    case "USER_ENTER_SESSION_FROM_CARD":        //从卡券进入公众号会话
                        requestMessage = new RequestMessageEvent_User_Enter_Session_From_Card();
                        break;

                    case "USER_VIEW_CARD":        //进入会员卡
                        requestMessage = new RequestMessageEvent_User_View_Card();
                        break;

                    case "MERCHANT_ORDER":        //微小店订单付款通知
                        requestMessage = new RequestMessageEvent_Merchant_Order();
                        break;

                    case "SUBMIT_MEMBERCARD_USER_INFO":        //接收会员信息事件通知
                        requestMessage = new RequestMessageEvent_Submit_Membercard_User_Info();
                        break;

                    case "SHAKEAROUNDUSERSHAKE":        //摇一摇事件通知
                        requestMessage = new RequestMessageEvent_ShakearoundUserShake();
                        break;

                    case "USER_GIFTING_CARD":        //卡券转赠事件推送
                        requestMessage = new RequestMessageEvent_User_Gifting_Card();
                        break;

                    case "USER_PAY_FROM_PAY_CELL":        // 微信买单完成
                        requestMessage = new RequestMessageEvent_User_Pay_From_Pay_Cell();
                        break;

                    case "UPDATE_MEMBER_CARD":        // 会员卡内容更新事件:会员卡积分余额发生变动时
                        requestMessage = new RequestMessageEvent_Update_Member_Card();
                        break;

                    case "CARD_SKU_REMIND":        //卡券库存报警事件:当某个card_id的初始库存数大于200且当前库存小于等于100时
                        requestMessage = new RequestMessageEvent_Card_Sku_Remind();
                        break;

                    case "CARD_PAY_ORDER":        //券点流水详情事件:当商户朋友的券券点发生变动时
                        requestMessage = new RequestMessageEvent_Card_Pay_Order();
                        break;

                    case "APPLY_MERCHANT_AUDIT_INFO":        //创建门店小程序审核事件
                        requestMessage = new RequestMessageEvent_ApplyMerchantAuditInfo();
                        break;

                    case "CREATE_MAP_POI_AUDIT_INFO":        //从腾讯地图中创建门店审核事件
                        requestMessage = new RequestMessageEvent_CreateMapPoiAuditInfo();
                        break;

                    case "ADD_STORE_AUDIT_INFO":        //门店小程序中创建门店审核事件
                        requestMessage = new RequestMessageEvent_AddStoreAuditInfo();
                        break;

                    case "MODIFY_STORE_AUDIT_INFO":        //修改门店图片审核事件
                        requestMessage = new RequestMessageEvent_ModifyStoreAuditInfo();
                        break;

                    case "VIEW_MINIPROGRAM":        //微信点击菜单跳转小程序的事件推送的事件
                        requestMessage = new RequestMessageEvent_View_Miniprogram();
                        break;

                        #region 卡券回调
                    case "GIFTCARD_PAY_DONE":        //券点流水详情事件:当商户朋友的券券点发生变动时
                        requestMessage = new RequestMessageEvent_GiftCard_Pay_Done();
                        break;

                    case "GIFTCARD_SEND_TO_FRIEND":        //券点流水详情事件:当商户朋友的券券点发生变动时
                        requestMessage = new RequestMessageEvent_GiftCard_Send_To_Friend();
                        break;

                    case "GIFTCARD_USER_ACCEPT":        //券点流水详情事件:当商户朋友的券券点发生变动时
                        requestMessage = new RequestMessageEvent_GiftCard_User_Accept();
                        break;
                        #endregion

                        #region 微信认证事件推送
                    case "QUALIFICATION_VERIFY_SUCCESS":        //资质认证成功(此时立即获得接口权限)
                        requestMessage = new RequestMessageEvent_QualificationVerifySuccess();
                        break;

                    case "QUALIFICATION_VERIFY_FAIL":        //资质认证失败
                        requestMessage = new RequestMessageEvent_QualificationVerifyFail();
                        break;

                    case "NAMING_VERIFY_SUCCESS":        //名称认证成功(即命名成功)
                        requestMessage = new RequestMessageEvent_NamingVerifySuccess();
                        break;

                    case "NAMING_VERIFY_FAIL":        //名称认证失败(这时虽然客户端不打勾,但仍有接口权限)
                        requestMessage = new RequestMessageEvent_NamingVerifyFail();
                        break;

                    case "ANNUAL_RENEW":        //年审通知
                        requestMessage = new RequestMessageEvent_AnnualRenew();
                        break;

                    case "VERIFY_EXPIRED":        //认证过期失效通知
                        requestMessage = new RequestMessageEvent_VerifyExpired();
                        break;

                        #endregion

                        #region 小程序审核事件推送
                    case "WEAPP_AUDIT_SUCCESS":         //小程序审核成功
                        requestMessage = new RequestMessageEvent_WeAppAuditSuccess();
                        break;

                    case "WEAPP_AUDIT_FAIL":         //小程序审核失败
                        requestMessage = new RequestMessageEvent_WeAppAuditFail();
                        break;
                        #endregion

                    default:        //其他意外类型(也可以选择抛出异常)
                        requestMessage = new RequestMessageEventBase();
                        break;
                    }
                    break;

                default:
                {
                    requestMessage = new RequestMessageUnknownType()
                    {
                        RequestDocument = doc
                    };

                    #region v14.8.3 之前的方案,直接在这里抛出异常

                    /*
                     * throw new UnknownRequestMsgTypeException(string.Format("MsgType:{0} 在RequestMessageFactory中没有对应的处理程序!", msgType), new ArgumentOutOfRangeException());//为了能够对类型变动最大程度容错(如微信目前还可以对公众账号suscribe等未知类型,但API没有开放),建议在使用的时候catch这个异常
                     */

                    #endregion

                    break;
                }
                }
                Senparc.NeuChar.Helpers.EntityHelper.FillEntityWithXml(requestMessage, doc);
            }
            catch (ArgumentException ex)
            {
                throw new WeixinException(string.Format("RequestMessage转换出错!可能是MsgType不存在!,XML:{0}", doc.ToString()), ex);
            }
            return(requestMessage);
        }
예제 #28
0
        //<?xml version="1.0" encoding="utf-8"?>
        //<xml>
        //  <ToUserName><![CDATA[gh_a96a4a619366]]></ToUserName>
        //  <FromUserName><![CDATA[olPjZjsXuQPJoV0HlruZkNzKc91E]]></FromUserName>
        //  <CreateTime>1357986928</CreateTime>
        //  <MsgType><![CDATA[text]]></MsgType>
        //  <Content><![CDATA[中文]]></Content>
        //  <MsgId>5832509444155992350</MsgId>
        //</xml>

        /// <summary>
        /// 获取XDocument转换后的IRequestMessageBase实例。
        /// 如果MsgType不存在,抛出UnknownRequestMsgTypeException异常
        /// </summary>
        /// <returns></returns>
        public static IRequestMessageBase GetRequestEntity(XDocument doc, PostModel postModel = null)
        {
            RequestMessageBase requestMessage = null;
            RequestMsgType     msgType;

            try
            {
                msgType = MsgTypeHelper.GetRequestMsgType(doc);
                switch (msgType)
                {
                case RequestMsgType.Text:
                    requestMessage = new RequestMessageText();
                    break;

                case RequestMsgType.Location:
                    requestMessage = new RequestMessageLocation();
                    break;

                case RequestMsgType.Image:
                    requestMessage = new RequestMessageImage();
                    break;

                case RequestMsgType.Voice:
                    requestMessage = new RequestMessageVoice();
                    break;

                case RequestMsgType.Video:
                    requestMessage = new RequestMessageVideo();
                    break;

                case RequestMsgType.Link:
                    requestMessage = new RequestMessageLink();
                    break;

                case RequestMsgType.ShortVideo:
                    requestMessage = new RequestMessageShortVideo();
                    break;

                case RequestMsgType.Event:
                    //判断Event类型
                    switch (doc.Root.Element("Event").Value.ToUpper())
                    {
                    case "ENTER":        //进入会话
                        requestMessage = new RequestMessageEvent_Enter();
                        break;

                    case "LOCATION":        //地理位置
                        requestMessage = new RequestMessageEvent_Location();
                        break;

                    case "SUBSCRIBE":        //订阅(关注)
                        requestMessage = new RequestMessageEvent_Subscribe();
                        break;

                    case "UNSUBSCRIBE":        //取消订阅(关注)
                        requestMessage = new RequestMessageEvent_Unsubscribe();
                        break;

                    case "CLICK":        //菜单点击
                        requestMessage = new RequestMessageEvent_Click();
                        break;

                    case "SCAN":        //二维码扫描
                        requestMessage = new RequestMessageEvent_Scan();
                        break;

                    case "VIEW":        //URL跳转
                        requestMessage = new RequestMessageEvent_View();
                        break;

                    case "MASSSENDJOBFINISH":
                        requestMessage = new RequestMessageEvent_MassSendJobFinish();
                        break;

                    case "TEMPLATESENDJOBFINISH":        //模板信息
                        requestMessage = new RequestMessageEvent_TemplateSendJobFinish();
                        break;

                    case "SCANCODE_PUSH":        //扫码推事件(scancode_push)
                        requestMessage = new RequestMessageEvent_Scancode_Push();
                        break;

                    case "SCANCODE_WAITMSG":        //扫码推事件且弹出“消息接收中”提示框(scancode_waitmsg)
                        requestMessage = new RequestMessageEvent_Scancode_Waitmsg();
                        break;

                    case "PIC_SYSPHOTO":        //弹出系统拍照发图(pic_sysphoto)
                        requestMessage = new RequestMessageEvent_Pic_Sysphoto();
                        break;

                    case "PIC_PHOTO_OR_ALBUM":        //弹出拍照或者相册发图(pic_photo_or_album)
                        requestMessage = new RequestMessageEvent_Pic_Photo_Or_Album();
                        break;

                    case "PIC_WEIXIN":        //弹出微信相册发图器(pic_weixin)
                        requestMessage = new RequestMessageEvent_Pic_Weixin();
                        break;

                    case "LOCATION_SELECT":        //弹出地理位置选择器(location_select)
                        requestMessage = new RequestMessageEvent_Location_Select();
                        break;

                    case "CARD_PASS_CHECK":        //卡券通过审核
                        requestMessage = new RequestMessageEvent_Card_Pass_Check();
                        break;

                    case "CARD_NOT_PASS_CHECK":        //卡券未通过审核
                        requestMessage = new RequestMessageEvent_Card_Not_Pass_Check();
                        break;

                    case "USER_GET_CARD":        //领取卡券
                        requestMessage = new RequestMessageEvent_User_Get_Card();
                        break;

                    case "USER_DEL_CARD":        //删除卡券
                        requestMessage = new RequestMessageEvent_User_Del_Card();
                        break;

                    case "KF_CREATE_SESSION":        //多客服接入会话
                        requestMessage = new RequestMessageEvent_Kf_Create_Session();
                        break;

                    case "KF_CLOSE_SESSION":        //多客服关闭会话
                        requestMessage = new RequestMessageEvent_Kf_Close_Session();
                        break;

                    case "KF_SWITCH_SESSION":        //多客服转接会话
                        requestMessage = new RequestMessageEvent_Kf_Switch_Session();
                        break;

                    case "POI_CHECK_NOTIFY":        //审核结果事件推送
                        requestMessage = new RequestMessageEvent_Poi_Check_Notify();
                        break;

                    case "WIFICONNECTED":        //Wi-Fi连网成功事件
                        requestMessage = new RequestMessageEvent_WifiConnected();
                        break;

                    case "USER_CONSUME_CARD":        //卡券核销
                        requestMessage = new RequestMessageEvent_User_Consume_Card();
                        break;

                    case "USER_ENTER_SESSION_FROM_CARD":        //从卡券进入公众号会话
                        requestMessage = new RequestMessageEvent_User_Enter_Session_From_Card();
                        break;

                    case "USER_VIEW_CARD":        //进入会员卡
                        requestMessage = new RequestMessageEvent_User_View_Card();
                        break;

                    case "MERCHANT_ORDER":        //微小店订单付款通知
                        requestMessage = new RequestMessageEvent_Merchant_Order();
                        break;

                    default:        //其他意外类型(也可以选择抛出异常)
                        requestMessage = new RequestMessageEventBase();
                        break;
                    }
                    break;

                default:
                    throw new UnknownRequestMsgTypeException(string.Format("MsgType:{0} 在RequestMessageFactory中没有对应的处理程序!", msgType), new ArgumentOutOfRangeException());    //为了能够对类型变动最大程度容错(如微信目前还可以对公众账号suscribe等未知类型,但API没有开放),建议在使用的时候catch这个异常
                }
                EntityHelper.FillEntityWithXml(requestMessage, doc);
            }
            catch (ArgumentException ex)
            {
                throw new WeixinException(string.Format("RequestMessage转换出错!可能是MsgType不存在!,XML:{0}", doc.ToString()), ex);
            }
            return(requestMessage);
        }
예제 #29
0
 /// <summary>
 /// Event事件类型请求之unsubscribe
 /// </summary>
 public virtual IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
 {
     return(DefaultResponseMessage(requestMessage));
 }
 /// <summary>
 /// 【异步方法】Event事件类型请求之unsubscribe
 /// </summary>
 public virtual async Task <IResponseMessageBase> OnEvent_UnsubscribeRequestAsync(RequestMessageEvent_Unsubscribe requestMessage)
 {
     return(await DefaultAsyncMethod(requestMessage, () => OnEvent_UnsubscribeRequest(requestMessage)).ConfigureAwait(false));
 }
예제 #31
0
        //<?xml version="1.0" encoding="utf-8"?>
        //<xml>
        //  <ToUserName><![CDATA[gh_a96a4a619366]]></ToUserName>
        //  <FromUserName><![CDATA[olPjZjsXuQPJoV0HlruZkNzKc91E]]></FromUserName>
        //  <CreateTime>1357986928</CreateTime>
        //  <MsgType><![CDATA[text]]></MsgType>
        //  <Content><![CDATA[中文]]></Content>
        //  <MsgId>5832509444155992350</MsgId>
        //</xml>

        /// <summary>
        /// 获取XDocument转换后的IRequestMessageBase实例。
        /// 如果MsgType不存在,抛出UnknownRequestMsgTypeException异常
        /// </summary>
        /// <returns></returns>
        public static IRequestMessageBase GetRequestEntity(XDocument doc)
        {
            RequestMessageBase requestMessage = null;
            RequestMsgType     msgType;

            try
            {
                msgType = MsgTypeHelper.GetRequestMsgType(doc);
                switch (msgType)
                {
                case RequestMsgType.Text:
                    requestMessage = new RequestMessageText();
                    break;

                case RequestMsgType.Location:
                    requestMessage = new RequestMessageLocation();
                    break;

                case RequestMsgType.Image:
                    requestMessage = new RequestMessageImage();
                    break;

                case RequestMsgType.Voice:
                    requestMessage = new RequestMessageVoice();
                    break;

                case RequestMsgType.Video:
                    requestMessage = new RequestMessageVideo();
                    break;

                case RequestMsgType.Link:
                    requestMessage = new RequestMessageLink();
                    break;

                case RequestMsgType.Event:
                    //判断Event类型
                    switch (doc.Root.Element("Event").Value.ToUpper())
                    {
                    case "ENTER":        //进入会话
                        requestMessage = new RequestMessageEvent_Enter();
                        break;

                    case "LOCATION":        //地理位置
                        requestMessage = new RequestMessageEvent_Location();
                        break;

                    case "SUBSCRIBE":        //订阅(关注)
                        requestMessage = new RequestMessageEvent_Subscribe();
                        break;

                    case "UNSUBSCRIBE":        //取消订阅(关注)
                        requestMessage = new RequestMessageEvent_Unsubscribe();
                        break;

                    case "CLICK":        //菜单点击
                        requestMessage = new RequestMessageEvent_Click();
                        break;

                    case "SCAN":        //二维码扫描
                        requestMessage = new RequestMessageEvent_Scan();
                        break;

                    default:        //其他意外类型(也可以选择抛出异常)
                        requestMessage = new RequestMessageEventBase();
                        break;
                    }
                    break;

                default:
                    throw new UnknownRequestMsgTypeException(
                              $"MsgType:{msgType} 在RequestMessageFactory中没有对应的处理程序!", new ArgumentOutOfRangeException());//为了能够对类型变动最大程度容错(如微信目前还可以对公众账号suscribe等未知类型,但API没有开放),建议在使用的时候catch这个异常
                }
                EntityHelper.FillEntityWithXml(requestMessage, doc);
            }
            catch (ArgumentException ex)
            {
                throw new WeixinException($"RequestMessage转换出错!可能是MsgType不存在!,XML:{doc.ToString()}", ex);
            }
            return(requestMessage);
        }
 /// <summary>
 /// 退订
 /// 实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
 /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。并且关注用户流失的情况。
 /// </summary>
 /// <returns></returns>
 public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
 {
     return EventProcess(7, requestMessage);
 }