Пример #1
0
        public string Pay()
        {
            string sTag = Request["paytype"];
            //string sBody = Request["body"];
            string sAmount      = Request["fee"];
            string sPayAccount  = Request["auth_code"];
            string sPlateNumber = Request["PlateNumber"];
            string sPKID        = Request["PKID"];

            if (sTag.IsEmpty() || (sTag != "0" && sTag != "1" && sTag != "2"))
            {
                return("2");
            }

            //if (string.IsNullOrEmpty(sBody))
            //{
            //    return "2sBody";
            //}
            if (string.IsNullOrEmpty(sAmount))
            {
                return("2");
            }

            if (sTag != "2")
            {
                if (string.IsNullOrEmpty(sPayAccount))
                {
                    return("2");
                }
            }
            if (string.IsNullOrEmpty(sPlateNumber))
            {
                return("2");
            }
            if (string.IsNullOrEmpty(sPKID))
            {
                return("2");
            }

            OnlineOrder model = new OnlineOrder();

            model.OrderTime = DateTime.Now;

            TempParkingFeeResult result = RechargeService.WXTempParkingFee(sPlateNumber, sPKID, sPayAccount, model.OrderTime);

            if (result.Result == APPResult.NoNeedPay)
            {
                return("3"); //不需要交费
            }
            if (result.Result == APPResult.RepeatPay)
            {
                return("4"); //重复交费
            }

            decimal dAmount = decimal.Parse(sAmount) / 100;

            //if (result.Pkorder.Amount != dAmount)
            //{
            //    return "6"; //金额不一致
            //}
            try
            {
                RechargeService.CheckCalculatingTempCost(result.Result);
            }
            catch (Exception ex)
            {
                return(((int)result.Result).ToString());
            }

            if (result.OrderSource == PayOrderSource.Platform)
            {
                bool testResult = CarService.WXTestClientProxyConnectionByPKID(result.ParkingID);
                if (!testResult)
                {
                    throw new MyException("车场网络异常,暂无法缴停车费!");
                }
                //int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(result.Pkorder.OrderNo);

                int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(result.Pkorder.OrderNo, result.ParkingID, result.Pkorder.TagID);
                if (interfaceOrderState != 1)
                {
                    if (interfaceOrderState == 2)
                    {
                        return("4"); //重复交费
                    }
                    else
                    {
                        return("5"); //订单已失效
                    }
                }
            }

            model.ParkCardNo   = result.CardNo;
            model.PKID         = result.ParkingID;
            model.PKName       = result.ParkName;
            model.InOutID      = result.Pkorder.TagID;
            model.PlateNo      = result.PlateNumber;
            model.EntranceTime = result.EntranceDate;
            model.ExitTime     = model.OrderTime.AddMinutes(result.OutTime);
            //model.Amount = result.Pkorder.Amount;
            model.Amount         = dAmount;
            model.PayDetailID    = result.Pkorder.OrderNo;
            model.DiscountAmount = result.Pkorder.DiscountAmount;
            // model.OrderSource = PayOrderSource.HAND;
            model.ExternalPKID = result.ExternalPKID;

            model.OrderID   = IdGenerator.Instance.GetId();
            model.Status    = OnlineOrderStatus.WaitPay;
            model.OrderType = OnlineOrderType.ParkFee;

            BaseCompany company = CompanyServices.QueryByParkingId(model.PKID);

            if (company == null)
            {
                throw new MyException("获取单位信息失败");
            }

            if (sTag == "0")
            {
                WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(company.CPID);
                if (config == null)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取微信配置信息失败", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return("-1");
                }
                if (!config.Status)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该车场暂停使用微信支付", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return("-1");
                }

                model.PayeeUser      = config.SystemName;
                model.PayeeAccount   = config.PartnerId;
                model.PayAccount     = sPayAccount;
                model.Payer          = sPayAccount;
                model.AccountID      = model.AccountID;
                model.CardId         = model.AccountID;
                model.PayeeChannel   = PaymentChannel.WeiXinPay;
                model.PaymentChannel = PaymentChannel.WeiXinPay;
                model.CompanyID      = config.CompanyID;

                bool isSuc = OnlineOrderServices.Create(model);
                if (!isSuc)
                {
                    throw new MyException("生成待缴费订单失败");
                }
            }
            else if (sTag == "1")
            {
                //支付宝
                AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(company.CPID);
                if (config == null)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取支付宝配置信息失败[0001]", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return("-1");
                }
                if (!config.Status)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该支付宝暂停使用", "单位编号:" + config.CompanyID, LogFrom.WeiXin);
                    return("-1");
                }

                model.AccountID      = string.Empty;
                model.CardId         = string.Empty;
                model.PayeeChannel   = PaymentChannel.AliPay;
                model.PaymentChannel = PaymentChannel.AliPay;
                model.PayeeUser      = config.SystemName;
                model.PayeeAccount   = config.PayeeAccount;
                model.Payer          = sPayAccount;
                model.PayAccount     = sPayAccount;
                model.CompanyID      = config.CompanyID;

                bool isSuc = OnlineOrderServices.Create(model);
                if (!isSuc)
                {
                    throw new MyException("生成待缴费订单失败");
                }
            }
            else if (sTag == "2")
            {
                //现金支付的
                model.AccountID  = string.Empty;
                model.CardId     = string.Empty;
                model.Payer      = sPayAccount;
                model.PayAccount = sPayAccount;
                model.CompanyID  = company.CPID;
            }

            //调用刷卡支付,如果内部出现异常则在页面上显示异常原因
            try
            {
                //int status=1;

                string tradeNo   = "";
                string sDataInfo = "";
                if (sTag == "0")    //微信
                {
                    if (!MicroPay.Run(model, out sDataInfo))
                    {
                        return("-2");
                    }
                    else
                    {
                        tradeNo = sDataInfo;
                        //发送通知开闸
                        bool isPayState = OnlineOrderServices.PaySuccess(model.OrderID, tradeNo, DateTime.Now, sPayAccount);
                        if (!isPayState)
                        {
                            throw new Exception("修改微信订单状态失败");
                        }

                        TxtLogServices.WriteTxtLogEx("WXPayReturn", string.Format("WXPayResult:{0}支付完成", tradeNo));
                    }
                }
                else if (sTag == "1")   //支付宝
                {
                    if (AliPayPay.Run(model, out sDataInfo) == false)
                    {
                        return("-3");
                    }
                    else
                    {
                        tradeNo = sDataInfo;

                        bool isPayState = OnlineOrderServices.PaySuccess(model.OrderID, tradeNo, DateTime.Now, sPayAccount);
                        if (!isPayState)
                        {
                            throw new Exception("修改支付宝订单状态失败");
                        }

                        TxtLogServices.WriteTxtLogEx("AliPayReturn", string.Format("AliPayShowResult:{0}支付完成", tradeNo));
                    }
                }
                else if (sTag == "2") //现金支付的
                {
                    TempStopPaymentResult payResult = RechargeService.WXTempStopPayment(result.Pkorder.OrderNo, (int)OrderPayWay.Cash, dAmount, sPKID, "", model.OrderID.ToString(), DateTime.Now);
                    TxtLogServices.WriteTxtLogEx("CashReturn", string.Format("CashShowResult:{1}:{0} 支付完成", payResult.ToXml(System.Text.Encoding.UTF8), dAmount));
                    if (payResult.Result != APPResult.Normal)
                    {
                        return("5");
                    }
                }

                //不是预支付的订单 就暂时不修改了
                //bool results = OnlineOrderServices.UpdatePrepayIdById(tradeNo, model.OrderID);
                //Response.Write("<span style='color:#00CD00;font-size:20px'>" + result + "</span>");
                ParkingFeeService.DeleteParkingFee(model.PlateNo + model.PKID);
                return("0");
            }
            //catch (WxPayException ex)
            //{
            //    return "1";
            //    //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
            //}
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("PayError", "该支付失败", "单位编号:" + model.CompanyID + "<br/>" + ex.StackTrace, LogFrom.UnKnown);
                return("-4");
                //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
            }
        }
Пример #2
0
        public void Index()
        {
            //TxtLogServices.WriteTxtLogEx("AliPayNotify", Request.Url.AbsoluteUri + ":" + Request.Form.ToString());

            try
            {
                string notify_time         = Request.Params["notify_time"];
                string notify_type         = Request.Params["notify_type"];
                string notify_id           = Request.Params["notify_id"];
                string app_id              = Request.Params["app_id"];
                string charset             = Request.Params["charset"];
                string version             = Request.Params["version"];
                string sign_type           = Request.Params["sign_type"];
                string sign                = Request.Params["sign"];
                string trade_no            = Request.Params["trade_no"];
                string out_trade_no        = Request.Params["out_trade_no"];
                string out_biz_no          = Request.Params["out_biz_no"];
                string buyer_id            = Request.Params["buyer_id"];
                string buyer_logon_id      = Request.Params["buyer_logon_id"];
                string seller_id           = Request.Params["seller_id"];
                string seller_email        = Request.Params["seller_email"];
                string trade_status        = Request.Params["trade_status"];
                string total_amount        = Request.Params["total_amount"];
                string receipt_amount      = Request.Params["receipt_amount"];
                string invoice_amount      = Request.Params["invoice_amount"];
                string buyer_pay_amount    = Request.Params["buyer_pay_amount"];
                string point_amount        = Request.Params["point_amount"];
                string refund_fee          = Request.Params["refund_fee"];
                string subject             = Request.Params["subject"];
                string gmt_create          = Request.Params["gmt_create"];
                string gmt_payment         = Request.Params["gmt_payment"];
                string gmt_refund          = Request.Params["gmt_refund"];
                string gmt_close           = Request.Params["gmt_close"];
                string fund_bill_list      = Request.Params["fund_bill_list"];
                string passback_params     = Request.Params["passback_params"];
                string voucher_detail_list = Request.Params["voucher_detail_list"];


                OnlineOrder order = OnlineOrderServices.QueryByOrderId(decimal.Parse(out_trade_no));
                if (order == null)
                {
                    throw new Exception("获取订单失败");
                }

                if (!CheckNotifySign(order.CompanyID))
                {
                    throw new Exception("验证签名失败");
                }

                TxtLogServices.WriteTxtLogEx("AliPayNotify", "验签成功:out_trade_no:" + out_trade_no);
                DateTime payTime = DateTime.Now;
                DateTime.TryParse(gmt_payment, out payTime);
                WeiXinInerface.ParkingFeeService.DeleteParkingFee(order.PlateNo + order.PKID);
                bool result = OnlineOrderServices.PaySuccess(decimal.Parse(out_trade_no), trade_no, payTime, buyer_id);
                if (!result)
                {
                    throw new Exception("修改订单状态未已支付失败");
                }

                TxtLogServices.WriteTxtLogEx("AliPayNotify", string.Format("AliPayShowResult:{0}支付完成", trade_no));
                Response.Write("success");
                Response.End();
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("AliPayNotify", "支付通知出错", ex, LogFrom.AliPay);
                Response.Write("fail");
                Response.End();
            }
        }
Пример #3
0
        /// <summary>
        /// 订单支付通道
        /// </summary>
        public void Index()
        {
            ReturnMessage returnMsg = new ReturnMessage()
            {
                Return_Code = "SUCCESS", Return_Msg = ""
            };
            string        xmlString = GetXmlString(Request);
            NotifyMessage message   = null;

            try
            {
                TxtLogServices.WriteTxtLogEx("WeiXinPayNotify", xmlString);
                //此处应记录日志
                message = XmlHelper.Deserialize <NotifyMessage>(xmlString);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmlString);

                Dictionary <string, string> dic = new Dictionary <string, string>();
                string sign = string.Empty;
                foreach (XmlNode node in doc.FirstChild.ChildNodes)
                {
                    if (node.Name.ToLower() != "sign")
                    {
                        dic.Add(node.Name, node.InnerText);
                    }
                    else
                    {
                        sign = node.InnerText;
                    }
                }
                //处理通知
                decimal orderId;
                if (!dic.ContainsKey("out_trade_no") || !decimal.TryParse(dic["out_trade_no"], out orderId))
                {
                    throw new MyException("支付回调订单编号格式不正确");
                }

                OnlineOrder order = OnlineOrderServices.QueryByOrderId(orderId);
                if (order == null)
                {
                    throw new MyException("订单存在,orderId:" + orderId);
                }

                UnifiedPayModel model = UnifiedPayModel.CreateUnifiedModel(order.CompanyID);
                if (!model.ValidateMD5Signature(dic, sign))
                {
                    throw new Exception("签名未通过!");
                }

                if (!dic.ContainsKey("transaction_id"))
                {
                    throw new MyException("支付流水号不存在");
                }

                string payTradeNo = dic["transaction_id"];

                DateTime payTime = DateTime.Now;
                if (dic.ContainsKey("time_end") && dic["time_end"].Length == 14)
                {
                    string strDate = dic["time_end"].Insert(4, "-").Insert(7, "-").Insert(10, " ").Insert(13, ":").Insert(16, ":");
                    if (!DateTime.TryParse(strDate, out payTime))
                    {
                        payTime = DateTime.Now;
                    }
                }
                string payAccount = string.Empty;
                if (dic.ContainsKey("attach") && dic["attach"] == "MWEB" && dic.ContainsKey("openid") && !string.IsNullOrWhiteSpace(dic["openid"]))
                {
                    payAccount = dic["openid"];
                }
                else if (dic.ContainsKey("attach") && dic["attach"].Length > 0)
                {
                    //统计二维码推广订单信息
                    string   sAgendID = dic["attach"];
                    tgPerson person   = tgPersonServices.QueryPersonByID(int.Parse(sAgendID));
                    TgOrder  to       = new TgOrder();
                    to.OrderID     = order.OrderID;
                    to.PKID        = order.PKID;
                    to.PKName      = order.PKName;
                    to.PlateNo     = order.PlateNo;
                    to.Amount      = order.Amount;
                    to.RealPayTime = payTime;
                    to.PersonId    = person.id;
                    to.PersonName  = person.name;
                    TgOrderService.Addperson(to);
                }

                //if (Request.Cookies["SmartSystem_WeiXinTg_personid"] != null)
                //{

                //}
                WeiXinInerface.ParkingFeeService.DeleteParkingFee(order.PlateNo + order.PKID);
                OnlineOrderServices.PaySuccess(orderId, payTradeNo, payTime, payAccount);
            }
            catch (MyException ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPayNotify", "支付通知出错:" + ex.Message, ex, LogFrom.WeiXin);
                //此处记录异常日志
                returnMsg.Return_Code = "FAIL";
                returnMsg.Return_Msg  = ex.Message;
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPayNotify", "支付通知出错", ex, LogFrom.WeiXin);
                //此处记录异常日志
                returnMsg.Return_Code = "FAIL";
                returnMsg.Return_Msg  = ex.Message;
            }
            Response.Write(returnMsg.ToXmlString());
            Response.End();
        }