Startup.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using Essensoft.AspNetCore.Payment.Alipay;
  2. using Essensoft.AspNetCore.Payment.JdPay;
  3. using Essensoft.AspNetCore.Payment.QPay;
  4. using Essensoft.AspNetCore.Payment.UnionPay;
  5. using Essensoft.AspNetCore.Payment.WeChatPay;
  6. using Microsoft.AspNetCore.Builder;
  7. using Microsoft.AspNetCore.Hosting;
  8. using Microsoft.Extensions.Configuration;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using System.Text.Encodings.Web;
  11. using System.Text.Unicode;
  12. namespace WebApplicationSample
  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. services.AddMvc();
  25. // 添加依赖注入
  26. // 依赖注入介绍:https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/dependency-injection
  27. services.AddAlipay();
  28. services.AddJdPay();
  29. services.AddQPay();
  30. services.AddUnionPay();
  31. services.AddWeChatPay();
  32. // 配置介绍: https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration?tabs=basicconfiguration
  33. // 用户机密介绍: https://docs.microsoft.com/zh-cn/aspnet/core/security/app-secrets?tabs=visual-studio
  34. // 注册配置实例(使用配置文件或用户机密的方式设置参数)
  35. services.Configure<AlipayOptions>(Configuration.GetSection("Alipay"));
  36. services.Configure<JdPayOptions>(Configuration.GetSection("JdPay"));
  37. services.Configure<QPayOptions>(Configuration.GetSection("QPay"));
  38. services.Configure<UnionPayOptions>(Configuration.GetSection("UnionPay"));
  39. services.Configure<WeChatPayOptions>(Configuration.GetSection("WeChatPay"));
  40. services.AddWebEncoders(opt =>
  41. {
  42. opt.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
  43. });
  44. // Json格式 配置参数. 具体参数见 AlipayOptions、JdPayOptions、QPayOptions、UnionPayOptions、WeChatPayOptions类
  45. //{
  46. // "Alipay": {
  47. // "AppId": "xxx",
  48. // "RsaPublicKey": "xxx",
  49. // "RsaPrivateKey": "xxx",
  50. // "SignType" : "RSA2"
  51. // },
  52. // "JdPay": {
  53. // "Merchant": "xxx",
  54. // "RsaPublicKey": "xxx",
  55. // "RsaPrivateKey": "xxx",
  56. // "DesKey": "xxx"
  57. // },
  58. // "QPay": {
  59. // "MchId": "xxx",
  60. // "Key": "xxx",
  61. // "Certificate": "xxx",
  62. // },
  63. // "UnionPay": {
  64. // "MerId": "xxx",
  65. // "SignCert": "xxx",
  66. // "SignCertPassword": "xxx",
  67. // "EncryptCert": "xxx",
  68. // "MiddleCert": "xxx",
  69. // "RootCert": "xxx",
  70. // "SecureKey": "xxx",
  71. // },
  72. // "WeChatPay": {
  73. // "AppId": "xxx",
  74. // "AppSecret": "xxx",
  75. // "MchId": "xxx",
  76. // "Key": "xxx",
  77. // "Certificate": "xxx",
  78. // "RsaPublicKey": "xxx",
  79. // }
  80. //}
  81. }
  82. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  83. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  84. {
  85. if (env.IsDevelopment())
  86. {
  87. app.UseBrowserLink();
  88. app.UseDeveloperExceptionPage();
  89. }
  90. else
  91. {
  92. app.UseExceptionHandler("/Home/Error");
  93. }
  94. app.UseStaticFiles();
  95. app.UseMvc(routes =>
  96. {
  97. routes.MapRoute(
  98. name: "default",
  99. template: "{controller=Home}/{action=Index}/{id?}");
  100. });
  101. }
  102. }
  103. }