Esempio n. 1
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);
        }
Esempio n. 2
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 = "支付异常,请重新支付" }));
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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();
        }
Esempio n. 7
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();
        }