예제 #1
0
        /// <summary>
        /// 商家充值
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ActionResult SellerRechargePayment(decimal orderId)
        {
            try
            {
                OnlineOrder order = CheckOrder(orderId);
                if (order.OrderType != OnlineOrderType.SellerRecharge)
                {
                    throw new MyException("支付方法不正确");
                }

                if (string.IsNullOrWhiteSpace(order.MWebUrl))
                {
                    UnifiedPayModel model = GetUnifiedPayModel(order, string.Format("商家充值-{0}", order.PKName));
                }
                ViewBag.MWeb_Url = order.MWebUrl;
                return(View(order));
            }
            catch (MyException ex)
            {
                TxtLogServices.WriteTxtLogEx("H5WeiXinPayment_Error", "支付失败 orderId:{0};", orderId, ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message, returnUrl = "/H5Seller/Index" }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("H5WeiXinPayment_Error", string.Format("商家充值支付失败 orderId:{0};", orderId), ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付失败,请重新支付", returnUrl = "/H5Seller/Index" }));
            }
        }
예제 #2
0
 /// <summary>
 /// 临停缴费
 /// </summary>
 /// <param name="orderId"></param>
 /// <returns></returns>
 public ActionResult ParkCarPayment(decimal orderId)
 {
     try
     {
         OnlineOrder order = CheckOrder(orderId);
         if (order.OrderType != OnlineOrderType.ParkFee)
         {
             throw new MyException("支付方法不正确");
         }
         if (string.IsNullOrWhiteSpace(order.MWebUrl))
         {
             UnifiedPayModel model = GetUnifiedPayModel(order, string.Format("临停缴费-{0}-{1}", order.PKName, order.PlateNo));
         }
         ViewBag.MaxWaitTime = DateTime.Now.AddMinutes(WXOtherConfigServices.GetTempParkingWeiXinPayTimeOut(order.CompanyID)).ToString("yyyy-MM-dd HH:mm:ss");
         ViewBag.MWeb_Url    = order.MWebUrl;
         return(View(order));
     }
     catch (MyException ex) {
         return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message, returnUrl = "/H5ParkingPayment/Index" }));
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("H5WeiXinPayment_Error", string.Format("Message:{0},StackTrace:{1}", ex.Message, ex.StackTrace), LogFrom.WeiXin);
         return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付失败,请重新支付", returnUrl = "/H5ParkingPayment/Index" }));
     }
 }
예제 #3
0
        /// <summary>
        /// APP充值
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ActionResult BalancePayment(decimal orderId)
        {
            try
            {
                OnlineOrder order = CheckOrder(orderId);
                if (order.OrderType != OnlineOrderType.APPRecharge)
                {
                    throw new MyException("支付方法不正确");
                }

                UnifiedPayModel    model    = GetUnifiedPayModel(order, string.Format("{0}-APP充值", order.PlateNo));
                WeiXinPaySignModel payModel = GetWeiXinPaySign(order, model);
                ViewBag.PayModel = payModel;
                return(View(order));
            }
            catch (MyException ex)
            {
                TxtLogServices.WriteTxtLogEx("WeiXinPayment_Error", "支付失败 orderId:{0};openId:{1}", orderId, WeiXinOpenId, ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message, returnUrl = "/PurseData/Index" }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPayment_Error", string.Format("APP充值支付失败 orderId:{0};openId:{1}", orderId, WeiXinOpenId), ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付失败,请重新支付", returnUrl = "/PurseData/Index" }));
            }
        }
예제 #4
0
        /// <summary>
        /// 临停缴费
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ActionResult ParkCarPayment(decimal orderId, int source = 0)
        {
            string returnUrl = source == 0 ? "/ParkingPayment/Index" : "/QRCodeParkPayment/QRCodePaySuccess?orderId=" + orderId;

            try
            {
                OnlineOrder order = CheckOrder(orderId);
                if (order.OrderType != OnlineOrderType.ParkFee)
                {
                    throw new MyException("支付方法不正确");
                }
                if (!OnlineOrderServices.UpdateSFMCode(order))
                {
                    throw new MyException("处理订单信息异常【SFM】");
                }

                string             sAttach  = Convert.ToString(Session["SmartSystem_WeiXinTg_personid"]);
                UnifiedPayModel    model    = GetUnifiedPayModel(order, string.Format("临停缴费-{0}", order.PlateNo), sAttach);
                WeiXinPaySignModel payModel = GetWeiXinPaySign(order, model);
                ViewBag.MaxWaitTime = DateTime.Now.AddMinutes(WXOtherConfigServices.GetTempParkingWeiXinPayTimeOut(order.CompanyID)).ToString("yyyy-MM-dd HH:mm:ss");
                ViewBag.PayModel    = payModel;
                ViewBag.ReturnUrl   = returnUrl;
                ViewBag.Source      = source;
                Session["SmartSystem_WeiXinTg_personid"] = null;
                return(View(order));
            }
            catch (MyException ex) {
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message, returnUrl = returnUrl }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPayment_Error", string.Format("支付失败 orderId:{0};openId:{1}", orderId, WeiXinOpenId), ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付失败,请重新支付", returnUrl = returnUrl }));
            }
        }
예제 #5
0
        /// <summary>
        /// V3 统一订单查询接口
        /// </summary>
        /// <param name="postXml"></param>
        /// <returns></returns>
        public static UnifiedOrderQueryMessage UnifiedOrderQuery(string companyId, string transactionId, string orderId)
        {
            UnifiedPayModel          model   = UnifiedPayModel.CreateUnifiedModel(companyId);
            string                   postXml = model.CreateOrderQueryXml(transactionId, orderId);
            string                   url     = WeiXinPayConst.WeiXin_Pay_UnifiedOrderQueryUrl;
            UnifiedOrderQueryMessage message = HttpHelper.PostXmlResponse <UnifiedOrderQueryMessage>(url, postXml);

            return(message);
        }
예제 #6
0
        public ActionResult AdvanceParkingPayment(decimal orderId)
        {
            try
            {
                AdvanceParking order = AdvanceParkingServices.QueryByOrderId(orderId);
                if (order == null)
                {
                    throw new MyException("支付信息不存在");
                }
                if (order.OrderState != 0)
                {
                    throw new MyException("支付状态不正确");
                }

                UnifiedPayModel model = UnifiedPayModel.CreateUnifiedModel(order.CompanyID);
                if (string.IsNullOrWhiteSpace(order.PrepayId))
                {
                    string payNotifyAddress = string.Format("{0}{1}", WXApiConfigServices.QueryWXApiConfig(order.CompanyID).Domain, "/WeiXinPayNotify/AdvanceParking");
                    //预支付
                    UnifiedPrePayMessage result = PaymentServices.UnifiedPrePay(model.CreatePrePayPackage(order.OrderId.ToString(), ((int)(order.Amount * 100)).ToString(), WeiXinOpenId, "预停车支付", payNotifyAddress));
                    if (result == null || !result.ReturnSuccess || !result.ResultSuccess || string.IsNullOrEmpty(result.Prepay_Id))
                    {
                        throw new Exception(string.Format("获取PrepayId 失败,Message:{0}", result.ToXmlString()));
                    }
                    AdvanceParkingServices.UpdatePrepayIdById(result.Prepay_Id, order.OrderId);
                    order.PrepayId = result.Prepay_Id;
                }
                WeiXinPaySignModel payModel = new WeiXinPaySignModel()
                {
                    AppId     = model.AppId,
                    Package   = string.Format("prepay_id={0}", order.PrepayId),
                    Timestamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString(),
                    Noncestr  = Util.CreateNoncestr(),
                };

                Dictionary <string, string> nativeObj = new Dictionary <string, string>();
                nativeObj.Add("appId", payModel.AppId);
                nativeObj.Add("package", payModel.Package);
                nativeObj.Add("timeStamp", payModel.Timestamp);
                nativeObj.Add("nonceStr", payModel.Noncestr);
                nativeObj.Add("signType", payModel.SignType);
                payModel.PaySign = model.GetCftPackage(nativeObj); //生成JSAPI 支付签名

                ViewBag.PayModel = payModel;
                return(View(order));
            }
            catch (MyException ex)
            {
                return(PageAlert("Index", "AdvanceParking", new { RemindUserContent = ex.Message }));
            }
            catch (Exception ex) {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPayment_Error", string.Format("预停车支付失败 orderId:{0};openId:{1}", orderId, WeiXinOpenId), ex, LogFrom.WeiXin);
                return(PageAlert("Index", "AdvanceParking", new { RemindUserContent = "支付异常,请重新支付" }));
            }
        }
예제 #7
0
        public static bool CloseOrderPay(string companyId, string out_trade_no)
        {
            UnifiedPayModel model    = UnifiedPayModel.CreateUnifiedModel(companyId);
            string          postData = model.CreateClosePayPackage(out_trade_no);

            TxtLogServices.WriteTxtLogEx("CloseOrderPay", "OrderId:{0},Request Xml:{1}", out_trade_no, postData);

            string url     = WeiXinPayConst.WeiXin_Pay_ClosePayUrl;
            var    message = HttpHelper.PostXmlResponse <ClosePayMessage>(url, postData);

            TxtLogServices.WriteTxtLogEx("CloseOrderPay", " OrderId:{0}, Return Xml:{1},Result:{2}", out_trade_no, message.ToXmlString(), message.Success ? "成功" : "失败");
            return(message.Success);
        }
예제 #8
0
        private UnifiedPayModel GetUnifiedPayModel(OnlineOrder order, string description, string attach = "")
        {
            UnifiedPayModel model = UnifiedPayModel.CreateUnifiedModel(order.CompanyID);

            if (string.IsNullOrWhiteSpace(order.PrepayId))
            {
                string payNotifyAddress = string.Format("{0}{1}", WXApiConfigServices.QueryWXApiConfig(order.CompanyID).Domain, "/WeiXinPayNotify/Index");
                //预支付
                string postData             = model.CreatePrePayPackage(order.OrderID.ToString(), ((int)(order.Amount * 100)).ToString(), WeiXinOpenId, description, payNotifyAddress, attach);
                UnifiedPrePayMessage result = PaymentServices.UnifiedPrePay(postData);
                if (result == null || !result.ReturnSuccess || !result.ResultSuccess || string.IsNullOrEmpty(result.Prepay_Id))
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPayment_Error", "预支付", string.Format("postData:{0}", postData), LogFrom.WeiXin);
                    throw new Exception(string.Format("获取PrepayId 失败,Message:{0}", result.ToXmlString()));
                }
                OnlineOrderServices.UpdatePrepayIdById(result.Prepay_Id, order.OrderID);
                order.PrepayId = result.Prepay_Id;
            }
            return(model);
        }
예제 #9
0
        private WeiXinPaySignModel GetWeiXinPaySign(OnlineOrder order, UnifiedPayModel model)
        {
            WeiXinPaySignModel payModel = new WeiXinPaySignModel()
            {
                AppId     = model.AppId,
                Package   = string.Format("prepay_id={0}", order.PrepayId),
                Timestamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString(),
                Noncestr  = Util.CreateNoncestr(),
            };

            Dictionary <string, string> nativeObj = new Dictionary <string, string>();

            nativeObj.Add("appId", payModel.AppId);
            nativeObj.Add("package", payModel.Package);
            nativeObj.Add("timeStamp", payModel.Timestamp);
            nativeObj.Add("nonceStr", payModel.Noncestr);
            nativeObj.Add("signType", payModel.SignType);
            payModel.PaySign = model.GetCftPackage(nativeObj); //生成JSAPI 支付签名
            return(payModel);
        }
예제 #10
0
        /// <summary>
        /// 申请退款(V3接口)
        /// </summary>
        /// <param name="postData">请求参数</param>
        /// <param name="certPath">证书路径</param>
        /// <param name="certPwd">证书密码</param>
        public static bool Refund(string comapnyId, string transaction_Id, string out_trade_no, string total_fee, string refund_fee, string refundNo, string certpath)
        {
            TxtLogServices.WriteTxtLogEx("WeiXin_Request_Refund", "transaction_Id:{0};out_trade_no:{1};total_fee:{2};refund_fee:{3};refundNo:{4}", transaction_Id, out_trade_no, total_fee, refund_fee, refundNo);
            UnifiedPayModel model    = UnifiedPayModel.CreateUnifiedModel(comapnyId);
            string          postData = model.CreateOrderRefundXml(out_trade_no, transaction_Id, total_fee, refundNo, refund_fee);

            TxtLogServices.WriteTxtLogEx("WeiXin_Request_Refund", "postData xml:{0}", postData);
            WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(comapnyId);

            TxtLogServices.WriteTxtLogEx("WeiXin_Request_Refund", "config:{0}", config == null?"is null":"is not null");
            if (config == null || string.IsNullOrWhiteSpace(config.CertPath) || string.IsNullOrWhiteSpace(config.CertPwd))
            {
                throw new MyException("获取支付配置失败");
            }
            string        path    = string.Format("{0}{1}", certpath, config.CertPath.TrimStart('/'));
            string        url     = WeiXinPayConst.WeiXin_Pay_UnifiedOrderRefundUrl;
            RefundMessage message = PostXmlResponse <RefundMessage>(url, postData, path, config.CertPwd);

            TxtLogServices.WriteTxtLogEx("WeiXin_Request_Refund", "OrderId:{0};return Xml:{1}", out_trade_no, message.ToXmlString());

            return(message.Success);
        }
예제 #11
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();
        }
예제 #12
0
        public void AdvanceParking()
        {
            ReturnMessage returnMsg = new ReturnMessage()
            {
                Return_Code = "SUCCESS", Return_Msg = ""
            };
            string        xmlString = GetXmlString(Request);
            NotifyMessage message   = null;

            try
            {
                TxtLogServices.WriteTxtLogEx("AdvanceParkingPayNotify", 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("支付回调订单编号格式不正确");
                }

                AdvanceParking order = AdvanceParkingServices.QueryByOrderId(orderId);
                if (order == null)
                {
                    throw new MyException("获取预订单失败");
                }

                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;
                    }
                }
                AdvanceParkingServices.PaySuccess(orderId, payTradeNo, payTime);
            }
            catch (MyException ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("AdvanceParkingPayNotify", "支付通知出错:" + ex.Message, ex, LogFrom.WeiXin);
                //此处记录异常日志
                returnMsg.Return_Code = "FAIL";
                returnMsg.Return_Msg  = ex.Message;
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("AdvanceParkingPayNotify", "支付通知出错", ex, LogFrom.WeiXin);
                //此处记录异常日志
                returnMsg.Return_Code = "FAIL";
                returnMsg.Return_Msg  = ex.Message;
            }
            Response.Write(returnMsg.ToXmlString());
            Response.End();
        }