Startup.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Essensoft.AspNetCore.Payment.Alipay;
  2. using Essensoft.AspNetCore.Payment.JDPay;
  3. using Essensoft.AspNetCore.Payment.LianLianPay;
  4. using Essensoft.AspNetCore.Payment.QPay;
  5. using Essensoft.AspNetCore.Payment.UnionPay;
  6. using Essensoft.AspNetCore.Payment.WeChatPay;
  7. using Microsoft.AspNetCore.Builder;
  8. using Microsoft.AspNetCore.Hosting;
  9. using Microsoft.Extensions.Configuration;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using Microsoft.Extensions.Hosting;
  12. namespace WebApplicationSample_V3_0
  13. {
  14. public class Startup
  15. {
  16. public Startup(IConfiguration configuration)
  17. {
  18. Configuration = configuration;
  19. }
  20. public IConfiguration Configuration { get; }
  21. // This method gets called by the runtime. Use this method to add services to the container.
  22. public void ConfigureServices(IServiceCollection services)
  23. {
  24. // 引入Payment 依赖注入
  25. services.AddAlipay();
  26. services.AddJDPay();
  27. services.AddQPay();
  28. services.AddUnionPay();
  29. services.AddWeChatPay();
  30. services.AddLianLianPay();
  31. // 在 appsettings.json 中 配置选项
  32. services.Configure<AlipayOptions>(Configuration.GetSection("Alipay"));
  33. services.Configure<JDPayOptions>(Configuration.GetSection("JDPay"));
  34. services.Configure<QPayOptions>(Configuration.GetSection("QPay"));
  35. services.Configure<UnionPayOptions>(Configuration.GetSection("UnionPay"));
  36. services.Configure<WeChatPayOptions>(Configuration.GetSection("WeChatPay"));
  37. services.Configure<LianLianPayOptions>(Configuration.GetSection("LianLianPay"));
  38. services.AddControllersWithViews();
  39. }
  40. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  41. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  42. {
  43. if (env.IsDevelopment())
  44. {
  45. app.UseDeveloperExceptionPage();
  46. }
  47. else
  48. {
  49. app.UseExceptionHandler("/Home/Error");
  50. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  51. app.UseHsts();
  52. }
  53. app.UseHttpsRedirection();
  54. app.UseStaticFiles();
  55. app.UseRouting();
  56. app.UseAuthorization();
  57. app.UseEndpoints(endpoints =>
  58. {
  59. endpoints.MapControllerRoute(
  60. name: "default",
  61. pattern: "{controller=Home}/{action=Index}/{id?}");
  62. });
  63. }
  64. }
  65. }