コード例 #1
0
        private async System.Threading.Tasks.Task <SendTemplateMessageResult> SendTemplateMessageAsync(
            string title, string content, string openID
            )
        {
            // Senparc.Weixin.MP.AdvancedAPIs.TemplateApi.SendTemplateMessage
            var accesstoken = await _accessTokenService.GetAccessToken(_wechatSetting.AppID, _wechatSetting.AppSecret);

            // get error, see https://www.cnblogs.com/szw/p/9265828.html
            // var accesstoken = Senparc.Weixin.MP.Containers.AccessTokenContainer.TryGetAccessToken(_wechatSetting.AppID, _wechatSetting.AppSecret);

            var data = new
            {
                title = new
                {
                    value = title,
                    color = "#cc2900"
                },
                content = new
                {
                    value = content,
                    color = "#173177"
                }
            };
            var result = await Senparc.Weixin.MP.AdvancedAPIs.TemplateApi.SendTemplateMessageAsync(accesstoken, openID,
                                                                                                   _wechatSetting.TemplateMessageID, "", data);

            return(result);
        }
コード例 #2
0
 private Ld_Member_AccessToken GetMemberAccessToken(string token)
 {
     try
     {
         var entity = AccessTokenService.GetAccessToken(token);
         if (entity == null)
         {
             return(null);
         }
         return(entity.ToObject <Ld_Member_AccessToken>());
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
コード例 #3
0
        public IActionResult RefreshToken(string uuid, [FromBody] JObject fromValue)
        {
            long logId = 0;

            try
            {
                logId = BaseApiManager.SaveLogs(uuid);
                if (!IsUuid(uuid))
                {
                    return(Error(logId, "verify uuid fail!"));
                }
                bool   isParams      = IsLoginParams(fromValue);
                string fRefreshToken = GetJObjectValue(fromValue, "refresh_token");
                if (string.IsNullOrWhiteSpace(fRefreshToken))
                {
                    return(Error(logId, "refresh token not empty!"));
                }
                var    tokenService          = new Common.Token.TokenHelper();
                string token                 = tokenService.GetToken();
                string refreshToken          = tokenService.GetToken();
                int    expiresIn             = AccessTokenExpiresIn;
                int    refreshTokenExpiresIn = RefreshTokenExpiresIn;
                string ipAddress             = Net.Ip;
                int    createTimestamp       = TimeHelper.GetUnixTimestamp();
                var    createResult          = AccessTokenService.SaveRefreshTokenPro(fRefreshToken, token, refreshToken, expiresIn, refreshTokenExpiresIn, ipAddress, createTimestamp);
                if (createResult)
                {
                    var entityMember = AccessTokenService.GetAccessToken(token);
                    return(Result(new
                    {
                        access_token = token,
                        expiresin = expiresIn,
                        refresh_token = refreshToken,
                        memberid = entityMember.MemberID,
                        scope = "scope"
                    }));
                }
                return(Error(logId, "fail"));
            }
            catch (Exception ex)
            {
                return(Error(logId, ex.Message));
            }
        }
コード例 #4
0
        public async Task <LoginUserResponse> Handle(LoginUserCommand request, CancellationToken cancellationToken)
        {
            var user = await _uowGeneral.UserRepository.FindByEmail(request.Email)
                       ?? throw new InvalidAccountException();

            if (user.HasDisabledAccount())
            {
                throw new InvalidAccountException("Cuenta deshabilitada");
            }

            var loginMaxAttempt = await _uowGeneral.LoginMaxAttemptRepository.Find(GeneralConstants.DefaultId);

            if (await HasReachedLoginMaxAttempts(user, loginMaxAttempt.MaxAttempts))
            {
                throw new LoginMaxAttemptsReachedException();
            }

            if (!_passwordService.Verify(request.Password, user.Password))
            {
                await HandleFailedLogin(user, loginMaxAttempt.MaxAttempts);

                throw new InvalidAccountException();
            }

            user.AddEvent(new UserLogged()
            {
                User = user
            });
            await AllowUserAccess(user);

            var accessToken = await _accessTokenService.GetAccessToken(user);

            var refreshToken = await _refreshTokenService.GetRefreshToken(user);

            await _uowGeneral.SaveChanges();

            return(new LoginUserResponse()
            {
                AccessToken = accessToken, RefreshToken = refreshToken
            });
        }
コード例 #5
0
        public async Task <RefreshTokenResponse> Handle(RefreshTokenCommand request, CancellationToken cancellationToken)
        {
            var refreshToken = await _uowGeneral.RefreshTokenRepository.FindByToken(request.Token)
                               ?? throw new InvalidRefreshTokenException();

            if (refreshToken.IsExpired())
            {
                throw new InvalidRefreshTokenException("El token de refresco ya ha expirado");
            }

            var user        = refreshToken.User;
            var accessToken = await _accessTokenService.GetAccessToken(user);

            var newRefreshToken = await _refreshTokenService.GetRefreshToken(user);

            await _uowGeneral.RefreshTokenRepository.Delete(refreshToken);

            await _uowGeneral.SaveChanges();

            return(new RefreshTokenResponse()
            {
                AccessToken = accessToken, RefreshToken = newRefreshToken
            });
        }
コード例 #6
0
        public async Task <ActionResult <AccessTokenResponse> > AuthorizeToken(string account, string requestToken, string tokenSecret, string verifier)
        {
            var response = await _accessTokenService.GetAccessToken(account, requestToken, tokenSecret, verifier);

            return((response.Error == null) ? Ok(response) : StatusCode((int)response.Error.StatusCode, response));
        }
 public HttpResponseMessage Get(string requestUri)
 {
     try
     {
         using (HttpClient client = new HttpClient())
         {
             client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessTokenService.GetAccessToken());
             return(client.GetAsync(Setting.addressAPI + requestUri).Result);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }