Startup.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Essensoft.AspNetCore.Alipay;
  2. using Essensoft.AspNetCore.JdPay;
  3. using Essensoft.AspNetCore.QPay;
  4. using Essensoft.AspNetCore.WeChatPay;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. namespace WebApplicationSample
  10. {
  11. public class Startup
  12. {
  13. public IConfiguration Configuration { get; }
  14. public Startup(IConfiguration configuration)
  15. {
  16. Configuration = configuration;
  17. }
  18. public void ConfigureServices(IServiceCollection services)
  19. {
  20. services.AddMvc();
  21. // 添加依赖注入
  22. // 依赖注入介绍:https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/dependency-injection
  23. services.AddAlipay();
  24. services.AddWeChatPay();
  25. services.AddQPay();
  26. services.AddJdPay();
  27. // 添加依赖注入时,也可以直接设置参数..
  28. // 如:
  29. //services.AddAlipay(Option =>
  30. //{
  31. // Option.AppId = "xxx";
  32. // Option.RsaPublicKey = "xxx";
  33. //});
  34. // 配置介绍: https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration?tabs=basicconfiguration
  35. // 用户机密介绍: https://docs.microsoft.com/zh-cn/aspnet/core/security/app-secrets?tabs=visual-studio
  36. // 注册配置实例(使用配置文件或用户机密的方式设置参数)
  37. services.Configure<AlipayOptions>(Configuration.GetSection("Alipay"));
  38. services.Configure<WeChatPayOptions>(Configuration.GetSection("WeChatPay"));
  39. services.Configure<QPayOptions>(Configuration.GetSection("QPay"));
  40. services.Configure<JdPayOptions>(Configuration.GetSection("JdPay"));
  41. // 配置参数 具体参数见 AlipayOptions、WeChatPayOptions、QPayOptions、JdPayOptions
  42. //{
  43. // "Alipay": {
  44. // "AppId": "xxx",
  45. // "RsaPublicKey": "xxx",
  46. // "RsaPrivateKey": "xxx"
  47. // },
  48. // "WeChatPay": {
  49. // "AppId": "xxx",
  50. // "AppSecret": "xxx",
  51. // "MchId": "xxx",
  52. // "Key": "xxx",
  53. // "Certificate": "xxx",
  54. // "RsaPublicKey": "xxx",
  55. // },
  56. // "QPay": {
  57. // "MchId": "xxx",
  58. // "Key": "xxx",
  59. // "Certificate": "xxx",
  60. // },
  61. // "JdPay": {
  62. // "Merchant": "xxx",
  63. // "RsaPublicKey": "xxx",
  64. // "RsaPrivateKey": "xxx",
  65. // "DesKey": "xxx"
  66. // }
  67. //}
  68. }
  69. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  70. {
  71. if (env.IsDevelopment())
  72. {
  73. app.UseDeveloperExceptionPage();
  74. app.UseBrowserLink();
  75. }
  76. else
  77. {
  78. app.UseExceptionHandler("/Home/Error");
  79. }
  80. app.UseStaticFiles();
  81. app.UseMvc(routes =>
  82. {
  83. routes.MapRoute(
  84. name: "default",
  85. template: "{controller=Home}/{action=Index}/{id?}");
  86. });
  87. }
  88. }
  89. }