Startup.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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(IHostingEnvironment env)
  15. {
  16. var builder = new ConfigurationBuilder();
  17. if (env.IsDevelopment()) // 添加用户机密
  18. {
  19. builder.AddUserSecrets<Startup>();
  20. }
  21. Configuration = builder.Build();
  22. }
  23. public void ConfigureServices(IServiceCollection services)
  24. {
  25. services.AddMvc();
  26. services.AddAlipay();
  27. services.AddWeChatPay();
  28. services.AddQPay();
  29. services.AddJdPay();
  30. services.Configure<AlipayOptions>(Configuration.GetSection("Alipay"));
  31. services.Configure<WeChatPayOptions>(Configuration.GetSection("WeChatPay"));
  32. services.Configure<QPayOptions>(Configuration.GetSection("QPay"));
  33. services.Configure<JdPayOptions>(Configuration.GetSection("JdPay"));
  34. // 配置参数
  35. //{
  36. // "Alipay": {
  37. // "AppId": "xxx",
  38. // "RsaPublicKey": "xxx",
  39. // "RsaPrivateKey": "xxx"
  40. // },
  41. // "WeChatPay": {
  42. // "AppId": "xxx",
  43. // "AppSecret": "xxx",
  44. // "MchId": "xxx",
  45. // "Key": "xxx",
  46. // "Certificate": "xxx",
  47. // },
  48. // "QPay": {
  49. // "MchId": "xxx",
  50. // "Key": "xxx",
  51. // "Certificate": "xxx",
  52. // },
  53. // "JdPay": {
  54. // "Merchant": "xxx",
  55. // "RsaPublicKey": "xxx",
  56. // "RsaPrivateKey": "xxx",
  57. // "DesKey": "xxx"
  58. // }
  59. //}
  60. }
  61. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  62. {
  63. if (env.IsDevelopment())
  64. {
  65. app.UseDeveloperExceptionPage();
  66. app.UseBrowserLink();
  67. }
  68. else
  69. {
  70. app.UseExceptionHandler("/Home/Error");
  71. }
  72. app.UseStaticFiles();
  73. app.UseMvc(routes =>
  74. {
  75. routes.MapRoute(
  76. name: "default",
  77. template: "{controller=Home}/{action=Index}/{id?}");
  78. });
  79. }
  80. }
  81. }