private OnlineOrder CheckOrder(decimal orderId) { OnlineOrder order = OnlineOrderServices.QueryByOrderId(orderId); if (order == null) { throw new MyException("获取支付信息失败,请重新支付"); } if (order.PaymentChannel != PaymentChannel.WeiXinPay) { throw new MyException("支付方法不正确"); } if (order.Status != OnlineOrderStatus.WaitPay) { throw new MyException("订单不是可支付状态"); } return(order); }
public ActionResult AliPayRequest(decimal orderId, int requestSource) { try { OnlineOrder order = OnlineOrderServices.QueryByOrderId(orderId); if (order == null) { throw new MyException("获取订单信息失败"); } if (order.Status != Common.Entities.Enum.OnlineOrderStatus.WaitPay) { throw new MyException("订单不是可支付状态"); } if (string.IsNullOrWhiteSpace(GetAliPayUserId)) { string id = string.Format("H5Order_AliPayRequest_orderId={0}^companyId={1}^requestSource={2}", order.OrderID, order.CompanyID, requestSource); return(RedirectToAction("Index", "AliPayAuthorize", new { id = id })); } bool result = OnlineOrderServices.UpdatePayAccount(orderId, GetAliPayUserId); if (!result) { throw new MyException("更改支付账号失败"); } if (requestSource == 1) { return(RedirectToAction("ParkCarPayment", "H5AliPayment", new { orderId = orderId })); } if (requestSource == 2) { return(RedirectToAction("MonthCardPayment", "H5AliPayment", new { orderId = orderId })); } throw new MyException("未知请求来源"); } catch (MyException ex) { return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message })); } catch (Exception ex) { ExceptionsServices.AddExceptionToDbAndTxt("H5OrderError", string.Format("更改支付人信息失败,订单编号:{0},单位编号:{1}", orderId, GetRequestCompanyId), ex, LogFrom.WeiXin); return(RedirectToAction("Index", "ErrorPrompt", new { message = "更改支付账号失败!" })); } }
/// <summary> /// 取消订单 /// </summary> /// <param name="orderId"></param> /// <returns></returns> public ActionResult CancelOrder(decimal orderId, int source = 0) { string actionName = "Index"; string controllerName = "ParkingPayment"; try { OnlineOrder order = OnlineOrderServices.QueryByOrderId(orderId); if (order != null) { OnlineOrderServices.CancelOrder(orderId); if (order.OrderType == OnlineOrderType.MonthCardRecharge) { controllerName = "CardRenewal"; actionName = "Index"; } if (order.OrderType == OnlineOrderType.ParkFee) { if (source == 0) { controllerName = "ParkingPayment"; actionName = "Index"; } else { controllerName = "QRCodeParkPayment"; actionName = "Index"; } } if (order.OrderType == OnlineOrderType.PkBitBooking) { controllerName = "ParkBitBooking"; actionName = "Index"; } } } catch (Exception ex) { ExceptionsServices.AddExceptionToDbAndTxt("AliPay_Error", string.Format("取消待支付订单失败 orderId:{0};openId:{1}", orderId, WeiXinOpenId), ex, LogFrom.WeiXin); } return(PageAlert(actionName, controllerName, new { RemindUserContent = "取消成功" })); }
public ActionResult CheckOrderState(decimal orderId) { try { OnlineOrder order = OnlineOrderServices.QueryByOrderId(orderId); //int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(order.PayDetailID); int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(order.PayDetailID, order.PKID, order.InOutID); if (interfaceOrderState != 1) { string msg = interfaceOrderState == 2 ? "重复支付" : "订单已失效"; return(Json(MyResult.Error(msg))); } return(Json(MyResult.Success())); } catch (Exception ex) { ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPayment_Error", string.Format("检查订单是否有效失败 orderId:{0};openId:{1}", orderId, WeiXinOpenId), ex, LogFrom.WeiXin); return(Json(MyResult.Error("检查订单是否有效失败"))); } }
public ActionResult PaymentSuccess(decimal orderId) { OnlineOrder order = OnlineOrderServices.QueryByOrderId(orderId); return(View(order)); }
public void Index() { //TxtLogServices.WriteTxtLogEx("AliPayNotify", Request.Url.AbsoluteUri + ":" + Request.Form.ToString()); try { string notify_time = Request.Params["notify_time"]; string notify_type = Request.Params["notify_type"]; string notify_id = Request.Params["notify_id"]; string app_id = Request.Params["app_id"]; string charset = Request.Params["charset"]; string version = Request.Params["version"]; string sign_type = Request.Params["sign_type"]; string sign = Request.Params["sign"]; string trade_no = Request.Params["trade_no"]; string out_trade_no = Request.Params["out_trade_no"]; string out_biz_no = Request.Params["out_biz_no"]; string buyer_id = Request.Params["buyer_id"]; string buyer_logon_id = Request.Params["buyer_logon_id"]; string seller_id = Request.Params["seller_id"]; string seller_email = Request.Params["seller_email"]; string trade_status = Request.Params["trade_status"]; string total_amount = Request.Params["total_amount"]; string receipt_amount = Request.Params["receipt_amount"]; string invoice_amount = Request.Params["invoice_amount"]; string buyer_pay_amount = Request.Params["buyer_pay_amount"]; string point_amount = Request.Params["point_amount"]; string refund_fee = Request.Params["refund_fee"]; string subject = Request.Params["subject"]; string gmt_create = Request.Params["gmt_create"]; string gmt_payment = Request.Params["gmt_payment"]; string gmt_refund = Request.Params["gmt_refund"]; string gmt_close = Request.Params["gmt_close"]; string fund_bill_list = Request.Params["fund_bill_list"]; string passback_params = Request.Params["passback_params"]; string voucher_detail_list = Request.Params["voucher_detail_list"]; OnlineOrder order = OnlineOrderServices.QueryByOrderId(decimal.Parse(out_trade_no)); if (order == null) { throw new Exception("获取订单失败"); } if (!CheckNotifySign(order.CompanyID)) { throw new Exception("验证签名失败"); } TxtLogServices.WriteTxtLogEx("AliPayNotify", "验签成功:out_trade_no:" + out_trade_no); DateTime payTime = DateTime.Now; DateTime.TryParse(gmt_payment, out payTime); WeiXinInerface.ParkingFeeService.DeleteParkingFee(order.PlateNo + order.PKID); bool result = OnlineOrderServices.PaySuccess(decimal.Parse(out_trade_no), trade_no, payTime, buyer_id); if (!result) { throw new Exception("修改订单状态未已支付失败"); } TxtLogServices.WriteTxtLogEx("AliPayNotify", string.Format("AliPayShowResult:{0}支付完成", trade_no)); Response.Write("success"); Response.End(); } catch (Exception ex) { ExceptionsServices.AddExceptionToDbAndTxt("AliPayNotify", "支付通知出错", ex, LogFrom.AliPay); Response.Write("fail"); Response.End(); } }
/// <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(); }