/// <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" })); } }
/// <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 })); } }
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 = "支付异常,请重新支付" })); } }
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); }