Пример #1
0
        //事件处理
        public void EventHandle(WeixinInfo wx, string WeixinAccess, string Appid)
        {
            string remsg = "";
            string responseContent = "";
            if (wx.WXEvent != null)
            {
                //菜单单击事件
                if (wx.WXEvent.Equals("CLICK"))
                {
                    if (wx.WXEventKey.Equals("click1"))
                    {
                        responseContent = string.Format(WeixinDAL.ReplyType.Message_News_Main,
                             wx.WXFromUserName,
                             wx.WXToUserName,
                             DateTime.Now.Ticks,
                             "1",
                              string.Format(WeixinDAL.ReplyType.Message_News_Item, "测试通过", "",
                              "" + DateTime.Now.Ticks,
                              ""));
                    }
                    else if (wx.WXEventKey.Equals("click2"))
                    {

                    }

                }
                else if (wx.WXEvent.Equals("location_select"))//接收地理位置
                {
                    if (wx.WXEventKey.Equals("rselfmenu_2_0"))
                    {

                    }
                }
                else if (wx.WXEvent.Equals("scancode_waitmsg"))//二维码
                {

                }
                else if (wx.WXEvent.Equals("subscribe"))//关注事件
                {

                }
                else if (wx.WXEvent.Equals("unsubscribe"))//取消事件
                {

                }

                System.Web.HttpContext.Current.Response.Write(EncryptDecryptMsg(responseContent, 1, Appid));
                wx.WeixinID = Guid.NewGuid();
                wx.WXReContent = responseContent;
                wx.WXFromAccess = WeixinAccess;
                PublicBLL.Insert(wx, "");
            }
        }
Пример #2
0
        private void ResponseMsg(WeixinInfo wx, string _remsg, string WeixinAccess, string Appid)
        {
            string responseContent = "";
            string remsg = "";

            responseContent = string.Format(WeixinDAL.ReplyType.Message_Text,
                           wx.WXFromUserName,
                           wx.WXToUserName,
                           DateTime.Now.Ticks,
                           _remsg + remsg);

            System.Web.HttpContext.Current.Response.Write(EncryptDecryptMsg(responseContent, 1, Appid));
            wx.WeixinID = Guid.NewGuid();
            wx.WXCreatime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            wx.WXReContent = responseContent;
            wx.WXFromAccess = WeixinAccess;
            PublicBLL.Insert(wx,"");
        }
Пример #3
0
        public static void Handle(string postStr, WxDelegate2 ResponseMsg, WxDelegate EventHandle, string WeixinAccess, string corpId)
        {

            //封装请求类

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(postStr);

            XmlElement rootElement = doc.DocumentElement;


            XmlNode MsgType = rootElement.SelectSingleNode("MsgType");


            WeixinInfo wx = new WeixinInfo();

            wx.WXToUserName = rootElement.SelectSingleNode("ToUserName").InnerText;

            wx.WXFromUserName = rootElement.SelectSingleNode("FromUserName").InnerText;

            wx.WXCreatime = rootElement.SelectSingleNode("CreateTime").InnerText;

            wx.WXMsgType = MsgType.InnerText;
            try
            {
                wx.WXEvent = rootElement.SelectSingleNode("Event").InnerText;

                wx.WXEventKey = rootElement.SelectSingleNode("EventKey").InnerText;
            }
            catch
            {
            }


            if (wx.WXMsgType == "text")
            {
                wx.WXMsg = rootElement.SelectSingleNode("Content").InnerText;
                ResponseMsg(wx, "", WeixinAccess, corpId);
            }
            else if (wx.WXMsgType == "event")
            {
                if (wx.WXEvent != null)
                    if (wx.WXEvent.ToLower() == "click")
                    {

                    }
                    else if (wx.WXEvent.ToLower() == "location_select")
                    {
                        wx.WXLocationX = rootElement.SelectSingleNode("Location_X").InnerText;

                        wx.WXLocationY = rootElement.SelectSingleNode("Location_Y").InnerText;

                        wx.WXScale = rootElement.SelectSingleNode("Scale").InnerText;

                        wx.WXLabel = rootElement.SelectSingleNode("Label").InnerText;
                    }
                    else if (wx.WXEvent.ToLower() == "scancode_waitmsg")
                    {
                        wx.WXScanResult = rootElement.SelectSingleNode("ScanCodeInfo").SelectSingleNode("ScanResult").InnerText;
                    }
                    else if (wx.WXEvent.ToLower() == "view")
                    {

                    }
                    else if (wx.WXEvent.ToLower() == "scancode_push")
                    {

                    }
                    else if (wx.WXEvent.ToLower() == "pic_sysphoto")
                    {

                    }
                    else if (wx.WXEvent.ToLower() == "pic_photo_or_album")
                    {

                    }
                    else if (wx.WXEvent.ToLower() == "pic_weixin")
                    {

                    }
                    else if (wx.WXEvent.ToLower() == "media_id")
                    {

                    }
                    else if (wx.WXEvent.ToLower() == "view_limited")
                    {

                    }

                EventHandle(wx, WeixinAccess, corpId);
            }

            else if (wx.WXMsgType == "image")
            {

                wx.WXPicUrl = rootElement.SelectSingleNode("PicUrl").InnerText;

            }
            else if (wx.WXMsgType == "voice")
            {
                //wx.WXMediaId = rootElement.SelectSingleNode("MediaId").InnerText;
                wx.WXMsgID = rootElement.SelectSingleNode("MsgID").InnerText;
                wx.WXFormat = rootElement.SelectSingleNode("Format").InnerText;
                ResponseMsg(wx, "", WeixinAccess, corpId);
            }
        }