Startup.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 System.Text.Encodings.Web;
  12. using System.Text.Unicode;
  13. namespace WebApplicationSample
  14. {
  15. public class Startup
  16. {
  17. public Startup(IConfiguration configuration)
  18. {
  19. Configuration = configuration;
  20. }
  21. public IConfiguration Configuration { get; }
  22. // This method gets called by the runtime. Use this method to add services to the container.
  23. public void ConfigureServices(IServiceCollection services)
  24. {
  25. services.AddMvc();
  26. // 参数配置 可参考以下两篇文章.
  27. // ASP.NET Core Web 支付功能接入 微信-扫码支付篇
  28. // http://www.cnblogs.com/essenroc/p/8630730.html
  29. // ASP.NET Core Web 支付功能接入 支付宝-电脑网页支付篇
  30. // https://www.cnblogs.com/essenroc/p/8627775.html
  31. services.AddAlipay();
  32. services.AddJDPay();
  33. services.AddQPay();
  34. services.AddUnionPay();
  35. services.AddWeChatPay();
  36. services.AddLianLianPay();
  37. services.Configure<AlipayOptions>(Configuration.GetSection("Alipay"));
  38. services.Configure<JDPayOptions>(Configuration.GetSection("JDPay"));
  39. services.Configure<QPayOptions>(Configuration.GetSection("QPay"));
  40. services.Configure<UnionPayOptions>(Configuration.GetSection("UnionPay"));
  41. services.Configure<WeChatPayOptions>(Configuration.GetSection("WeChatPay"));
  42. services.Configure<LianLianPayOptions>(Configuration.GetSection("LianLianPay"));
  43. services.AddWebEncoders(opt =>
  44. {
  45. opt.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
  46. });
  47. // Json格式 配置参数. 具体参数见 AlipayOptions、JDPayOptions、QPayOptions、UnionPayOptions、WeChatPayOptions类
  48. //{
  49. // "Alipay": {
  50. // "AppId": "xxx",
  51. // "RsaPublicKey": "xxx",
  52. // "RsaPrivateKey": "xxx",
  53. // "SignType" : "RSA2"
  54. // },
  55. // "JDPay": {
  56. // "Merchant": "xxx",
  57. // "RsaPublicKey": "xxx",
  58. // "RsaPrivateKey": "xxx",
  59. // "DesKey": "xxx"
  60. // },
  61. // "QPay": {
  62. // "MchId": "xxx",
  63. // "Key": "xxx",
  64. // "Certificate": "xxx",
  65. // },
  66. // "UnionPay": {
  67. // "MerId": "xxx",
  68. // "SignCert": "xxx",
  69. // "SignCertPassword": "xxx",
  70. // "EncryptCert": "xxx",
  71. // "MiddleCert": "xxx",
  72. // "RootCert": "xxx",
  73. // "TestMode": "true",
  74. // },
  75. // "WeChatPay": {
  76. // "AppId": "xxx",
  77. // "MchId": "xxx",
  78. // "Key": "xxx",
  79. // "Certificate": "xxx",
  80. // "RsaPublicKey": "xxx",
  81. // }
  82. //}
  83. }
  84. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  85. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  86. {
  87. if (env.IsDevelopment())
  88. {
  89. app.UseBrowserLink();
  90. app.UseDeveloperExceptionPage();
  91. }
  92. else
  93. {
  94. app.UseExceptionHandler("/Home/Error");
  95. }
  96. app.UseStaticFiles();
  97. app.UseMvc(routes =>
  98. {
  99. routes.MapRoute(
  100. name: "default",
  101. template: "{controller=Home}/{action=Index}/{id?}");
  102. });
  103. }
  104. }
  105. }