using DFS.Core.Mvc; using DFS.Infrastructure.Redis.Extension; using FreeSql; using Fuel.Application; using Fuel.Application.Repositories; using Fuel.Application.Service; using Fuel.Infrastructure; using Fuel.Payment.Service.AliPaymentProcessor.Alipay; using Fuel.Payment.Service.AllInPayProcessor.AllInPay; using Fuel.Payment.Service.Factory; using Fuel.Payment.Service.Pay; using Fuel.Payment.Service.UnionPayProcessor; using Fuel.PaymentServer.MicServer; using Fuel.Infrastructure.Extension; using CSRedis; using Microsoft.Extensions.Logging; using Fuel.Core; using Microsoft.AspNetCore.Authorization; using Fuel.Application.Authorization; var builder = WebApplication.CreateBuilder(args); builder.Services.AddScoped(); AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ALI_SCAN", new AlipayPaymentProcessor()); //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "WX_SCAN", new WechatPaymentProcessor()); AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ALL_IN_SCAN", new AllInPayProcessor()); //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ALL_IN_SCAN_V2", new AllInPayProcessorV2()); //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "WX_ORDER_SCAN", new WechatPaymentProcessor()); AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ALI_ORDER_SCAN", new AlipayPaymentProcessor()); //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "WECHAT_MINIPROGRAM_PAY", new WechatPaymentProcessor()); //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ICBC_SCAN", new IcbcPayProcessor()); //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ICBC_ORDER_SCAN", new IcbcPayProcessor()); //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "GRG_SCAN", new GrgPayProcessor()); AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "UNION_MINI", new MiniUnionPayProcessor()); AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "UNION_SCAN", new UnionPayProcessor()); // Add services to the container. // 添加FreeSQL配置 builder.Services.AddFreeSql(builder.Configuration); //初始化DFS Server builder.Services.AddMicService(builder.Environment); builder.Services.AddHttpContextAccessor(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); Fuel.Infrastructure.Extension.RedisOptions redisOptions = builder.Configuration.GetSection("Redis").Get(); builder.Services.UseRedisClient(redisOptions); // 动态添加基于权限的策略 void AddPermissionPolicies(AuthorizationOptions options) { // 获取所有可能的权限字符串(这里只是一个例子,你应该根据实际情况实现) var permissions = Authorization.GetPermissions(); foreach (var permission in permissions) { options.AddPolicy($"Permission_{permission}", policy => policy.Requirements.Add(new PermissionRequirement(permission))); } } builder.Services.AddAuthorization(options => { AddPermissionPolicies(options); }); var app = builder.Build(); app.UseRouting(); var loggerFactory = LoggerFactory.Create(builder => { builder.AddConsole(); }); var accessKeySecret = "sfsdfasfsdafasdfdsa";//密钥 var logger = loggerFactory.CreateLogger(); var signatureValidator = new SignatureValidator(accessKeySecret, logger); app.UseMiddleware(signatureValidator);//签名验证 // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseDFSServer(); app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); app.Run();