Esempio n. 1
0
        public async Task <string> CreateToken(string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException($"key 不能为空");
            }

            var weChatSession = await _weChatSessionStore.GetSessionInfo(key);

            return(_associateWeChatUser.GetUserToken(weChatSession.OpenId));
        }
        public async Task <WeChatLoginDto> Login(string key)
        {
            CheckValue.NotNullOrWhiteSpace(key, nameof(key));

            var weChatSessionInfo = await _weChatSessionStore.GetSessionInfo(key) ?? throw new ArgumentException("没有找到匹配的微信密匙信息");

            var anyUser = await _wechatRepository.GetUserIdWithOpenId(weChatSessionInfo.OpenId);

            if (anyUser == default)
            {
                return(WeChatLoginDto.NoUser(key));
            }

            var user = await _userRepository.FindAsync(anyUser);

            var token = _jwtSupporter.CreateToken(user);

            return(new WeChatLoginDto()
            {
                AccessToken = token, HasUser = true, UserInfo = user.Adapt <UserDto>()
            });
        }