Ejemplo n.º 1
0
        public void LoginMiniAlipay_WhenFailed_ThenError()
        {
            A.CallTo(() => _alipayService.GetUserIdByCode(A <string> .Ignored)).Returns(new Alipay.AopSdk.Core.Response.AlipaySystemOauthTokenResponse()
            {
                Code = "error"
            });

            var result = _service.LoginMiniAlipay(A <string> .Ignored);

            Assert.Pass();
        }
Ejemplo n.º 2
0
        public LoginResultModel LoginMiniAlipay(string code)
        {
            var response = _alipayService.GetUserIdByCode(code);

            if (response.IsError)
            {
                _logger.LogError(response.Body);
                return(null);
            }

            var alipayUser = _userRepo.FindByAlipayId(response.AlipayUserId);

            if (alipayUser == null)
            {
                alipayUser = _userRepo.Create(new AlipayUser()
                {
                    Id            = "yufelix",
                    AlibabaUserId = response.UserId,
                    AlipayUserId  = response.AlipayUserId,
                    CreatedAt     = DateTime.UtcNow
                });
            }

            var tokenStr = _tokenService.CreateJwtToken(alipayUser);
            var result   = new LoginResultModel()
            {
                BOToken      = tokenStr,
                AccessToken  = response.AccessToken,
                ExpiresIn    = response.ReExpiresIn,
                ReExpiresIn  = response.ReExpiresIn,
                RefreshToken = response.RefreshToken,
                UserId       = alipayUser.Id,
                NickName     = alipayUser.AlipayName,
                Photo        = alipayUser.AlipayPhoto
            };

            return(result);
        }