Esempio n. 1
0
        /// <summary>
        /// 接收微信发送的XML消息并且解析
        /// </summary>
        private void ReceiveXml()
        {
            try
            {
                //BaseMessage bm = wxPlatForm.WxRequest.Load(new EnterParam { IsAes = false, token = "", appid = "", EncodingAESKey = "" });

                Stream requestStream = System.Web.HttpContext.Current.Request.InputStream;
                byte[] requestByte = new byte[requestStream.Length];
                requestStream.Read(requestByte, 0, (int)requestStream.Length);
                string requestStr = Encoding.UTF8.GetString(requestByte);
                BaseMessage bm = MessageFactory.CreateMessage(requestStr);
                
                if (bm.MsgType == MsgType.TEXT)
                {
                    TextMessage tm = (TextMessage)bm;
                    ReceiveMessage.GetText(tm);
                }
                else if (bm.MsgType == MsgType.LOCATION)
                {
                    ReceiveMessage.WriteXML_Text(bm, "我们不接收地理位置消息!");
                    //xml = ReceiveMessage.GetText(bm.FromUserName, bm.ToUserName, "this is location info");
                }
                else if (bm.MsgType == MsgType.IMAGE)
                {
                    ReceiveMessage.WriteXML_Text(bm, "我们不接收图片消息!");
                    //xml = ReceiveMessage.GetText(bm.FromUserName, bm.ToUserName, "this is image info");
                }
                else if (bm.MsgType == MsgType.EVENT)
                {
                    EventMessage eventmessage = (EventMessage)bm;
                    eventFunc.loadFunc(eventmessage);
                }
            
            }
            catch (Exception ex) {
                common.CommonMethod.WriteTxt(ex.Message);//记录错误信息
            }
        }