コード例 #1
0
        private static EntrustPaymentApi CreateEntrustPaymentApi()
        {
            var factory = XDI.Resolve <IHttpClientFactory>();
            var client  = factory.CreateClient("EntrustPaymentApiHttpClient");

            return(new EntrustPaymentApi(client, GlobalConfig.X99bill_EntrustPay_Hehua_MerchantId, GlobalConfig.X99bill_EntrustPay_Hehua_TerminalId));
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: SZarrow/CPI
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(LogTraceFilter));
            }).AddJsonOptions(options =>
            {
                //忽略循环引用
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                //不使用驼峰样式的key
                options.SerializerSettings.ContractResolver = new DefaultContractResolver();
                //设置时间格式
                options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
            }).AddXDI().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);


            //关闭mvc自带模型验证
            services.Configure <ApiBehaviorOptions>(options =>
            {
                options.SuppressModelStateInvalidFilter = true;
            });

            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(GlobalConfig.CommonRemoteCertificateValidationCallback);
            InitAgreePaymentHttpClient(services);
            InitEntrustPaymentHttpClient(services);
            InitCommonHttpClient(services);

            XDI.AddServices(services);
            XDI.Scope(typeof(CPIDbContext));
        }
コード例 #3
0
ファイル: TransactionScope.cs プロジェクト: SZarrow/CPI
        /// <summary>
        /// 初始化TransactionScope类的实例
        /// </summary>
        /// <param name="isolationLevel">事务隔离级别</param>
        public TransactionScope(IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
        {
            var db = XDI.Resolve <CPIDbContext>();

            if (db == null)
            {
                _logger.Error(TraceType.DAL.ToString(), CallResultStatus.ERROR.ToString(), $"{nameof(XDI)}.{nameof(XDI.Resolve)}<{nameof(CPIDbContext)}>", "事务TransactionScope初始化失败", "解析CPIDbContext类型的实例失败");
                throw new ArgumentNullException(nameof(db));
            }

            _transaction = db.Database.BeginTransaction(isolationLevel);
            _logger.Trace(TraceType.DAL.ToString(), CallResultStatus.OK.ToString(), SERVICE, $"tx_{_transaction.TransactionId.ToString()}", LogPhase.BEGIN, "开始数据库事务");
        }
コード例 #4
0
ファイル: Startup.cs プロジェクト: SZarrow/CPI
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseDeveloperExceptionPage();
            app.UseStaticFiles();
            app.UseMvc();

            GlobalConfig.Environment = Configuration["Environment"];
            ErrorCodeDescriptor.AddErrorCodeTypes(typeof(ErrorCode));
            XDI.Run();
        }
コード例 #5
0
        static void Main(String[] args)
        {
            XDI.Run();

            GlobalConfig.Environment = ConfigurationManager.AppSettings["Environment"];

            String jobsConfigFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CPI.ScheduleJobs.Development.config");

            if (GlobalConfig.Environment == EnvironmentType.Production.ToString())
            {
                jobsConfigFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CPI.ScheduleJobs.config");
            }

            var service = new QuartzService(jobsConfigFilePath);

            service.Start(null);
            Console.WriteLine("CPI定时调度服务已启动...");
            Console.ReadKey();
        }
コード例 #6
0
 public Bill99AgreePayInvocation(GatewayCommonRequest request)
 {
     _request         = request;
     _agreePayService = XDI.Resolve <IAgreementPaymentService>();
     _bindInfoService = XDI.Resolve <IAgreePayBankCardBindInfoService>();
 }
コード例 #7
0
 public Bill99AllotAmountInvocation(GatewayCommonRequest request)
 {
     _request = request;
     _service = XDI.Resolve <IAllotAmountService>();
 }
コード例 #8
0
 public Bill99WithdrawInvocation(GatewayCommonRequest request)
 {
     _request                    = request;
     _withdrawService            = XDI.Resolve <IWithdrawService>();
     _allotAmountWithdrawService = XDI.Resolve <IAllotAmountWithdrawService>();
 }
コード例 #9
0
ファイル: ProxyActivator.cs プロジェクト: SZarrow/CPI
        public static IInvocation GetInvocation(GatewayCommonRequest request)
        {
            if (request == null || !request.IsValid)
            {
                return(null);
            }

            String service = $"{typeof(ProxyActivator).FullName}.GetInvocation()";
            String tag     = $"{request.Method}.{request.Version}";

            if (request.Method.IndexOf("cpi.fundout.single.99bill.") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99SinglePayInvocation");
                return(new Bill99SinglePayInvocation(request));
            }

            if (request.Method.IndexOf("cpi.fundout.single.95epay.") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 EPay95SinglePayInvocation");
                return(new EPay95SinglePayInvocation(request));
            }

            if (request.Method.IndexOf("cpi.fundout.single.yeepay.") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 YeePaySinglePayInvocation");
                return(new YeePaySinglePayInvocation(request));
            }

            if (request.Method.IndexOf("cpi.settle.personal.") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99PersonalInvocation");
                return(new Bill99PersonalInvocation(request));
            }

            if (request.Method.IndexOf("cpi.settle.allot.") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99AllotAmountInvocation");
                return(new Bill99AllotAmountInvocation(request));
            }

            if (request.Method.IndexOf("cpi.settle.allotamount.withdraw.") == 0 ||
                request.Method.IndexOf("cpi.settle.withdraw.") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99WithdrawInvocation");
                return(new Bill99WithdrawInvocation(request));
            }

            if (request.Method.IndexOf("cpi.settle.account.") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99AccountInvocation");
                return(new Bill99AccountInvocation(request));
            }

            if (request.Method.IndexOf("cpi.agreepay.apply.99bill") == 0 ||
                request.Method.IndexOf("cpi.agreepay.bindcard.99bill") == 0 ||
                request.Method.IndexOf("cpi.agreepay.pay.99bill") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99AgreePayInvocation");
                return(new Bill99AgreePayInvocation(request));
            }

            if (request.Method.IndexOf("cpi.agreepay.apply.yeepay") == 0 ||
                request.Method.IndexOf("cpi.agreepay.bindcard.yeepay") == 0 ||
                request.Method.IndexOf("cpi.agreepay.pay.yeepay") == 0 ||
                request.Method.IndexOf("cpi.agreepay.refund.yeepay") == 0 ||
                request.Method.IndexOf("cpi.agreepay.payresult.pull.yeepay") == 0 ||
                request.Method.IndexOf("cpi.agreepay.refundresult.pull.yeepay") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99AgreePayInvocation");
                return(new YeePayAgreePayInvocation(request));
            }

            if (request.Method.IndexOf("cpi.entrust.pay.99bill") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99EntrustPayInvocation");
                return(new Bill99EntrustPayInvocation(request));
            }

            if (request.Method.IndexOf("cpi.unified.querystatus") == 0 ||
                request.Method.IndexOf("cpi.unified.querydetail") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 AgreePayInvocation");
                return(new AgreePayInvocation(request));
            }

            if (request.Method.IndexOf("cpi.unified.payresult.pull") == 0)
            {
                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99AgreePayInvocation");
                return(new Bill99AgreePayInvocation(request));
            }

            if (request.Method.IndexOf("cpi.unified.pay") == 0)
            {
                // 根据AppId从数据库中查出默认通道编码,如果没有指定则默认使用快钱
                var appChannelRouteService = XDI.Resolve <IAppChannelRouteService>();
                if (appChannelRouteService == null)
                {
                    _logger.Error(TraceType.ROUTE.ToString(), CallResultStatus.ERROR.ToString(), service, tag, "未能初始化IAppChannelRouteService的实例", null, request);
                    return(null);
                }

                var channelRouteInfo = appChannelRouteService.GetPayChannel(request.AppId);
                request.Method += $".{(channelRouteInfo != null ? channelRouteInfo.ChannelCode : GlobalConfig.DefaultPayChannelCode)}";

                // 确定通道之后取出所有通道的费率,
                // 然后根据当前支付金额算出每个通道的费用,
                // 然后得到费用最小的一个通道,
                // 然后对于这个费用最小的通道,通道费用大于阈值的用代扣,否则用协议支付。

                var paymentRequest = JsonUtil.DeserializeObject <CommonPayRequest>(request.BizContent);
                if (!paymentRequest.Success)
                {
                    _logger.Error(TraceType.ROUTE.ToString(), CallResultStatus.ERROR.ToString(), service, tag, "解析支付金额失败", paymentRequest.FirstException, request);
                    return(null);
                }

                #region 关闭协议支付
                //var payChannelService = XDI.Resolve<IPayChannelService>();
                //var channels = payChannelService.GetAllChannels();
                //if (channels != null && channels.Count() > 0)
                //{
                //    var cheapestChannel = (from ch in channels
                //                           let cost = paymentRequest.Value.GetPayAmount() * ch.PayRate
                //                           orderby cost
                //                           select new
                //                           {
                //                               ch.ChannelCode,
                //                               Cost = cost
                //                           }).FirstOrDefault();

                //    if (cheapestChannel.Cost > GlobalConfig.PayChannelFeeThreshold)
                //    {
                //        _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99EntrustPayInvocation");
                //        return CreateEntrustPayInvocation(cheapestChannel.ChannelCode, request);
                //    }

                //    return CreateAgreePayInvocation(cheapestChannel.ChannelCode, request);
                //}
                #endregion

                _logger.Trace(TraceType.ROUTE.ToString(), CallResultStatus.OK.ToString(), service, tag, LogPhase.ACTION, "创建 Bill99AgreePayInvocation");
                return(CreateEntrustPayInvocation(GlobalConfig.X99BILL_PAYCHANNEL_CODE, request));
            }

            return(null);
        }
コード例 #10
0
        private static HttpClient CreateHttpClient()
        {
            var factory = XDI.Resolve <IHttpClientFactory>();

            return(factory.CreateClient());
        }
コード例 #11
0
 public EPay95SinglePayInvocation(GatewayCommonRequest request)
 {
     _request = request;
     _service = XDI.Resolve <IEPay95SinglePaymentService>();
 }
コード例 #12
0
 public Bill99PersonalInvocation(GatewayCommonRequest request)
 {
     _request   = request;
     _service   = XDI.Resolve <IPersonalService>();
     _serviceV1 = XDI.Resolve <IPersonalServiceV1>();
 }
コード例 #13
0
 protected EFRepository() : this(XDI.Resolve <CPIDbContext>())
 {
 }