Пример #1
0
        //post数据
        public static WxPayDataTool GetResult(string url, WxPayDataTool inputobj, bool isUseCert = true)
        {
            string xml = inputobj.ToXml();
            //LogDB.DebugTest("发送的数据:" + xml);
            string response = UtilTool.Post(url, xml, isUseCert);
            //LogDB.DebugTest("接收的结果:"+response);
            WxPayDataTool result = new WxPayDataTool();

            result.FromXml(response);
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 接收从微信支付后台发送过来的数据并验证签名
        /// </summary>
        /// <returns>微信支付后台返回的数据</returns>
        public WxPayDataTool GetNotifyData(Stream InputStream)
        {
            //接收从微信后台POST过来的数据
            System.IO.Stream s = InputStream;
            int count          = 0;

            byte[]        buffer  = new byte[1024];
            StringBuilder builder = new StringBuilder();

            while ((count = s.Read(buffer, 0, 1024)) > 0)
            {
                builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
            }
            s.Flush();
            s.Close();
            s.Dispose();

            //转换数据格式并验证签名
            WxPayDataTool data = new WxPayDataTool();

            try
            {
                //LogDB.DebugTest("支付结果回调信息:" + builder.ToString());
                data.FromXml(builder.ToString());
            }
            catch (Exception ex)
            {
                //若签名错误,则立即返回结果给微信支付后台
                WxPayDataTool res = new WxPayDataTool();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", ex.Message);
                //LogDB.DebugTest("异步回调信息出错:" + res.ToXml());
                page.Response.Write(res.ToXml());
                page.Response.End();
            }
            return(data);
        }