示例#1
0
 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();
 }
示例#2
0
        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);
            }
        }
示例#3
0
        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));
            }
        }
示例#4
0
 public WeChatManager(TokenManager tokenManager)
 {
     this.tokenManager = tokenManager;
     this.httpClient   = tokenManager.httpClient;
     this.httpClient.SetManager(tokenManager);
 }