Пример #1
0
 public void ProcessRequest(HttpContext context)
 {
     try
     {
         context.Response.ContentType = "text/plain";
         if (context.Request.HttpMethod.ToLower() == "post")
         {
             using (Stream stream = HttpContext.Current.Request.InputStream)
             {
                 Byte[] postBytes = new Byte[stream.Length];
                 stream.Read(postBytes, 0, (Int32)stream.Length);
                 MessageHelp help            = new MessageHelp();
                 string      responseContent = help.ReturnMessage(postBytes);
                 HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
                 HttpContext.Current.Response.Write(responseContent);
             }
         }
         else////否则就是get方式,进行校验认证
         {
             AccessToken.Auth();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string postString = string.Empty;
                context.Response.ContentType = "text/plain";
                if (context.Request.HttpMethod.ToLower() == "post")
                {
                    using (Stream stream = HttpContext.Current.Request.InputStream)
                    {
                        Byte[] postBytes = new Byte[stream.Length];
                        stream.Read(postBytes, 0, (Int32)stream.Length);
                        postString = Encoding.UTF8.GetString(postBytes);

                        MessageHelp help            = new MessageHelp();
                        string      responseContent = help.ReturnMessage(postBytes);

                        HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
                        HttpContext.Current.Response.Write(responseContent);
                    }
                }
                else
                {
                    //从微信后台过来的请求只有初始配置时是get方式,那么就去配饰配置校验
                    Biz.WeiXin.AccessToken.Auth();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        /// <summary>
        /// 处理信息并应答
        /// </summary>
        private void Handle(string postStr)
        {
            MessageHelp help            = new MessageHelp();
            string      responseContent = help.ReturnMessage(postStr);

            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
            HttpContext.Current.Response.Write(responseContent);
        }
Пример #4
0
        /// <summary>
        /// 处理信息并应答
        /// </summary>
        private void Handle(string postStr)
        {
            //处理完成消息 回执给微信
            string responseContent = MessageHelp.getInstance().HandleMessage(Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(postStr)));

            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
            HttpContext.Current.Response.Write(responseContent);
            HttpContext.Current.Response.End();
        }
Пример #5
0
        public void Index()
        {
            string echoString = HttpContext.Current.Request.QueryString["echoStr"];
            string signature  = HttpContext.Current.Request.QueryString["signature"];
            string timestamp  = HttpContext.Current.Request.QueryString["timestamp"];
            string nonce      = HttpContext.Current.Request.QueryString["nonce"];

            //WriteLog("echoString:" + echoString + "---signature:" + signature + "---timestamp:" + timestamp + "---nonce:" + nonce);
            if (string.IsNullOrEmpty(echoString))
            {
                if (WeChatHelper.CheckSignature(signature, timestamp, nonce))
                {
                    string postString = string.Empty;
                    if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
                    {
                        //读取流消息
                        using (Stream stream = HttpContext.Current.Request.InputStream)
                        {
                            Byte[] postBytes = new Byte[stream.Length];
                            stream.Read(postBytes, 0, (Int32)stream.Length);
                            postString = Encoding.UTF8.GetString(postBytes);
                            MessageHelp help = new MessageHelp();
                            help.ToKen = GetToken();
                            string responseContent = string.Empty;
                            //判断是否加密
                            bool IsAes = HttpContext.Current.Request.QueryString["encrypt_type"] == "aes" ? true : false;
                            if (IsAes)
                            {
                                string        msg_signature = HttpContext.Current.Request.QueryString["msg_signature"];
                                WXBizMsgCrypt wmc           = new WXBizMsgCrypt(WeChatConfig.Token, WeChatConfig.EncodingAESKey, WeChatConfig.AppId);
                                string        decmsg        = string.Empty; //解密后
                                int           decnum        = wmc.DecryptMsg(msg_signature, timestamp, nonce, postString, ref postString);
                                if (decnum == 0)
                                {
                                    wmc.EncryptMsg(help.ReturnMessage(postString), timestamp, nonce, ref responseContent);
                                }
                            }
                            else
                            {
                                responseContent = help.ReturnMessage(postString);
                            }
                            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
                            HttpContext.Current.Response.Write(responseContent);
                        }
                    }
                }
            }
            else
            {
                if (WeChatHelper.CheckSignature(signature, timestamp, nonce))
                {
                    Write(echoString);
                }
            }
        }
Пример #6
0
 public System.IAsyncResult BeginHelp(MessageHelp Help, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("Help", new object[] {
         Help}, callback, asyncState);
 }