public TokenManager(WeChatHttpClient httpClient, IOptions <WeChatOptions> options, ITokenStore tokenStore) { this.httpClient = httpClient; this.options = options; this.tokenStore = tokenStore; this.Config = options.Value.AppConfigs.First(); this.GetTokenAsync().Wait(); }
public async Task QrCode() { var stream = await WeChatHttpClient.GetMiniProgramQrCodeAsync("36", "1", "wx85137f0c169973eb", "b2650954994f5992688bd88a33ec51a6"); using (var fileStream = File.Create("C:\\wx-qr-code.png")) { stream.Seek(0, SeekOrigin.Begin); stream.CopyTo(fileStream); } }
public async Task <IHttpActionResult> Login(string code) { if (code.IsNullOrWhiteSpace()) { return(Ok(GetErrorModel(ApiErrorCode.SessionExpired))); } var session = await WeChatHttpClient.GetSessionAsync(code, ConfigurationManager.AppSettings.Get("WeChatMiniProgramAppId"), ConfigurationManager.AppSettings.Get("WeChatMiniProgramAppSecret")); using (var context = new TasteContext()) { var user = context.Users.FirstOrDefault(u => string.Equals(u.UserId, session.OpenId)); if (user != null) { return(Ok(user.UserId)); } user = context.Users.Add(new User { Name = session.OpenId, UserId = session.OpenId }); context.SaveChanges(); return(Ok(user.UserId)); } }
public WeChatManager(TokenManager tokenManager) { this.tokenManager = tokenManager; this.httpClient = tokenManager.httpClient; this.httpClient.SetManager(tokenManager); }