示例#1
0
        //支付宝支付结果

        /*
         * public ResultObj<int> PostPayResultA(List<ProductModel> listProductInfo)
         * {
         *
         *  IMachine _imachine = new MachineService();
         *  _imachine.PostPayResultA(listProductInfo);
         *  return Content(1);
         * }
         */
        public string PostPayResultA()
        {
            try
            {
                string outTradeNo = Fycn.Utility.HttpContext.Current.Request.Form["out_trade_no"].ToString().Trim();
                //RedisHelper helper = new RedisHelper(0);
                //log.Info(outTradeNo);
                //log.Info(helper.KeyExists(outTradeNo));

                /*
                 * if (!helper.KeyExists(outTradeNo))
                 * {
                 *  return "success";
                 * }
                 */
                /*
                 * IMachine _imachine = new MachineService();
                 * if (_imachine.GetCountByTradeNo(outTradeNo) > 0)
                 * {
                 *  return Content(1);
                 * }
                 */
                string tradeStatus = Fycn.Utility.HttpContext.Current.Request.Form["trade_status"].ToString().ToUpper();
                if (tradeStatus == "TRADE_SUCCESS")
                {
                    /*******************************放到微信支付通知参数里,因参数只支付最大128个字符长度,所以注释修改*****************************/
                    //string jsonProduct = Fycn.Utility.HttpContext.Current.Request.Form["body"];
                    //KeyJsonModel keyJsonModel = JsonHandler.GetObjectFromJson<KeyJsonModel>(jsonProduct);
                    string tradeNo  = Fycn.Utility.HttpContext.Current.Request.Form["trade_no"];
                    string sellerId = Fycn.Utility.HttpContext.Current.Request.Form["seller_id"];      //买家合作者id
                    string buyerId  = Fycn.Utility.HttpContext.Current.Request.Form["buyer_logon_id"]; //买家账号
                    //log.Info(Fycn.Utility.HttpContext.Current.Request.Form["passback_params"]);
                    //string jsonProduct = helper.StringGet(outTradeNo);
                    string jsonProduct = Fycn.Utility.HttpContext.Current.Request.Form["passback_params"];

                    //log.Info("test");
                    string gmtPayment = Fycn.Utility.HttpContext.Current.Request.Form["gmt_payment"]; //付款时间

                    //string jsonProduct = FileHandler.ReadFile("data/" + outTradeNo + ".wa");
                    //log.Info(gmtPayment);

                    KeyJsonModel keyJsonModel = JsonHandler.GetObjectFromJson <KeyJsonModel>(jsonProduct);
                    IMachine     _imachine    = new MachineService();
                    int          result       = _imachine.PostPayResultA(keyJsonModel, outTradeNo, tradeNo, sellerId, buyerId, gmtPayment);
                    if (result == 1)
                    {
                        //Fycn.Utility.HttpContext.Current.Response.Write("success");
                        //Response.WriteAsync("success");
                        List <CommandModel> lstCommand = new List <CommandModel>();
                        lstCommand.Add(new CommandModel()
                        {
                            Content = keyJsonModel.m,
                            Size    = 12
                        });
                        lstCommand.Add(new CommandModel()
                        {
                            Content = outTradeNo,
                            Size    = 22
                        });
                        lstCommand.Add(new CommandModel()
                        {
                            Content = keyJsonModel.t[0].tid,
                            Size    = 5
                        });
                        lstCommand.Add(new CommandModel()
                        {
                            Content = "4",
                            Size    = 1
                        });

                        SocketHelper.GenerateCommand(10, 41, 66, lstCommand);
                        //删除文件
                        //helper.KeyDelete(outTradeNo);
                        //FileHandler.DeleteFile("data/" + outTradeNo + ".wa");
                        if (sellerId == PathConfig.RootAliMchId)
                        {
                            IDistrubuteMoney imoney = new DistrubuteMoneyService();
                            imoney.PostMoney(outTradeNo);
                        }
                        return("success");
                    }
                }
                return("success");
            }
            catch (Exception ex)
            {
                return("success");
            }
        }
示例#2
0
        // 微信支付结果
        public string PostPayResultW()
        {
            try
            {
                var    request = Fycn.Utility.HttpContext.Current.Request;
                int    len     = (int)request.ContentLength;
                byte[] b       = new byte[len];
                Fycn.Utility.HttpContext.Current.Request.Body.Read(b, 0, len);
                string      postStr = Encoding.UTF8.GetString(b);
                XmlDocument xmlDoc  = new XmlDocument();
                xmlDoc.LoadXml(postStr);
                // 商户交易号
                XmlNode tradeNoNode = xmlDoc.SelectSingleNode("xml/out_trade_no");

                /*
                 * RedisHelper helper = new RedisHelper(0);
                 *
                 * if (!helper.KeyExists(tradeNoNode.InnerText))
                 * {
                 *  return Content(1);
                 * }
                 */
                /*
                 * IMachine _imachine = new MachineService();
                 * if (_imachine.GetCountByTradeNo(tradeNoNode.InnerText) > 0)
                 * {
                 *  return Content(1);
                 * }
                 */


                //支付结果
                XmlNode payResultNode = xmlDoc.SelectSingleNode("xml/result_code");
                if (payResultNode.InnerText.ToUpper() == "SUCCESS")
                {
                    /*******************************放到微信支付通知参数里,因参数只支付最大128个字符长度,所以注释修改*****************************/
                    //XmlNode tunnelNode = xmlDoc.SelectSingleNode("xml/attach");
                    //KeyJsonModel keyJsonModel = JsonHandler.GetObjectFromJson<KeyJsonModel>(tunnelNode.InnerText);
                    XmlNode attachNode  = xmlDoc.SelectSingleNode("xml/attach");
                    string  jsonProduct = attachNode.InnerText;                        //helper.StringGet(tradeNoNode.InnerText);
                    XmlNode mchIdNode   = xmlDoc.SelectSingleNode("xml/mch_id");       // 商户号
                    XmlNode openidNode  = xmlDoc.SelectSingleNode("xml/openid");       //买家唯一标识
                    XmlNode isSubNode   = xmlDoc.SelectSingleNode("xml/is_subscribe"); // 是否为公众号关注者
                    XmlNode timeEndNode = xmlDoc.SelectSingleNode("xml/time_end");     // 是否为公众号关注者
                    //string jsonProduct = FileHandler.ReadFile("data/" + tradeNoNode.InnerText + ".wa");

                    KeyJsonModel keyJsonModel = JsonHandler.GetObjectFromJson <KeyJsonModel>(jsonProduct);
                    IMachine     _imachine    = new MachineService();
                    int          result       = _imachine.PostPayResultW(keyJsonModel, tradeNoNode.InnerText, mchIdNode.InnerText, openidNode.InnerText, isSubNode.InnerText, timeEndNode.InnerText);
                    if (result == 1)
                    {
                        List <CommandModel> lstCommand = new List <CommandModel>();
                        lstCommand.Add(new CommandModel()
                        {
                            Content = keyJsonModel.m,
                            Size    = 12
                        });
                        lstCommand.Add(new CommandModel()
                        {
                            Content = tradeNoNode.InnerText,
                            Size    = 22
                        });
                        lstCommand.Add(new CommandModel()
                        {
                            Content = keyJsonModel.t[0].tid,
                            Size    = 5
                        });
                        lstCommand.Add(new CommandModel()
                        {
                            Content = "3",
                            Size    = 1
                        });

                        //var log = LogManager.GetLogger("FycnApi", "weixin");
                        //log.Info("test");
                        //log.Info(tradeNoNode.InnerText);
                        SocketHelper.GenerateCommand(10, 41, 66, lstCommand);
                        //删除文件
                        //helper.KeyDelete(tradeNoNode.InnerText);
                        //FileHandler.DeleteFile("data/" + tradeNoNode.InnerText + ".wa");
                        if (mchIdNode.InnerText == PathConfig.RootWeixinMchId)
                        {
                            IDistrubuteMoney imoney = new DistrubuteMoneyService();
                            imoney.PostMoney(tradeNoNode.InnerText);
                        }
                    }
                }
                return("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>");
            }
            catch (Exception ex)
            {
                return("<xml><return_code><![CDATA[FAIL]]></return_code></xml>");
            }

            //File.WriteAllText(@"c:\text.txt", postStr);
        }