/// <summary> /// Initializes a new instance of the <see cref="WeChatClient"/> class. /// </summary> /// <param name="client"></param> /// <param name="logger"></param> /// <param name="config"></param> /// <exception cref="ArgumentNullException">client</exception> public WeChatClient( HttpMessageInvoker client, ILogger <WeChatClient> logger, WeChatOptions config) : this(() => client, logger, config) { }
/// <summary> /// 使用微信登陆。 /// </summary> /// <param name="app"></param> /// <param name="configureOptions"></param> /// <returns></returns> public static SchubertWebBuilder AddWeChatSignIn(this SchubertWebBuilder app, Action <WeChatOptions> configureOptions = null) { WeChatOptions options = new WeChatOptions(); configureOptions?.Invoke(options); return(app.ConfigureServices(s => s.AddAuthentication().AddOAuth <WeChatOptions, WeChatOAuthHandler>(WeiboDefaults.AuthenticationScheme, WechatDefaults.DisplayName, configureOptions))); }
public WeChatHttpClient(HttpClient httpClient, IOptions <WeChatOptions> options , IWeChatRequestFilter requestFilter) { this.httpClient = httpClient; this.requestFilter = requestFilter; this.options = options.Value; }
/// <summary> /// Initializes a new instance of the <see cref="StrokeService"/> class. /// </summary> /// <param name="strokeContext">The stroke context.</param> /// <param name="weChatOptions">The we chat options.</param> /// <param name="logger"></param> /// <param name="contextAccessor"></param> public StrokeService(StrokeContext strokeContext, IOptions <WeChatOptions> weChatOptions, ILogger <StrokeService> logger, IHttpContextAccessor contextAccessor, IMemoryCache memoryCache) { this.strokeContext = strokeContext; this.weChatOptions = weChatOptions.Value; this.Logger = logger; this.contextAccessor = contextAccessor; this.memoryCache = memoryCache; }
/// <summary> /// Initializes a new instance of the <see cref="PaymentService"/> class. /// </summary> /// <param name="strokeContext">The stoke context.</param> /// <param name="logger">The logger.</param> /// <param name="weChatOptions">The we chat options.</param> /// <param name="configOptions"></param> /// <param name="httpContextAccessor">The HTTP context accessor.</param> public PaymentService(StrokeContext strokeContext, ILogger <PaymentService> logger, IOptions <WeChatOptions> weChatOptions, IOptions <ConfigOptions> configOptions, IHttpContextAccessor httpContextAccessor) { this.strokeContext = strokeContext; this.Logger = logger; this.weChatOptions = weChatOptions.Value; this.configOptions = configOptions.Value; this.httpContextAccessor = httpContextAccessor; }
/// <summary> /// Initializes a new instance of the <see cref="HomeController" /> class. /// </summary> /// <param name="weChatOptions">The we chat options.</param> /// <param name="jwtOptions">The JWT options.</param> /// <param name="configOptions"></param> /// <param name="logger">The logger.</param> /// <param name="strokeContext">The stroke context.</param> public HomeController(IOptions <WeChatOptions> weChatOptions, IOptions <JwtOptions> jwtOptions, IOptions <ConfigOptions> configOptions, ILogger <HomeController> logger, StrokeContext strokeContext) { this.weChatOptions = weChatOptions.Value; this.logger = logger; this.strokeContext = strokeContext; this.jwtOptions = jwtOptions.Value; this.configOptions = configOptions.Value; }
private static WeChatOptions CreateWeChatAuthOptions(IConfiguration configuration) { var options = new WeChatOptions { AppId = configuration["Authentication:WeChat:AppId"], AppSecret = configuration["Authentication:WeChat:AppSecret"], SignInScheme = AuthenticationScheme }; return(options); }
/// <summary> /// Initializes a new instance of the <see cref="WeChatClient"/> class. /// </summary> /// <param name="client"></param> /// <param name="logger"></param> /// <param name="config"></param> /// <exception cref="ArgumentNullException">client</exception> public WeChatClient( Func <HttpMessageInvoker> client, ILogger <WeChatClient> logger, WeChatOptions config) { _client = client ?? throw new ArgumentNullException(nameof(client)); _logger = logger; _config = config; InitScopeAutoMapper(); }
/// <summary> /// Adds the <see cref="WeChatMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables WeChat authentication capabilities. /// </summary> /// <param name="app">The <see cref="IApplicationBuilder" /> to add the middleware to.</param> /// <param name="configureOptions">An action delegate to configure the provided <see cref="WeChatOptions"/>.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IApplicationBuilder UseWeChatAuthentication(this IApplicationBuilder app, Action <WeChatOptions> configureOptions) { if (app == null) { throw new ArgumentNullException(nameof(app)); } var options = new WeChatOptions(); configureOptions?.Invoke(options); return(app.UseWeChatAuthentication(options)); }
/// <summary> /// Initializes a new instance of the <see cref="UserService"/> class. /// </summary> /// <param name="strokeContext">The stroke context.</param> /// <param name="weChatOptions">The we chat options.</param> /// <param name="logger"></param> /// <param name="jwtOptions"></param> /// <param name="contextAccessor"></param> /// <param name="smsOptions"></param> /// <param name="memory"></param> /// <param name="hostingEnvironment"></param> public UserService(StrokeContext strokeContext, IOptions <WeChatOptions> weChatOptions, ILogger <UserService> logger, IOptions <JwtOptions> jwtOptions, IHttpContextAccessor contextAccessor, IOptions <SMSOptions> smsOptions, IMemoryCache memory, IHostingEnvironment hostingEnvironment ) { this.strokeContext = strokeContext; this.weChatOptions = weChatOptions.Value; this.Logger = logger; this.jwtOptions = jwtOptions.Value; this.contextAccessor = contextAccessor; this.smsOptions = smsOptions.Value; this.memory = memory; this.hostingEnvironment = hostingEnvironment; }
/// <summary> /// 构造函数 /// </summary> /// <param name="logger"></param> /// <param name="weChatClient"></param> /// <param name="config"></param> /// <param name="cache"></param> public TokenAccessHostedService( ILogger <TokenAccessHostedService> logger, IWeChatClient weChatClient, WeChatOptions config, IWeChatCache cache) { _logger = logger; _weChatClient = weChatClient; _config = config; _cacheManager = cache; // 过期策略 1/4过期生效,1/5刷新间隔 刷新必定命中过期片段 _expireTime = _config.RefreshTimeSpan * 60 * 5; _allowRefreshTimeOffset = _config.RefreshTimeSpan * 60 * 5 / 4; }
/// <summary> /// 定义WeChat功能 /// </summary> /// <param name="services">注入服务</param> /// <param name="configuration">全局配置文件</param> /// <param name="options">配置参数</param> /// <returns></returns> public static IServiceCollection AddWeChatCore(this IServiceCollection services, [NotNull] IConfiguration configuration, [NotNull] Action <WeChatOptions> options) { configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); options = options ?? throw new ArgumentNullException(nameof(options)); #region Construct Config var config = new WeChatOptions(); options(config); config.AssertAppConfigIsValid(); #endregion services.AddWeChatCache(configuration, config); services.AddWeChatHttpClient(config); services.AddTransient <IWeChatClient, WeChatClient>(); services.AddHostedService <TokenAccessHostedService>(); return(services); }
/// <summary> /// 定义HttpMessageInvoker /// </summary> /// <param name="services"></param> /// <param name="config"></param> /// <returns></returns> private static void AddWeChatHttpClient(this IServiceCollection services, WeChatOptions config) { var httpFunc = config.ClientFactory; if (httpFunc != null) { services.AddTransient(ioc => httpFunc); } else { services.AddHttpClient(); services.AddTransient <Func <HttpMessageInvoker> >(ioc => { return(() => { var factory = ioc.GetService <IHttpClientFactory>(); return factory.CreateClient(); }); }); } }
public WeChatAuthService(WeChatOptions options) { _options = options; }
/// <summary> /// Initializes a new instance of the <see cref="WeChatController"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="memoryCache">The memory cache.</param> /// <param name="weChatOptions">The we chat options.</param> public WeChatController(ILogger <WeChatController> logger, IMemoryCache memoryCache, IOptions <WeChatOptions> weChatOptions) { this.Logger = logger; this.memoryCache = memoryCache; this.weChatOptions = weChatOptions.Value; }
private static void AddWeChatCache(this IServiceCollection services, IConfiguration configuration, WeChatOptions config) { config.UseCache(services, configuration, config.WeChatConfig); services.AddSingleton(ioc => { config.WeChatConfig.CacheManager = ioc.GetRequiredService <IWeChatCache>(); return(config); }); }
public static HuskyServiceHub AddWeChatIntegration(this HuskyServiceHub husky, WeChatOptions options) { husky.Services.AddScoped(svc => new WeChatService( options, svc.GetRequiredService <IHttpContextAccessor>(), svc.GetRequiredService <IMemoryCache>() ) ); return(husky); }
public WeChatJsApiService(WeChatOptions options, IHttpContextAccessor httpContextAccessor, IMemoryCache cache) { _options = options; _httpContextAccessor = httpContextAccessor; _cache = cache; }
/// <summary> /// Adds the <see cref="WeChatMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables WeChat authentication capabilities. /// </summary> /// <param name="app">The <see cref="IApplicationBuilder" /> to add the middleware to.</param> /// <param name="options">A <see cref="WeChatOptions"/> that specifies options for the middleware.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IApplicationBuilder UseWeChatAuthentication(this IApplicationBuilder app, WeChatOptions options) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(app.UseMiddleware <WeChatMiddleware>(options)); }
public WeChatPayService(WeChatOptions options) { _options = options; _options.RequireMerchantSettings(); }
public WeChatUserService(WeChatOptions options) { _options = options; }