|
@@ -307,7 +307,7 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
|
|
/// <param name="dto"></param>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
- public async Task<ApiResponse<TokenOutDto>> GetThredTokenAsync(ThirdTokenInDto dto)
|
|
|
|
|
|
+ public async Task<TokenOutDto> GetThredTokenAsync(ThirdTokenInDto dto)
|
|
{
|
|
{
|
|
var thirdDto = dto.Adapt<ThirdTokenDto>();
|
|
var thirdDto = dto.Adapt<ThirdTokenDto>();
|
|
if (dto.ThirdType == EThirdType.WeChat)
|
|
if (dto.ThirdType == EThirdType.WeChat)
|
|
@@ -316,12 +316,14 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
|
|
thirdDto.Secret = _systemSettingCacheManager.WxOpenAppSecret;
|
|
thirdDto.Secret = _systemSettingCacheManager.WxOpenAppSecret;
|
|
}
|
|
}
|
|
var thirdToken = await _thirdIdentiyService.GetTokenAsync(thirdDto);
|
|
var thirdToken = await _thirdIdentiyService.GetTokenAsync(thirdDto);
|
|
|
|
+ var phone = await _thirdIdentiyService.GetPhoneNumberAsync(thirdDto);
|
|
var thirdAccount = await _thirdAccountRepository.QueryByOpenIdAsync(thirdToken.OpenId);
|
|
var thirdAccount = await _thirdAccountRepository.QueryByOpenIdAsync(thirdToken.OpenId);
|
|
|
|
|
|
// 新用户注册
|
|
// 新用户注册
|
|
if (thirdAccount is null)
|
|
if (thirdAccount is null)
|
|
{
|
|
{
|
|
thirdAccount = thirdToken.Adapt<ThirdAccount>();
|
|
thirdAccount = thirdToken.Adapt<ThirdAccount>();
|
|
|
|
+ thirdAccount.PhoneNumber = phone.PhoneNumber;
|
|
thirdAccount.Id = await _thirdAccountRepository.AddAsync(thirdAccount);
|
|
thirdAccount.Id = await _thirdAccountRepository.AddAsync(thirdAccount);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -337,69 +339,6 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
|
|
var expiredSeconds = jwtOptions.Expired <= 0 ? 3600 : jwtOptions.Expired;
|
|
var expiredSeconds = jwtOptions.Expired <= 0 ? 3600 : jwtOptions.Expired;
|
|
await _cacheAudience.SetAsync(audience.Id, audience, TimeSpan.FromSeconds(expiredSeconds));
|
|
await _cacheAudience.SetAsync(audience.Id, audience, TimeSpan.FromSeconds(expiredSeconds));
|
|
var token = _jwtSecurity.EncodeJwtToken(claims, audience.Ticket);
|
|
var token = _jwtSecurity.EncodeJwtToken(claims, audience.Ticket);
|
|
- if (thirdAccount.PhoneNumber.IsNullOrEmpty())
|
|
|
|
- return new ApiResponse<TokenOutDto>
|
|
|
|
- {
|
|
|
|
- Code = 201,
|
|
|
|
- Message = "请绑定手机号码 '/Identity/third/phone'",
|
|
|
|
- Result = new TokenOutDto(thirdAccount.CitizenType, token),
|
|
|
|
- };
|
|
|
|
- return new ApiResponse<TokenOutDto> {
|
|
|
|
- Code = 0,
|
|
|
|
- Result = new TokenOutDto(thirdAccount.CitizenType, token),
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 获取微信用户手机号码
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="dto"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- /// <exception cref="UserFriendlyException"></exception>
|
|
|
|
- public async Task GetThirdPhoneAsync(ThirdPhoneInDto dto)
|
|
|
|
- {
|
|
|
|
- var thirdAccount = await _thirdAccountRepository.QueryByOpenIdAsync(_sessionContext.OpenId)
|
|
|
|
- ?? throw new UserFriendlyException(401, "请重新登录");
|
|
|
|
-
|
|
|
|
- var thirdDto = dto.Adapt<ThirdTokenDto>();
|
|
|
|
- if (dto.ThirdType == EThirdType.WeChat)
|
|
|
|
- {
|
|
|
|
- thirdDto.AppId = _systemSettingCacheManager.WxOpenAppId;
|
|
|
|
- }
|
|
|
|
- var thirdPhone = await _thirdIdentiyService.GetPhoneNumberAsync(thirdDto);
|
|
|
|
- if (thirdPhone.IsError)
|
|
|
|
- throw new UserFriendlyException(thirdPhone.ErrorCode + ":" + thirdPhone.ErrorMessage);
|
|
|
|
-
|
|
|
|
- thirdAccount.PhoneNumber = thirdPhone.PhoneNumber;
|
|
|
|
- var guider = await _guiderInfoRepository.Queryable()
|
|
|
|
- .Where(m => m.PhoneNumber == thirdAccount.PhoneNumber)
|
|
|
|
- .FirstAsync();
|
|
|
|
- if (guider is not null)
|
|
|
|
- { // 回填网格员信息
|
|
|
|
- thirdAccount.UserId = guider.Id;
|
|
|
|
- thirdAccount.CitizenType = EReadPackUserType.Gukder;
|
|
|
|
- await _thirdAccountRepository.UpdateAsync(thirdAccount);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var citizen = await _citizenRepository.Queryable()
|
|
|
|
- .Where(m => m.PhoneNumber == thirdAccount.PhoneNumber)
|
|
|
|
- .FirstAsync();
|
|
|
|
- if (citizen is not null)
|
|
|
|
- {
|
|
|
|
- thirdAccount.CitizenType = EReadPackUserType.Citizen;
|
|
|
|
- thirdAccount.UserId = citizen.Id;
|
|
|
|
- await _thirdAccountRepository.UpdateAsync(thirdAccount);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- citizen = new Citizen
|
|
|
|
- {
|
|
|
|
- PhoneNumber = thirdAccount.PhoneNumber
|
|
|
|
- };
|
|
|
|
- thirdAccount.UserId = await _citizenRepository.AddAsync(citizen);
|
|
|
|
- thirdAccount.CitizenType = EReadPackUserType.Citizen;
|
|
|
|
- await _thirdAccountRepository.UpdateAsync(thirdAccount);
|
|
|
|
- }
|
|
|
|
|
|
+ return new TokenOutDto(thirdAccount.CitizenType, token);
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+ }
|