public static string MakePreAliPayOrder(string companyId, PreAliPayOrderModel model) { try { AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(companyId); if (config == null) { throw new MyException("获取支付宝配置失败"); } string aliPayNotifyUrl = string.Format("{0}/AliPayNotify", config.SystemDomain); AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); request.BizContent = JsonHelper.GetJsonString(model); request.SetNotifyUrl(aliPayNotifyUrl); AlipayTradePrecreateResponse response = GetDefaultAopClient(companyId).Execute(request); if (response.IsError) { TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("预下单失败:{0}", response.Body)); return(""); } return(response.QrCode); } catch (Exception ex) { TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("预下单失败:{0}", ex.Message)); } return(""); }
private static void CheckApiConfigInfo(string companyId) { AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(companyId); if (config == null) { throw new MyException("获取支付宝配置失败"); } if (string.IsNullOrWhiteSpace(config.SystemDomain)) { throw new MyException("获取支付宝SystemDomain配置失败"); } if (string.IsNullOrWhiteSpace(config.AppId)) { throw new MyException("获取支付宝AppId配置失败"); } if (string.IsNullOrWhiteSpace(config.PrivateKey)) { throw new MyException("获取支付宝PrivateKey配置失败"); } if (string.IsNullOrWhiteSpace(config.PublicKey)) { throw new MyException("获取支付宝PublicKey配置失败"); } if (string.IsNullOrWhiteSpace(config.SystemName)) { throw new MyException("获取支付宝SystemName配置失败"); } if (string.IsNullOrWhiteSpace(config.PayeeAccount)) { throw new MyException("获取支付宝PayeeAccount配置失败"); } }
public ActionResult Index(string preferentialMoney = "0", string payMoney = "0", bool showPreferentialMoney = true, string alreadyPayment = "0", bool showWaitPayMoney = true) { ViewBag.PreferentialMoney = preferentialMoney; ViewBag.PayMoney = payMoney; ViewBag.ShowWaitPayMoney = showWaitPayMoney; ViewBag.ShowPreferentialMoney = showPreferentialMoney; ViewBag.AlreadyPayment = alreadyPayment; bool SupportWeiXinPayment = false; bool SupportAliPayment = false; if (!string.IsNullOrWhiteSpace(GetRequestCompanyId)) { AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(GetRequestCompanyId); if (config != null) { SupportAliPayment = true; } WX_ApiConfig wxConfig = WXApiConfigServices.QueryWXApiConfig(GetRequestCompanyId); if (wxConfig != null) { SupportWeiXinPayment = true; } } ViewBag.SupportWeiXinPayment = SupportWeiXinPayment; ViewBag.SupportAliPayment = SupportAliPayment; return(PartialView()); }
public static bool AddOrUpdate(AliPayApiConfig model) { if (string.IsNullOrWhiteSpace(model.CompanyID)) { throw new MyException("获取单位编号失败"); } IAliPayApiConfig factory = AliPayApiConfigFactory.GetFactory(); if (factory.QueryByCompanyID(model.CompanyID) != null) { bool result = factory.Update(model); if (result) { RefreshCache(); } return(result); } model.RecordId = GuidGenerator.GetGuidString(); bool addResult = factory.Add(model); if (addResult) { RefreshCache(); } return(addResult); }
public ActionResult Index(string id, string state) { try { if (SourceClient != RequestSourceClient.AliPay) { return(RedirectToAction("Index", "ErrorPrompt", new { message = "请用支付宝页面打开" })); } ClearQRCodeCookie(); TxtLogServices.WriteTxtLogEx("AliPayAuthorize", string.Format("state:{0}", state)); if (!string.IsNullOrWhiteSpace(state) && string.IsNullOrWhiteSpace(id)) { id = state; } Dictionary <string, string> dicParams = GetRequestParams(id); if (!dicParams.ContainsKey("COMPANYID")) { throw new MyException("获取单位信息失败"); } AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(dicParams["COMPANYID"]); if (config == null) { return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝配置失败" })); } if (!config.Status) { return(RedirectToAction("Index", "ErrorPrompt", new { message = "已暂停支付宝支付,稍后再试!" })); } Session["CurrLoginAliPayApiConfig"] = config; if (string.IsNullOrWhiteSpace(Request["auth_code"])) { TxtLogServices.WriteTxtLogEx("AliPayAuthorize", string.Format("autState:{0}", id)); string publicAppAuthorizeUrl = AliPayApiServices.GetPublicAppAuthorizeUrl(id, config); TxtLogServices.WriteTxtLogEx("AliPayAuthorize", string.Format("PublicAppAuthorizeUrl:{0}", publicAppAuthorizeUrl)); return(Redirect(publicAppAuthorizeUrl)); } string auth_code = Request["auth_code"]; TxtLogServices.WriteTxtLogEx("AliPayAuthorize", string.Format("auth_code:{0}", auth_code)); string userId = ""; string aliAccessToken = AliPayApiServices.GetAccessToken(dicParams["COMPANYID"], auth_code, ref userId); if (string.IsNullOrWhiteSpace(aliAccessToken) || string.IsNullOrWhiteSpace(aliAccessToken) || string.IsNullOrWhiteSpace(userId)) { throw new MyException("获取支付宝用户授权信息失败"); } TxtLogServices.WriteTxtLogEx("AliPayAuthorize", string.Format("userId:{0}", userId)); Response.Cookies.Add(new HttpCookie("SmartSystem_AliPay_UserId", userId)); return(Redir(id, userId)); } catch (MyException ex) { TxtLogServices.WriteTxtLogEx("AliPayAuthorize", ex); return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message })); } catch (Exception ex) { TxtLogServices.WriteTxtLogEx("AliPayAuthorize", ex); return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝授权失败" })); } }
public static string GetPublicAppAuthorizeUrl(string state, AliPayApiConfig config) { if (config == null) { throw new MyException("获取支付宝配置失败"); } string redirect_uri = HttpUtility.UrlEncode(string.Format("{0}/AliPayAuthorize/Index", config.SystemDomain)); return(string.Format("{0}?app_id={1}&scope=auth_base&redirect_uri={2}&state={3}", AliPayParam.authUrl, config.AppId, redirect_uri, state)); }
public static IAopClient GetDefaultAopClient(string companyId) { AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(companyId); if (config == null) { throw new MyException("获取支付宝配置失败"); } string signType = config.AliPaySignType == 0 ? "RSA" : "RSA2"; return(new DefaultAopClient(AliPayParam.serverUrl, config.AppId, config.PrivateKey, AliPayParam.format, AliPayParam.version, signType, config.PublicKey, AliPayParam.charset, false)); }
public JsonResult GetAlipayApiConfig(string companyId) { try { AliPayApiConfig config = AliPayApiConfigServices.QueryByCompanyID(companyId); return(Json(MyResult.Success(string.Empty, config))); } catch (Exception ex) { ExceptionsServices.AddExceptions(ex, "获取支付宝配置信息失败"); return(Json(MyResult.Error("获取支付宝配置信息失败"))); } }
public static IAlipayTradeService GetDefaultF2FClient(string companyId) { AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(companyId); if (config == null) { throw new MyException("获取支付宝配置失败"); } string signType = config.AliPaySignType == 0 ? "RSA" : "RSA2"; return(F2FBiz.CreateClientInstance(AliPayParam.serverUrl, config.AppId, config.PrivateKey, AliPayParam.version, signType, config.PublicKey, "utf-8")); }
/// <summary> /// 当前单位或上级的支付宝配置 /// </summary> /// <param name="companyId"></param> /// <returns></returns> public static AliPayApiConfig QueryAliPayConfig(string companyId) { try { AliPayApiConfig config = staticApiConfigs.FirstOrDefault(p => p.CompanyID == companyId); if (config != null && config.Status) { return(config); } bool result = true; while (result) { if (string.IsNullOrWhiteSpace(companyId)) { result = false; break; } BaseCompany company = CompanyServices.QueryCompanyByRecordId(companyId); if (company == null) { result = false; break; } config = staticApiConfigs.FirstOrDefault(p => p.CompanyID == companyId); if (config == null) { companyId = company.MasterID; continue; } if (!config.Status && config.SupportSuperiorPay) { companyId = company.MasterID; continue; } break; } return(config); } catch (Exception ex) { TxtLogServices.WriteTxtLogEx("WXApiConfigServices", "当前单位或上级的支付宝配置失败", ex); return(null); } }
public static bool RSACheckV1(string companyId, IDictionary <string, string> paramsMap) { try { AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(companyId); if (config == null) { throw new MyException("获取支付宝配置失败"); } string signType = config.AliPaySignType == 0 ? "RSA" : "RSA2"; return(AlipaySignature.RSACheckV1(paramsMap, config.PublicKey, AliPayParam.charset, signType, false)); } catch (Exception ex) { TxtLogServices.WriteTxtLogEx("AliPayApiServices", "验签报错:" + ex.StackTrace); return(false); } }
public bool Update(AliPayApiConfig model) { using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Ali_ApiConfig set SystemName=@SystemName,SystemDomain=@SystemDomain,AppId=@AppId,PublicKey=@PublicKey,PrivateKey=@PrivateKey,PayeeAccount=@PayeeAccount,Status=@Status,SupportSuperiorPay=@SupportSuperiorPay,AliPaySignType=@AliPaySignType"); strSql.Append(" where CompanyID=@CompanyID"); dbOperator.ClearParameters(); dbOperator.AddParameter("CompanyID", model.CompanyID); dbOperator.AddParameter("SystemName", model.SystemName); dbOperator.AddParameter("SystemDomain", model.SystemDomain); dbOperator.AddParameter("AppId", model.AppId); dbOperator.AddParameter("PublicKey", model.PublicKey); dbOperator.AddParameter("PrivateKey", model.PrivateKey); dbOperator.AddParameter("PayeeAccount", model.PayeeAccount); dbOperator.AddParameter("Status", model.Status); dbOperator.AddParameter("SupportSuperiorPay", model.SupportSuperiorPay); dbOperator.AddParameter("AliPaySignType", model.AliPaySignType); return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0); } }
public bool Add(AliPayApiConfig model) { using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Ali_ApiConfig(RecordId,SystemName,SystemDomain,AppId,PublicKey,PrivateKey,PayeeAccount,CompanyID,Status,SupportSuperiorPay,AliPaySignType)"); strSql.Append(" values(@RecordId,@SystemName,@SystemDomain,@AppId,@PublicKey,@PrivateKey,@PayeeAccount,@CompanyID,@Status,@SupportSuperiorPay,@AliPaySignType)"); dbOperator.ClearParameters(); dbOperator.AddParameter("RecordId", model.RecordId); dbOperator.AddParameter("SystemName", model.SystemName); dbOperator.AddParameter("SystemDomain", model.SystemDomain); dbOperator.AddParameter("AppId", model.AppId); dbOperator.AddParameter("PublicKey", model.PublicKey); dbOperator.AddParameter("PrivateKey", model.PrivateKey); dbOperator.AddParameter("PayeeAccount", model.PayeeAccount); dbOperator.AddParameter("CompanyID", model.CompanyID); dbOperator.AddParameter("Status", model.Status); dbOperator.AddParameter("SupportSuperiorPay", model.SupportSuperiorPay); dbOperator.AddParameter("AliPaySignType", model.AliPaySignType); return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0); } }
public JsonResult AddOrUpdate(AliPayApiConfig config) { try { config.SystemDomain = config.SystemDomain.TrimEnd('/'); bool result = AliPayApiConfigServices.AddOrUpdate(config); if (!result) { throw new MyException("保存失败"); } return(Json(MyResult.Success("", config.RecordId))); } catch (MyException ex) { return(Json(MyResult.Error(ex.Message))); } catch (Exception ex) { ExceptionsServices.AddExceptions(ex, "保存支付宝配置信息失败"); return(Json(MyResult.Error("保存失败"))); } }
public static string BarCodePayOrder(string companyId, AlipayTradeOrderModel model) { try { AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(companyId); if (config == null) { throw new MyException("获取支付宝配置失败"); } IAlipayTradeService serviceClient = GetDefaultF2FClient(companyId); AlipayTradePayContentBuilder builder = BuildPayContent(model); string out_trade_no = builder.out_trade_no; AlipayF2FPayResult payResult = serviceClient.tradePay(builder); TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("F2F支付:{0}\r\nResult:{1}", builder.ToXml(Encoding.GetEncoding("GB2312")), payResult.response.Body)); switch (payResult.Status) { case ResultEnum.SUCCESS: return(payResult.response.TradeNo); case ResultEnum.FAILED: return(""); case ResultEnum.UNKNOWN: return("-1"); } } catch (Exception ex) { TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("统一下单失败2:{0}", ex.Message)); } return("-2"); }
public ActionResult SubmitParkingPaymentRequest(OnlineOrder model) { try { if (model.OrderSource == PayOrderSource.Platform) { int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(model.PayDetailID); if (interfaceOrderState != 1) { string msg = interfaceOrderState == 2 ? "重复支付" : "订单已失效"; return(RedirectToAction("Index", "ErrorPrompt", new { message = msg, returnUrl = "/H5ParkingPayment/Index" })); } } model.OrderID = IdGenerator.Instance.GetId(); model.Status = OnlineOrderStatus.WaitPay; model.OrderType = OnlineOrderType.ParkFee; model.Amount = model.Amount; BaseCompany company = CompanyServices.QueryByParkingId(model.PKID); if (company == null) { throw new MyException("获取单位信息失败"); } if (model.PaymentChannel == PaymentChannel.AliPay) { AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(company.CPID); if (config == null) { ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "获取支付宝配置信息失败[0001]", "单位编号:" + company.CPID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝配置信息失败!" })); } if (!config.Status) { ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "该支付宝暂停使用", "单位编号:" + config.CompanyID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用支付宝支付!" })); } AliPayApiConfig requestConfig = AliPayApiConfigServices.QueryAliPayConfig(GetRequestCompanyId); if (requestConfig == null) { throw new MyException("获取请求单位微信配置失败"); } if (config.CompanyID != requestConfig.CompanyID) { ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "支付的支付宝配置和请求的支付配置不匹配,不能支付", string.Format("支付单位:{0},请求单位:{1}", config.CompanyID, requestConfig.CompanyID), LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付的支付宝配置和请求的支付配置不匹配,不能支付!" })); } model.AccountID = LoginAccountID; model.CardId = string.Empty; model.PayeeChannel = PaymentChannel.AliPay; model.PaymentChannel = PaymentChannel.AliPay; model.PayeeUser = config.SystemName; model.PayeeAccount = config.PayeeAccount; model.PayAccount = string.Empty; model.Payer = model.PayAccount; model.CompanyID = config.CompanyID; } else { WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(company.CPID); if (config == null) { ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "获取微信配置信息失败", "单位编号:" + company.CPID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取微信配置信息失败!" })); } if (!config.Status) { ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "该车场暂停使用微信支付", "单位编号:" + company.CPID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用微信支付!" })); } WX_ApiConfig requestConfig = WXApiConfigServices.QueryWXApiConfig(GetRequestCompanyId); if (requestConfig == null) { throw new MyException("获取请求单位微信配置失败"); } if (config.CompanyID != requestConfig.CompanyID) { ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "微信支付配置和当前请求微信支付配置不匹配,不能支付", string.Format("支付单位:{0},请求单位:{1}", config.CompanyID, requestConfig.CompanyID), LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "微信支付配置和当前请求微信支付配置不匹配,不能支付!" })); } model.PayeeUser = config.SystemName; model.PayeeAccount = config.PartnerId; model.PayAccount = string.Empty; model.Payer = model.PayAccount; model.AccountID = LoginAccountID; model.CardId = model.AccountID; model.PayeeChannel = PaymentChannel.WeiXinPay; model.PaymentChannel = PaymentChannel.WeiXinPay; model.CompanyID = config.CompanyID; } bool result = OnlineOrderServices.Create(model); if (!result) { throw new MyException("生成待缴费订单失败"); } switch (model.PaymentChannel) { case PaymentChannel.WeiXinPay: { return(RedirectToAction("ParkCarPayment", "H5WeiXinPayment", new { orderId = model.OrderID })); } case PaymentChannel.AliPay: { return(RedirectToAction("AliPayRequest", "H5Order", new { orderId = model.OrderID, requestSource = 1 })); } default: throw new MyException("支付方式错误"); } } catch (MyException ex) { return(RedirectToAction("ComputeParkingFee", "H5CodeParkPayment", new { licensePlate = model.PlateNo, RemindUserContent = ex.Message })); } catch (Exception ex) { ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "保存临停缴费订单失败", ex, LogFrom.WeiXin); return(RedirectToAction("ComputeParkingFee", "H5CodeParkPayment", new { licensePlate = model.PlateNo, RemindUserContent = "提交支付失败" })); } }
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>"); } }
public ActionResult SubmitMonthRenewals(string cardId, int month, double paymoney, PaymentChannel paytype, DateTime afterdate, string plateno, int source) { try { List <ParkUserCarInfo> carInfos = new List <ParkUserCarInfo>(); if (source == 1) { carInfos = RechargeService.GetMonthCarInfoByPlateNumber(plateno); } else { if (UserAccount != null) { carInfos = RechargeService.GetMonthCarInfoByAccountID(UserAccount.AccountID); } } ParkUserCarInfo card = carInfos.FirstOrDefault(p => p.CardID == cardId); if (card == null) { throw new MyException("获月卡信息失败"); } CheckMonthCardOrder(card, month, paymoney, paytype, afterdate); BaseCompany company = CompanyServices.QueryByParkingId(card.PKID); if (company == null) { throw new MyException("获取单位信息失败"); } OnlineOrder model = new OnlineOrder(); if (paytype == PaymentChannel.AliPay) { AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(company.CPID); if (config == null) { ExceptionsServices.AddExceptionToDbAndTxt("H5CardRenewalError", "获取支付宝配置信息失败[0001]", "单位编号:" + company.CPID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝配置信息失败!" })); } if (!config.Status) { ExceptionsServices.AddExceptionToDbAndTxt("H5CardRenewalError", "该支付宝暂停使用", "单位编号:" + config.CompanyID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用支付宝支付!" })); } AliPayApiConfig requestConfig = AliPayApiConfigServices.QueryAliPayConfig(GetRequestCompanyId); if (requestConfig == null) { throw new MyException("获取请求单位微信配置失败"); } if (config.CompanyID != requestConfig.CompanyID) { ExceptionsServices.AddExceptionToDbAndTxt("H5CardRenewalError", "支付的支付宝配置和请求的支付配置不匹配,不能支付", string.Format("支付单位:{0},请求单位:{1}", config.CompanyID, requestConfig.CompanyID), LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付的支付宝配置和请求的支付配置不匹配,不能支付!" })); } model.PayeeUser = config.SystemName; model.PayeeAccount = config.PayeeAccount; model.PayeeChannel = PaymentChannel.AliPay; model.PaymentChannel = PaymentChannel.AliPay; model.CompanyID = config.CompanyID; } else { WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(company.CPID); if (config == null) { ExceptionsServices.AddExceptionToDbAndTxt("H5CardRenewalError", "获取微信配置信息失败", "单位编号:" + company.CPID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取微信配置信息失败!" })); } if (!config.Status) { ExceptionsServices.AddExceptionToDbAndTxt("H5CardRenewalError", "该车场暂停使用微信支付", "单位编号:" + company.CPID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用微信支付!" })); } WX_ApiConfig requestConfig = WXApiConfigServices.QueryWXApiConfig(GetRequestCompanyId); if (requestConfig == null) { throw new MyException("获取请求单位微信配置失败"); } if (config.CompanyID != requestConfig.CompanyID) { ExceptionsServices.AddExceptionToDbAndTxt("H5CardRenewalError", "微信支付配置和当前请求微信支付配置不匹配,不能支付", string.Format("支付单位:{0},请求单位:{1}", config.CompanyID, requestConfig.CompanyID), LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "微信支付配置和当前请求微信支付配置不匹配,不能支付!" })); } model.PayeeUser = config.SystemName; model.PayeeAccount = config.PartnerId; model.PayeeChannel = PaymentChannel.WeiXinPay; model.PaymentChannel = PaymentChannel.WeiXinPay; model.CompanyID = config.CompanyID; } model.OrderID = IdGenerator.Instance.GetId(); model.CardId = card.CardID; model.PKID = card.PKID; model.PKName = card.PKName; model.EntranceTime = card.EndDate; model.ExitTime = afterdate; model.MonthNum = month; model.Amount = (decimal)paymoney; model.Status = OnlineOrderStatus.WaitPay; model.OrderTime = DateTime.Now; model.AccountID = LoginAccountID; model.OrderType = OnlineOrderType.MonthCardRecharge; model.PlateNo = card.PlateNumber; bool result = OnlineOrderServices.Create(model); if (!result) { throw new MyException("续期失败[保存订单失败]"); } Response.Cookies.Add(new HttpCookie("SmartSystem_MonthCardPayment_Month", string.Format("{0},{1}", month, (int)paytype))); switch (model.PaymentChannel) { case PaymentChannel.WeiXinPay: { return(RedirectToAction("MonthCardPayment", "H5WeiXinPayment", new { orderId = model.OrderID })); } case PaymentChannel.AliPay: { return(RedirectToAction("AliPayRequest", "H5Order", new { orderId = model.OrderID, requestSource = 2 })); } default: throw new MyException("支付方式错误"); } } catch (MyException ex) { return(PageAlert("MonthCardRenewal", "H5CardRenewal", new { cardId = cardId, RemindUserContent = ex.Message })); } catch (Exception ex) { ExceptionsServices.AddExceptionToDbAndTxt("H5CardRenewalError", string.Format("获取续费信息失败,编号:" + cardId), ex, LogFrom.WeiXin); return(PageAlert("MonthCardRenewal", "CardRenewal", new { cardId = cardId, RemindUserContent = "提交支付失败" })); } }
public ActionResult SubmitParkingPaymentRequest(OnlineOrder model) { try { if (model.OrderSource == PayOrderSource.Platform) { //int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(model.PayDetailID); int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(model.PayDetailID, model.PKID, model.InOutID); if (interfaceOrderState != 1) { string msg = interfaceOrderState == 2 ? "重复支付" : "订单已失效"; string companyId = GetCompanyId(model.PKID, string.Empty, string.Empty); return(RedirectToAction("Index", "ErrorPrompt", new { message = msg, returnUrl = "/QRCode/Index?companyId=" + companyId + "" })); } } model.OrderID = IdGenerator.Instance.GetId(); model.Status = OnlineOrderStatus.WaitPay; model.OrderType = OnlineOrderType.ParkFee; model.Amount = model.Amount; BaseCompany company = CompanyServices.QueryByParkingId(model.PKID); if (company == null) { throw new MyException("获取单位信息失败"); } if (model.PaymentChannel == PaymentChannel.AliPay) { if (string.IsNullOrWhiteSpace(AliPayUserId)) { return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取用户信息失败,请重新扫码进入" })); } AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(company.CPID); if (config == null) { ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取支付宝配置信息失败[0001]", "单位编号:" + company.CPID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝配置信息失败!" })); } if (!config.Status) { ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该支付宝暂停使用", "单位编号:" + config.CompanyID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用支付宝支付!" })); } if (model.OrderSource == PayOrderSource.Platform && (CurrLoginAliPayApiConfig == null || CurrLoginAliPayApiConfig.CompanyID != config.CompanyID)) { string loginCompanyId = CurrLoginAliPayApiConfig != null ? CurrLoginAliPayApiConfig.CompanyID : string.Empty; ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "支付宝配置信息和当前支付宝配置信息不匹配,不能支付", string.Format("支付单位:{0},用户单位:{1}", config.CompanyID, loginCompanyId), LogFrom.WeiXin); if (CurrLoginAliPayApiConfig == null) { return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝授权信息失败,请重试!" })); } return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付宝配置信息和当前支付宝配置信息不匹配,不能支付!" })); } 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 = AliPayUserId; model.PayAccount = AliPayUserId; model.CompanyID = config.CompanyID; } else { if (string.IsNullOrWhiteSpace(WeiXinOpenId)) { return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取用户信息失败,请重新扫码进入" })); } WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(company.CPID); if (config == null) { ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取微信配置信息失败", "单位编号:" + company.CPID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取微信配置信息失败!" })); } if (!config.Status) { ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该车场暂停使用微信支付", "单位编号:" + company.CPID, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用微信支付!" })); } if (model.OrderSource == PayOrderSource.Platform && (CurrLoginWeiXinApiConfig == null || config.CompanyID != CurrLoginWeiXinApiConfig.CompanyID)) { string loginCompanyId = CurrLoginWeiXinApiConfig != null ? CurrLoginWeiXinApiConfig.CompanyID : string.Empty; ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "车场所属公众号和当前公众号不匹配,不能支付", string.Format("支付单位:{0},微信用户单位:{1}", config.CompanyID, loginCompanyId), LogFrom.WeiXin); if (CurrLoginWeiXinApiConfig == null) { return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取微信授权信息失败,请重试!" })); } return(RedirectToAction("Index", "ErrorPrompt", new { message = "车场所属公众号和当前公众号不匹配,不能支付!" })); } model.PayeeUser = config.SystemName; model.PayeeAccount = config.PartnerId; model.PayAccount = WeiXinOpenId; model.Payer = model.PayAccount; model.AccountID = model.AccountID; model.CardId = model.AccountID; model.PayeeChannel = PaymentChannel.WeiXinPay; model.PaymentChannel = PaymentChannel.WeiXinPay; model.CompanyID = config.CompanyID; } bool result = OnlineOrderServices.Create(model); if (!result) { throw new MyException("生成待缴费订单失败"); } switch (model.PaymentChannel) { case PaymentChannel.WeiXinPay: { return(RedirectToAction("ParkCarPayment", "WeiXinPayment", new { orderId = model.OrderID, source = 1 })); } case PaymentChannel.AliPay: { return(RedirectToAction("ParkCarPayment", "AliPayment", new { orderId = model.OrderID, source = 1 })); } default: throw new MyException("支付方式错误"); } } catch (MyException ex) { return(RedirectToAction("ComputeParkingFee", "QRCodeParkPayment", new { licensePlate = model.PlateNo, RemindUserContent = ex.Message })); } catch (Exception ex) { ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "保存临停缴费订单失败", ex, LogFrom.WeiXin); return(RedirectToAction("ComputeParkingFee", "QRCodeParkPayment", new { licensePlate = model.PlateNo, RemindUserContent = "提交支付失败" })); } }