Beispiel #1
0
        /// <summary>
        /// 验证订单是否支付
        /// </summary>
        /// <param name="pRequest"></param>
        /// <returns></returns>
        internal static bool IsOrderPaid(TradeRequest pRequest)
        {
            var para   = pRequest.GetParameter <QueryOrderByAppInfoParameters>();
            var bll    = new AppOrderBLL(pRequest.GetUserInfo());
            var entity = bll.GetByAppInfo(pRequest.AppID.Value, para.AppOrderID, pRequest.ClientID);

            return(entity.Status == 2);
        }
Beispiel #2
0
        /// <summary>
        /// 查询订单信息
        /// </summary>
        /// <param name="pRequest"></param>
        /// <returns></returns>
        public static object QueryOrder(TradeRequest pRequest)
        {
            QueryOrderResponse response = new QueryOrderResponse();
            var         user            = pRequest.GetUserInfo();
            AppOrderBLL bll             = new AppOrderBLL(user);
            var         para            = pRequest.GetParameter <QueryOrderParameters>();
            var         entity          = bll.GetByID(para.OrderID);

            if (entity != null)
            {
                response.Status = entity.Status;
            }
            else
            {
                response.Message = "无此订单信息";
            }
            return(response);
        }
Beispiel #3
0
        public bool IsValid(string pIpAddress, TradeRequest pRequest)
        {
            Loggers.Debug(new DebugLogInfo()
            {
                Message = "请求IP:" + pIpAddress
            });
            if (pIpAddress == "127.0.0.1")
            {
                return(true);
            }
            if (pIpAddress == "::1")
            {
                return(true);
            }
            AppWhiteListBLL bll = new AppWhiteListBLL(pRequest.GetUserInfo());

            return(bll.IsValidApp(pIpAddress, pRequest.AppID.ToString(), pRequest.ClientID));
        }
Beispiel #4
0
        /// <summary>
        /// 使用汇付储值卡支付订单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        internal static PrePaidCardPayRD PrePaidCardPay(TradeRequest request)
        {
            PrePaidCardPayRD rd = new PrePaidCardPayRD();
            var rp       = request.GetParameter <PrePaidCardPayRP>();
            var userInfo = request.GetUserInfo();

            if (rp == null || string.IsNullOrEmpty(rp.OrderId) ||
                string.IsNullOrEmpty(rp.CardNo) || string.IsNullOrEmpty(rp.Password))
            {
                rd.errcode = 40000;
                rd.errmsg  = "参数错误";
                return(rd);
            }

            try
            {
                var appBll   = new AppOrderBLL(userInfo);
                var appOrder = appBll.GetAppOrderByAppOrderId(rp.OrderId);

                if (appOrder == null)
                {
                    rd.errcode = 40001;
                    rd.errmsg  = "未找到支付订单,请重试!";
                    return(rd);
                }

                if (CacheOrder.Contains(rp.OrderId))
                {
                    rd.errcode = 40003;
                    rd.errmsg  = "订单支付中,请稍后重试";
                    return(rd);
                }
                CacheOrder.Add(rp.OrderId); // 限制重复提交支付,只针对单服务器程序,多服务请走第三方缓存

                if (appOrder.Status == 2)
                {
                    rd.errcode = 0;
                    rd.errmsg  = "该订单已支付";
                    return(rd);
                }
                string msg    = string.Empty;
                var    result = Consumption(rp, appOrder, out msg);

                if (result.rspCd == "0000")
                {
                    rd.errcode = 200;
                    rd.errmsg  = "success";

                    AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo());
                    if (!(appOrder.IsNotified ?? false))
                    {
                        Task.Factory.StartNew(() =>
                        {//起一个新线程通知业务系统处理订单
                            try
                            {
                                string errmsg;
                                if (NotifyHandler.Notify(appOrder, out errmsg))
                                {
                                    appOrder.IsNotified = true;
                                }
                                else
                                {
                                    appOrder.NextNotifyTime = DateTime.Now.AddMinutes(1);
                                }
                                //通知完成,通知次数+1

                                appOrder.NotifyCount = (appOrder.NotifyCount ?? 0) + 1;
                                bll.Update(appOrder);
                            }
                            catch (Exception ex)
                            {
                                Loggers.Exception(new ExceptionLogInfo(ex));
                            }
                        });
                    }
                }
                else
                {
                    rd.errcode = 40002;
                    rd.errmsg  = result.rspDesc;
                }
            }
            catch (Exception ex)
            {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = ex.Message
                });
            }
            finally
            {
                CacheOrder.Remove(rp.OrderId);
            }
            return(rd);
        }
Beispiel #5
0
        /// <summary>
        /// 创建交易中心支付订单AppOrder
        /// </summary>
        /// <param name="pRequest"></param>
        /// <returns></returns>
        public static CreateOrderResponse CreateOrder(TradeRequest pRequest)
        {
            var userInfo = pRequest.GetUserInfo();
            CreateOrderResponse response = new CreateOrderResponse();

            response.ResultCode = 0;
            CreateOrderParameters para = pRequest.GetParameter <CreateOrderParameters>();

            Loggers.Debug(new DebugLogInfo()
            {
                Message = "业务参数:" + para.ToJSON()
            });
            if (para == null)
            {
                throw new Exception("Parameters参数不正确");
            }
            AppOrderBLL    bll = new AppOrderBLL(userInfo);
            AppOrderEntity entity;

            #region 支付等待5秒后可再次支付
            var appOrderEntity = bll.QueryByEntity(new AppOrderEntity()
            {
                ClientIP = pRequest.ClientID, AppOrderID = para.AppOrderID
            }, null).FirstOrDefault();
            if (appOrderEntity != null)
            {
                DateTime dtNow = DateTime.Now;
                TimeSpan ts    = dtNow - appOrderEntity.CreateTime.Value;
                if (ts.TotalSeconds < 5)
                {
                    throw new Exception("支付已启动,请稍后再试");
                }
            }
            #endregion

            #region  在支付中心创建订单
            var tran = bll.CreateTran();
            using (tran.Connection)
            {
                try
                {
                    #region  除已存在的订单
                    bll.DeleteByAppInfo(pRequest.ClientID, para.AppOrderID, pRequest.AppID.Value, tran);
                    #endregion

                    #region 创建订单
                    entity = new AppOrderEntity()
                    {
                        Status         = 0,
                        MobileNO       = para.MobileNO,
                        AppClientID    = pRequest.ClientID,
                        AppUserID      = pRequest.UserID,
                        AppID          = pRequest.AppID,
                        AppOrderAmount = Convert.ToInt32(para.AppOrderAmount),
                        AppOrderDesc   = para.AppOrderDesc,
                        AppOrderID     = para.AppOrderID,
                        AppOrderTime   = para.GetDateTime(),
                        Currency       = 1,
                        CreateBy       = pRequest.UserID,
                        PayChannelID   = para.PayChannelID,
                        LastUpdateBy   = pRequest.UserID,
                        OpenId         = para.OpenId,
                        ClientIP       = para.ClientIP
                    };
                    bll.Create(entity, tran);//并且生成了一个自动增长的订单标识orderid
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "创建支付中心订单并保存数据库:" + entity.ToJSON()
                    });
                    #endregion

                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    throw;
                }
            }
            #endregion

            #region 获取Channel
            PayChannelBLL channelBll = new PayChannelBLL(userInfo);
            var           channel    = channelBll.GetByID(para.PayChannelID);//PayChannelID是不同商户的支付方式的标识
            if (channel == null)
            {
                throw new Exception("无此ChannelID的Channel信息");
            }
            #endregion

            #region 测试Channel订单价格设置为1分钱***
            entity.AppOrderAmount = channel.IsTest.Value ? 1 : entity.AppOrderAmount;
            #endregion

            string url = string.Empty;
            if (para.AppOrderDesc != "ScanWxPayOrder")
            {
                if (para.PaymentMode == 0)
                {
                    channel.PayType = 9; //新版支付宝扫码支付
                }
                url = CreatePayRecord(response, para, bll, entity, channel);
            }

            response.PayUrl  = url;
            response.OrderID = entity.OrderID;
            return(response);
        }