public void ProcessRequest(HttpContext context) { //如果param为null,则实例化 param = param ?? new EnterParam { appid = System.Web.Configuration.WebConfigurationManager.AppSettings["appID"], EncodingAESKey = System.Web.Configuration.WebConfigurationManager.AppSettings["EncodingAESKey"], token = System.Web.Configuration.WebConfigurationManager.AppSettings["token"] }; //var ip = context.Request.UserHostAddress; //var ipEntity = BaseServices.GetIpArray("你的access_token"); //if (ipEntity!=null&&!ipEntity.ip_list.Contains(ip)) //{ // context.Response.Write("非法请求"); // return; //} if (context.Request.HttpMethod == "GET") { BaseServices.ValidUrl(param.token); } else { //判断MsgHandlerEntities是否为空,如果是,则实例化,并将各个消息类型的处理程序实体添加到此列表中 //因为MsgHandlerEntities是静态变量,只需绑定一次即可。免去了重复绑定的性能损耗。 if (MsgHandlerEntity.MsgHandlerEntities == null) { MsgHandlerEntity.MsgHandlerEntities = new List <MsgHandlerEntity>(); #region 文本消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.TEXT, Action = TextHandler }); #endregion #region 图片消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.IMAGE, Action = ImgHandler }); #endregion #region 语音消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.VOICE, Action = VoiceHandler }); #endregion #region 视频消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.VIDEO, Action = VideoHandler }); #endregion #region 地理位置消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.LOCATION, Action = LoctionHandler }); #endregion #region 链接消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.LINK, Action = linkHandler }); #endregion #region 群发消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.MASSSENDJOBFINISH, Action = GroupJobHandler }); #endregion #region 模板消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.TEMPLATESENDJOBFINISH, Action = TemplateJobHandler }); #endregion #region 扫描带参数二维码消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.SCAN, Action = SanQrEventHandler }); #endregion #region 自定义菜单Click消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.CLICK, Action = ClickEventHandler }); #endregion #region 自定义菜单View消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.VIEW, Action = ViewEventHandler }); #endregion #region 自定义菜单扫描二维码(scancode_push)消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.SCANCODE_PUSH, Action = MenuSanQrEventHandler }); #endregion #region 自定义菜单扫描二维码(scancode_waitmsg)消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.SCANCODE_WAITMSG, Action = MenuSanQrEventHandler }); #region 自定义菜单扫描二维码(scancode_waitmsg)消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.SCANCODE_WAITMSG, Action = MenuSanQrEventHandler }); #endregion #endregion #region 自定义菜单发送图片(pic_sysphoto)消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.PIC_SYSPHOTO, Action = MenuSendPicEventHandler }); #region 自定义菜单发送图片(pic_photo_or_album)消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.PIC_PHOTO_OR_ALBUM, Action = MenuSendPicEventHandler }); #endregion #region 自定义菜单发送图片(pic_weixin)消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.PIC_WEIXIN, Action = MenuSendPicEventHandler }); #endregion #endregion #region 创建多客服会话消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.KF_CREATE_SESSION, Action = KfHandler }); #endregion #region 关闭多客服会话消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.KF_CLOSE_SESSION, Action = KfHandler }); #endregion #region 转接多客服会话消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.KF_SWITCH_SESSION, Action = KfHandler }); #endregion #region 微信小店订单消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.MERCHANT_ORDER, Action = OrderHandler }); #endregion #region 门店审核处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.POI_CHECK_NOTIFY, Action = PoiNotifyHandler }); #endregion #region 卡券审核通过处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.CARD_PASS_CHECK, Action = CardCheckNotifyHandler }); #endregion #region 卡券审核未通过处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.CARD_NOT_PASS_CHECK, Action = CardCheckNotifyHandler }); #endregion #region 领取卡券处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.USER_GET_CARD, Action = UserGetCardHandler }); #endregion #region 关注事件处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.SUBSCRIBE, Action = SubscribeHandler }); #endregion #region 取消关注事件处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.UNSUBSCRIBE, Action = SubscribeHandler }); #endregion } MsgFactory.LoadMsg(param, MsgHandlerEntity.MsgHandlerEntities); } }
public void ProcessRequest(HttpContext context) { // 测试时暂不使用 /*var ip = context.Request.UserHostAddress; * var ipEntity = BaseServices.GetIpArray("你的access_token"); * if(ipEntity!=null && !ipEntity.ip_list.Contains(ip)) * { * context.Response.Write("非法请求"); * return; * }*/ // var url = context.Request.RawUrl; if (context.Request.HttpMethod == "GET") { BaseServices.ValidUrl("skywalkerxl"); } else { //var xml = Utils.GetRequestData(); //System.Diagnostics.Debug.WriteLine("----------------------Receive the xml message Start----------------------"); //System.Diagnostics.Debug.WriteLine(xml); //System.Diagnostics.Debug.WriteLine("---------------------- Receive the xml message End ----------------------"); //context.Response.Write(""); string openid = context.Request.Params["openid"]; Utils.OutPrint(openid); if (SessionUtils.Get("openid") == null) { SessionUtils.Add("openid", openid); } // 判断MsgHandlerEntities是否为空,如果是,则实例化,并将各个消息类型的处理程序实体添加到此列表中 // 因为MsgHandlerEntities是静态变量,之需绑定一次即可,免去了重复绑定的性能损耗 if (MsgHandlerEntity.MsgHandlerEntities == null) { MsgHandlerEntity.MsgHandlerEntities = new List <MsgHandlerEntity>(); #region 文本消息绑定处理 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.TEXT, Action = TextHandler }); #endregion #region 图片消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.IMAGE, Action = ImgHandler }); #endregion #region 语音消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.VOICE, Action = VoiceHandler }); #endregion #region 视频消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.VIDEO, Action = VideoHandler }); #endregion #region 地理位置消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.LOCATION, Action = LocationHandler }); #endregion #region 链接消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.LINK, Action = linkHandler }); #endregion #region 点击事件处理程序 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.CLICK, Action = ClickEventHandler }); #endregion #region 图片事件处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.PIC_WEIXIN, Action = PicWeiXinHandler }); #endregion #region 订阅事件处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.SUBSCRIBE, Action = SubscribeEventHandler }); #endregion /*** * * * 其它一系列的事件处理 * * ***/ // TODO #region 获取地理位置信息事件处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.LOCATION, Action = LocationEventHandler }); #endregion #region 浏览事件处理程序绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.VIEW, Action = ViewEventHandler }); #endregion #region 扫码推送事件处理程序绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.SCANCODE_PUSH, Action = ScanCodePushEventHandler }); #endregion #region 扫码等待事件处理程序绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.SCANCODE_WAITMSG, Action = ScanCOdeWatingEventHandler }); #endregion #region 系统照相事件处理程序绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.PIC_SYSPHOTO, Action = PicSysphotoEventHandler }); #endregion #region 系统照相或相册事件处理程序绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.PIC_PHOTO_OR_ALBUM, Action = PicPhotoOrAlbumEventHandler }); #endregion #region 弹出地理位置选择器事件处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.LOCATION_SELECT, Action = LocationSelectEventHandler }); #endregion #region 模板消息事件处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.TEMPLATESENDJOBFINISH, Action = TEMPLATESENDJOBFINISHEventHandler }); #endregion #region 群发消息处理绑定 MsgHandlerEntity.MsgHandlerEntities.Add(new MsgHandlerEntity { MsgType = MsgType.EVENT, EventType = EventType.MASSSENDJOBFINISH, Action = GroupJobHandler }); #endregion } MsgFactory.LoadMsg(MsgHandlerEntity.MsgHandlerEntities); } }