Program.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using DFS.Core.Mvc;
  2. using DFS.Infrastructure.Redis.Extension;
  3. using FreeSql;
  4. using Fuel.Application;
  5. using Fuel.Application.Repositories;
  6. using Fuel.Application.Service;
  7. using Fuel.Infrastructure;
  8. using Fuel.Payment.Service.AliPaymentProcessor.Alipay;
  9. using Fuel.Payment.Service.AllInPayProcessor.AllInPay;
  10. using Fuel.Payment.Service.Factory;
  11. using Fuel.Payment.Service.Pay;
  12. using Fuel.Payment.Service.UnionPayProcessor;
  13. using Fuel.PaymentServer.MicServer;
  14. using Fuel.Infrastructure.Extension;
  15. using CSRedis;
  16. using Microsoft.Extensions.Logging;
  17. using Fuel.Core;
  18. using Microsoft.AspNetCore.Authorization;
  19. using Fuel.Application.Authorization;
  20. var builder = WebApplication.CreateBuilder(args);
  21. builder.Services.AddScoped<IPayService, PayService>();
  22. AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ALI_SCAN", new AlipayPaymentProcessor());
  23. //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "WX_SCAN", new WechatPaymentProcessor());
  24. AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ALL_IN_SCAN", new AllInPayProcessor());
  25. //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ALL_IN_SCAN_V2", new AllInPayProcessorV2());
  26. //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "WX_ORDER_SCAN", new WechatPaymentProcessor());
  27. AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ALI_ORDER_SCAN", new AlipayPaymentProcessor());
  28. //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "WECHAT_MINIPROGRAM_PAY", new WechatPaymentProcessor());
  29. //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ICBC_SCAN", new IcbcPayProcessor());
  30. //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "ICBC_ORDER_SCAN", new IcbcPayProcessor());
  31. //AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "GRG_SCAN", new GrgPayProcessor());
  32. AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "UNION_MINI", new MiniUnionPayProcessor());
  33. AsyncPaymentProcessorFactory.Default.Regist(o => o.Channel == "UNION_SCAN", new UnionPayProcessor());
  34. // Add services to the container.
  35. // 添加FreeSQL配置
  36. builder.Services.AddFreeSql(builder.Configuration);
  37. //初始化DFS Server
  38. builder.Services.AddMicService(builder.Environment);
  39. builder.Services.AddHttpContextAccessor();
  40. builder.Services.AddScoped<INozzleRepository, NozzleRepository>();
  41. builder.Services.AddScoped<INozzleService, NozzleService>();
  42. builder.Services.AddScoped<ITransactionsService, TransactionsService>();
  43. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  44. builder.Services.AddEndpointsApiExplorer();
  45. builder.Services.AddSwaggerGen();
  46. Fuel.Infrastructure.Extension.RedisOptions redisOptions = builder.Configuration.GetSection("Redis").Get<Fuel.Infrastructure.Extension.RedisOptions>();
  47. builder.Services.UseRedisClient(redisOptions);
  48. // 动态添加基于权限的策略
  49. void AddPermissionPolicies(AuthorizationOptions options)
  50. {
  51. // 获取所有可能的权限字符串(这里只是一个例子,你应该根据实际情况实现)
  52. var permissions = Authorization.GetPermissions();
  53. foreach (var permission in permissions)
  54. {
  55. options.AddPolicy($"Permission_{permission}", policy =>
  56. policy.Requirements.Add(new PermissionRequirement(permission)));
  57. }
  58. }
  59. builder.Services.AddAuthorization(options =>
  60. {
  61. AddPermissionPolicies(options);
  62. });
  63. var app = builder.Build();
  64. app.UseRouting();
  65. var loggerFactory = LoggerFactory.Create(builder =>
  66. {
  67. builder.AddConsole();
  68. });
  69. var accessKeySecret = "sfsdfasfsdafasdfdsa";//密钥
  70. var logger = loggerFactory.CreateLogger<SignatureValidator>();
  71. var signatureValidator = new SignatureValidator(accessKeySecret, logger);
  72. app.UseMiddleware<SignatureValidationMiddleware>(signatureValidator);//签名验证
  73. // Configure the HTTP request pipeline.
  74. if (app.Environment.IsDevelopment())
  75. {
  76. app.UseSwagger();
  77. app.UseSwaggerUI();
  78. }
  79. app.UseDFSServer();
  80. app.UseHttpsRedirection();
  81. app.UseAuthentication();
  82. app.UseAuthorization();
  83. app.MapControllers();
  84. app.Run();