Ejemplo n.º 1
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);
        }
Ejemplo 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 = "支付异常,请重新支付" }));
            }
        }