Ejemplo n.º 1
0
        public static bool SyncPaymentResult(decimal orderId)
        {
            IOnlineOrder factory = OnlineOrderFactory.GetFactory();
            OnlineOrder  order   = factory.QueryByOrderId(orderId);

            if (order.PaymentChannel != PaymentChannel.WeiXinPay && order.PaymentChannel == PaymentChannel.AliPay)
            {
                throw new MyException("目前只能同步微信或支付宝的支付结果");
            }

            if (order.Status != OnlineOrderStatus.WaitPay && order.Status != OnlineOrderStatus.Paying)
            {
                throw new MyException("只有待支付或支付中的订单才能同步");
            }

            switch (order.PaymentChannel)
            {
            case PaymentChannel.WeiXinPay: {
                UnifiedOrderQueryMessage result = PaymentServices.UnifiedOrderQuery(order.CompanyID, order.SerialNumber, order.OrderID.ToString());
                if (result.Success)
                {
                    DateTime payTime = GetConversionWeiXinPayTime(result.Tiem_End);
                    return(PaySuccess(orderId, result.TransactionId, payTime));
                }

                if (result.Return_Code.ToUpper() != "SUCCESS")
                {
                    throw new MyException(string.Format("同步失败:{0}", result.Return_Msg));
                }

                if (result.Result_Code.ToUpper() != "SUCCESS")
                {
                    throw new MyException(string.Format("同步失败:【{0}】{1}", result.Err_Code, result.Err_Code_Des));
                }

                if (result.Trade_State.ToUpper() != "SUCCESS")
                {
                    throw new MyException(string.Format("同步失败:{0}", GetWeiXinPayOrderErrorStateDes(result.Trade_State)));
                }
                break;
            }

            case PaymentChannel.AliPay: {
                DateTime payTime = DateTime.Now;
                bool     result  = AliPayApiServices.QueryPayResult(order.CompanyID, order.OrderID.ToString(), order.PrepayId, out payTime);
                if (result)
                {
                    return(PaySuccess(orderId, order.PrepayId, payTime));
                }
                else
                {
                    throw new MyException("该订单未支付");
                }
            }

            default: throw new MyException("支付通道不正确");
            }

            return(false);
        }
Ejemplo n.º 2
0
        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 = "获取支付宝授权失败" }));
            }
        }
Ejemplo n.º 3
0
 private bool CheckNotifySign(string companyId)
 {
     try
     {
         IDictionary <string, string> paramsMap = GetRequestPost();
         return(AliPayApiServices.RSACheckV1(companyId, paramsMap));
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("AliPayNotify", "验签报错:" + ex.StackTrace);
         return(false);
     }
 }
Ejemplo n.º 4
0
        private string MakeAlipayTradeOrder(OnlineOrder order)
        {
            string parkid = string.Empty;
            AlipayTradeOrderModel model = new AlipayTradeOrderModel();

            model.out_trade_no          = order.OrderID.ToString();
            model.total_amount          = order.Amount.ToString("F2");
            model.discountable_amount   = "";
            model.undiscountable_amount = "";
            model.seller_id             = order.PayeeAccount;
            model.buyer_logon_id        = "";
            model.subject  = order.PKName + "," + order.PlateNo + "," + order.EntranceTime.ToString("yyyy-MM-dd HH:mm:ss");
            model.buyer_id = order.PayAccount;
            model.store_id = parkid;
            model.body     = string.Format("临停缴费-{0}-{1}", order.PKName, order.PlateNo);
            TxtLogServices.WriteTxtLogEx("AliPayApiServices", JsonHelper.GetJsonString(model));
            string tradeNo = AliPayApiServices.MakeAliPayOrder(order.CompanyID, model);

            if (string.IsNullOrWhiteSpace(tradeNo))
            {
                throw new MyException("创建交易订单失败");
            }
            return(tradeNo);
        }
Ejemplo n.º 5
0
        private static bool Refund(OnlineOrder model, string certpath)
        {
            IOnlineOrder factory       = OnlineOrderFactory.GetFactory();
            bool         refundResult  = false;
            string       refundOrderId = IdGenerator.Instance.GetId().ToString();

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    refundResult = factory.RefundSuccess(model.OrderID, refundOrderId, dbOperator);
                    if (!refundResult)
                    {
                        throw new MyException("更改订单为退款成功时失败");
                    }
                    switch (model.PaymentChannel)
                    {
                    case PaymentChannel.WeiXinPay: {
                        string refundAmount = ((int)(model.Amount * 100)).ToString();
                        refundResult = PaymentServices.Refund(model.CompanyID, model.SerialNumber, model.OrderID.ToString(), refundAmount, refundAmount, refundOrderId, certpath);
                        TxtLogServices.WriteTxtLogEx("OnlineOrderServices", string.Format("方法名:{0},操作类型:{1},订单编号:{2},备注:{3} {4}", "Refund", "订单退款处理", model.OrderID, model.SerialNumber.ToString(), (model.Amount / 100).ToString("F2"), refundOrderId));
                        if (!refundResult)
                        {
                            throw new MyException("微信退款失败");
                        }
                        break;
                    }

                    case PaymentChannel.AliPay:
                    {
                        refundResult = AliPayApiServices.RefundRequest(model.CompanyID, model.OrderID.ToString(), model.SerialNumber.ToString(), model.Amount.ToString("F2"), "车场网络异常", refundOrderId);
                        TxtLogServices.WriteTxtLogEx("OnlineOrderServices", string.Format("方法名:{0},操作类型:{1},订单编号:{2},备注:{3} {4}", "Refund", "订单退款处理", model.OrderID, model.SerialNumber.ToString(), (model.Amount / 100).ToString("F2"), refundOrderId));
                        if (!refundResult)
                        {
                            throw new MyException("支付宝退款失败");
                        }
                        break;
                    }

                    default: throw new MyException("退款渠道不正确");
                    }
                    dbOperator.CommitTransaction();
                    TxtLogServices.WriteTxtLogEx("OnlineOrderServices", "方法名:{0},操作类型:{1},订单编号:{2},备注:{3}", "Refund", "订单退款处理", model.OrderID, "退款成功");
                }
                catch (Exception ex)
                {
                    refundResult = false;
                    dbOperator.RollbackTransaction();
                    ExceptionsServices.AddExceptionToDbAndTxt("OnlineOrderServices", string.Format("订单退款失败,订单编号{0},描述:{1}", model.OrderID, ex.Message), ex, LogFrom.WeiXin);
                }
                if (!refundResult)
                {
                    factory.RefundFail(model.OrderID);
                }
                if (model.PaymentChannel == PaymentChannel.WeiXinPay)
                {
                    if (!refundResult)
                    {
                        switch (model.OrderType)
                        {
                        case OnlineOrderType.PkBitBooking: {
                            TemplateMessageServices.SendBookingBitNoRefundFail(model.CompanyID, model.OrderID.ToString(), "车场网络异常", model.Amount, model.PayAccount);
                            break;
                        }

                        case OnlineOrderType.SellerRecharge: {
                            TemplateMessageServices.SendSellerRechargeRefundFail(model.CompanyID, model.OrderID.ToString(), "车场网络异常", model.Amount, model.PayAccount);
                            break;
                        }

                        default: {
                            TemplateMessageServices.SendParkingRefundFail(model.CompanyID, model.OrderID.ToString(), "车场网络异常", model.Amount, model.PayAccount);
                            break;
                        }
                        }
                    }
                    else
                    {
                        string message = string.IsNullOrWhiteSpace(model.Remark) ? "车场网络异常" : model.Remark;
                        switch (model.OrderType)
                        {
                        case OnlineOrderType.PkBitBooking:
                        {
                            TemplateMessageServices.SendBookingBitNoRefundSuccess(model.CompanyID, model.OrderID.ToString(), message, model.Amount, model.PayAccount);
                            break;
                        }

                        case OnlineOrderType.SellerRecharge:
                        {
                            TemplateMessageServices.SendSellerRechargeRefundSuccess(model.CompanyID, model.OrderID.ToString(), message, model.Amount, model.PayAccount);
                            break;
                        }

                        default:
                        {
                            TemplateMessageServices.SendParkingRefundSuccess(model.CompanyID, model.OrderID.ToString(), message, model.Amount, model.PayAccount);
                            break;
                        }
                        }
                    }
                }
            }
            return(refundResult);
        }