123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- using System;
- using System.Collections.Generic;
- using System.ServiceModel;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Http.Features;
- using Microsoft.AspNetCore.Rewrite;
- using Microsoft.AspNetCore.StaticFiles;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.FileProviders;
- using Microsoft.Extensions.Hosting;
- using MySystem.PublicClass.GraphQL;
- using System.Text;
- using Microsoft.IdentityModel.Tokens;
- using System.Linq;
- namespace MySystem
- {
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- }
- public IConfiguration Configuration { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddControllersWithViews();
- services.AddRouting(options =>
- {
- options.LowercaseUrls = true;
- });
- services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
- services.Configure<Setting>(Configuration.GetSection("Setting"));
- // services.AddCors(option => option.AddPolicy("cors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().SetIsOriginAllowed(_ => true)));
- services.AddMvc(options =>
- {
- options.EnableEndpointRouting = false;
- options.Filters.Add(typeof(GlobalExceptions));
- });
- services.AddSession(options =>
- {
- // 设置 Session 过期时间
- options.IdleTimeout = TimeSpan.FromHours(1);
- options.Cookie.HttpOnly = true;
- });
- services.AddSingleton<IRepository, Repository>();
- services.Configure<FormOptions>(x =>
- {
- x.MultipartBodyLengthLimit = 50 * 1024 * 1024;//不到300M
- });
- //生成密钥
- var symmetricKeyAsBase64 = Configuration["Setting:JwtSecret"];
- var keyByteArray = Encoding.ASCII.GetBytes(symmetricKeyAsBase64);
- var signingKey = new SymmetricSecurityKey(keyByteArray);
- //认证参数
- services.AddAuthentication("Bearer").AddJwtBearer(o =>
- {
- o.TokenValidationParameters = new TokenValidationParameters
- {
- ValidateIssuerSigningKey = true,//是否验证签名,不验证的画可以篡改数据,不安全
- IssuerSigningKey = signingKey,//解密的密钥
- ValidateIssuer = true,//是否验证发行人,就是验证载荷中的Iss是否对应ValidIssuer参数
- // ValidIssuer = Configuration["Setting:JwtIss"],//发行人
- IssuerValidator = (m, n, z) =>
- {
- return n.Issuer;
- },
- ValidateAudience = true,//是否验证订阅人,就是验证载荷中的Aud是否对应ValidAudience参数
- // ValidAudience = Configuration["Setting:JwtAud"],//订阅人
- AudienceValidator = (m, n, z) =>
- {
- string check = RedisDbconn.Instance.Get<string>("utoken:" + n.Issuer);
- return m != null && m.FirstOrDefault().Equals(check);
- },
- ValidateLifetime = true,//是否验证过期时间,过期了就拒绝访问
- ClockSkew = TimeSpan.Zero,//这个是缓冲过期时间,也就是说,即使我们配置了过期时间,这里也要考虑进去,过期时间+缓冲,默认好像是7分钟,你可以直接设置为0
- RequireExpirationTime = true,
- };
- });
-
- MySystemLib.SystemPublicFuction.appcheck = "success";
- string conn = Configuration["Setting:SqlConnStr"];
- Dictionary<string, Dictionary<string, string>> tables = new Dictionary<string, Dictionary<string, string>>();
- System.Data.DataTable tablecollection = Library.CustomerSqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = 'QrCodePlateMainServer'", conn);
- foreach (System.Data.DataRow subtable in tablecollection.Rows)
- {
- Dictionary<string, string> Columns = new Dictionary<string, string>();
- System.Data.DataTable columncollection = Library.CustomerSqlConn.dtable("select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_schema = 'QrCodePlateMainServer' and TABLE_NAME='" + subtable["TABLE_NAME"].ToString() + "'", conn);
- foreach (System.Data.DataRow column in columncollection.Rows)
- {
- string datatype = column["DATA_TYPE"].ToString();
- if (datatype == "decimal")
- {
- datatype = "numeric";
- }
- Columns.Add(column["COLUMN_NAME"].ToString(), datatype);
- }
- tables.Add(subtable["TABLE_NAME"].ToString(), Columns);
- }
- MySystemLib.SystemPublicFuction.dbtables = tables;
- RedisDbconn.csredis = new CSRedis.CSRedisClient(Configuration["Setting:RedisConnStr"]);
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- // app.UseExceptionHandler("/Home/Error");
- Library.ConfigurationManager.EnvironmentFlag = 1;
- }
- else
- {
- app.UseExceptionHandler("/Home/Error");
- app.UseHsts();
- Library.ConfigurationManager.EnvironmentFlag = 2;
- }
- Library.function.WritePage("/", "WebRootPath.txt", env.WebRootPath);
- // app.UseStatusCodePagesWithReExecute("/public/errpage/pc/{0}.html");
- // RequestDelegate handler = async context =>
- // {
- // var response = context.Response;
- // if (response.StatusCode < 500)
- // {
- // response.("/public/errpage/pc/{0}.html");
- // }
- // };
- // app.UseStatusCodePages(builder => builder.Run(handler));
- app.UseStaticFiles();
- app.UseStaticFiles(new StaticFileOptions
- {
- FileProvider = new PhysicalFileProvider(AppContext.BaseDirectory + "/static"),
- RequestPath = "/static"
- });
- // app.UseStaticFiles(new StaticFileOptions
- // {
- // FileProvider = new PhysicalFileProvider(AppContext.BaseDirectory + "/" + Configuration["Setting:Database"]),
- // RequestPath = "/" + Configuration["Setting:Database"]
- // });
- app.UseStaticFiles(new StaticFileOptions
- {
- ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
- {
- { ".apk", "application/vnd.android.package-archive" }
- })
- });
- app.UseCors("cors");
- app.UseAuthentication();
- app.UseRouting();
- app.UseAuthorization();
- app.UseSession();
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapControllerRoute(
- name: "default",
- pattern: "{controller=Home}/{action=Index}/{Id?}");
- });
- //必须打开的
- if(Library.ConfigurationManager.EnvironmentFlag == 1)
- {
- // MerchantStandardService.Instance.Start();
- // MerchantStandardService.Instance.StartThree();
- // MerchantStandardService.Instance.StartActive();
- // ProfitHelper.Instance.ReturnStat("157186", 2);
- // ProfitHelper.Instance.ReturnStat("157187", 2);
- // ProfitHelper.Instance.ReturnStat("157190", 2);
- // ProfitHelper.Instance.ReturnStat("157191", 2);
- // ProfitHelper.Instance.ReturnStat("157192", 2);
- // ProfitHelper.Instance.ReturnStat("157193", 2);
- // ProfitHelper.Instance.ReturnStat("157194", 2);
- // ProfitHelper.Instance.ReturnStat("157195", 2);
- // ProfitHelper.Instance.ReturnStat("157196", 2);
- // ProfitHelper.Instance.ReturnStat("157197", 2);
- // ProfitHelper.Instance.ReturnStat("157198", 2);
- }
- if(Library.ConfigurationManager.EnvironmentFlag == 2)
- {
- GetTencentAddressInfoService.Instance.Start(); // 获取腾讯地图地址
- UpdateSignUrlService.Instance.Start(); //更新签约码
- MerchantConfirmService.Instance.Start(); //特约商户进件队列
- CheckAlipaySignService.Instance.Start(); //特约商户签约队列(支付宝)
- CheckWeChatSignService.Instance.Start(); //特约商户签约队列(微信)
- AlipayPayBackService.Instance.Start(); //支付宝支付回调队列
- AlipayPayBackService.Instance.StartProfitShare(); //监听已支付订单,超过1分钟的订单执行分账
- WeChatPayBackService.Instance.Start(); //微信支付回调队列
- WeChatPayBackService.Instance.StartProfitShare(); //监听已支付订单,超过1分钟的订单执行分账
- // ProfitHelper.Instance.StartActive(); //发放达标奖励队列
- ProfitHelper.Instance.StartListenTrade(); //支付宝返现队列
- ProfitHelper.Instance.StartListenWxTrade(); //微信返现队列
- ProfitHelper.Instance.StartSetDivi(); //设置订单当前返现金额
- ProfitShareService.Instance.Start(); //分账状态监控队列,分账完成则提交返现(微信)
- AlipayShareService.Instance.Start(); //分账状态监控队列,分账完成则提交返现(支付宝)
- WeChatPayBackService.Instance.StartDivi(); //补分账
- AlipayPayBackService.Instance.StartDivi(); //补分账
- ProfitHelper.Instance.StartListenProfit(); //每月分润
- AlipayPayBackFeeService.Instance.Start();
- ActiveRewardService.Instance.StartAct();
- ActiveRewardService.Instance.StartOpenReward();
- ActiveRewardService.Instance.StartLeaderReward();
- ActiveRewardService.Instance.StartOperateReward();
- MerchantStandardService.Instance.Start(); //商户缴纳服务费次月活动交易额大于等于1W,奖励进件创客50元
- MerchantStandardService.Instance.StartThree(); //商户缴纳服务费次月起连续不间断三个月,每月活动交易额大于1W,奖励进件创客100元
- MerchantStandardService.Instance.StartActive();
- }
- // HaoDaExtHelper.Instance.StartWeChat();
- // HaoDaExtHelper.Instance.StartAlipay();
- // HaoDaExtQueryHelper.Instance.StartWeChat();
- // HaoDaExtQueryHelper.Instance.StartAlipay();
- //必须打开的
-
- }
- }
- }
|