|
|
@ -16,6 +16,8 @@ using Furion.DynamicApiController;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using GDZZ.Application.Help;
|
|
|
|
using GDZZ.Application.Help;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
|
|
using Mapster;
|
|
|
|
|
|
|
|
using GDZZ.Core.Service;
|
|
|
|
|
|
|
|
|
|
|
|
namespace GDZZ.Application.Service.Auth
|
|
|
|
namespace GDZZ.Application.Service.Auth
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -27,7 +29,7 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRep; // 用户表仓储
|
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRep; // 用户表仓储
|
|
|
|
private readonly SqlSugarRepository<SysTenant> _sysTenantRep; //租户仓储
|
|
|
|
private readonly SqlSugarRepository<SysTenant> _sysTenantRep; //租户仓储
|
|
|
|
private readonly SqlSugarRepository<SeIF> Self; //职业仓储
|
|
|
|
private readonly SqlSugarRepository<SeIF> Self; //职业仓储
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<Company> CompanyRep;
|
|
|
|
private readonly SqlSugarRepository<MiniRecharge> rechargeRep; //充值仓储
|
|
|
|
private readonly SqlSugarRepository<MiniRecharge> rechargeRep; //充值仓储
|
|
|
|
private readonly SqlSugarRepository<MiniPayTake> payTakeRep; //支付仓储
|
|
|
|
private readonly SqlSugarRepository<MiniPayTake> payTakeRep; //支付仓储
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
@ -51,11 +53,14 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
SqlSugarRepository<SysTenant> sysTenantRep,
|
|
|
|
SqlSugarRepository<SysTenant> sysTenantRep,
|
|
|
|
SqlSugarRepository<SysUser> sysUserRep,
|
|
|
|
SqlSugarRepository<SysUser> sysUserRep,
|
|
|
|
SqlSugarRepository<SeIF> Self,
|
|
|
|
SqlSugarRepository<SeIF> Self,
|
|
|
|
|
|
|
|
SqlSugarRepository<Company> CompanyRep,
|
|
|
|
|
|
|
|
SqlSugarRepository<MiniPayTake> payTakeRep,
|
|
|
|
ICacheService cacheService,
|
|
|
|
ICacheService cacheService,
|
|
|
|
WechatOAuth wechatOAuth,
|
|
|
|
WechatOAuth wechatOAuth,
|
|
|
|
IEventPublisher eventPublisher,
|
|
|
|
IEventPublisher eventPublisher,
|
|
|
|
IHttpContextAccessor httpContextAccessor)
|
|
|
|
IHttpContextAccessor httpContextAccessor)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
this.CompanyRep= CompanyRep;
|
|
|
|
this._eventPublisher= eventPublisher;
|
|
|
|
this._eventPublisher= eventPublisher;
|
|
|
|
this._sysUserRep = sysUserRep;
|
|
|
|
this._sysUserRep = sysUserRep;
|
|
|
|
this._sysTenantRep = sysTenantRep;
|
|
|
|
this._sysTenantRep = sysTenantRep;
|
|
|
@ -63,6 +68,7 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
this._httpContextAccessor = httpContextAccessor;
|
|
|
|
this._httpContextAccessor = httpContextAccessor;
|
|
|
|
this.cacheService= cacheService;
|
|
|
|
this.cacheService= cacheService;
|
|
|
|
this.Self = Self;
|
|
|
|
this.Self = Self;
|
|
|
|
|
|
|
|
this.payTakeRep = payTakeRep;
|
|
|
|
_wechatOAuth = wechatOAuth;
|
|
|
|
_wechatOAuth = wechatOAuth;
|
|
|
|
_oauthConfig = options.Value.Wechat;
|
|
|
|
_oauthConfig = options.Value.Wechat;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -76,9 +82,11 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
public async Task<AuthUserOut> SignInAsync(PhoneModel phoneModel)
|
|
|
|
public async Task<AuthUserOut> SignInAsync(PhoneModel phoneModel)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AuthUserOut authUserOut = new AuthUserOut();
|
|
|
|
AuthUserOut authUserOut = new AuthUserOut();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Company company = new Company();
|
|
|
|
|
|
|
|
|
|
|
|
//读取凭证
|
|
|
|
//读取凭证
|
|
|
|
var tokenModel = await this._wechatOAuth.GetAccessTokenAsync(phoneModel.code);
|
|
|
|
var tokenModel = await this._wechatOAuth.GetAccessTokenAsync(phoneModel.code);
|
|
|
|
|
|
|
|
|
|
|
|
//解析电话
|
|
|
|
//解析电话
|
|
|
|
var phoneInfo = MiniProgramUtil.AESDecrypt(phoneModel.encryptedDataStr, tokenModel.SessionKey, phoneModel.iv);
|
|
|
|
var phoneInfo = MiniProgramUtil.AESDecrypt(phoneModel.encryptedDataStr, tokenModel.SessionKey, phoneModel.iv);
|
|
|
|
|
|
|
|
|
|
|
@ -87,6 +95,14 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
.First(x => x.Phone == phoneInfo.PhoneNumber);
|
|
|
|
.First(x => x.Phone == phoneInfo.PhoneNumber);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var wxUser = await this.Baseuser.AsQueryable()
|
|
|
|
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
|
|
|
|
.Where(x => x.OpenID == tokenModel.OpenId).SingleAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//账号不存在 生成系统账号
|
|
|
|
if (sysUser.IsEmpty())
|
|
|
|
if (sysUser.IsEmpty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sysUser = await this._sysUserRep.InsertReturnEntityAsync(new SysUser()
|
|
|
|
sysUser = await this._sysUserRep.InsertReturnEntityAsync(new SysUser()
|
|
|
@ -111,10 +127,9 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var wxUser = await this.Baseuser.AsQueryable()
|
|
|
|
//区分不同类型账号
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
if (phoneModel.logInType ==(int)UserEnum.JOB)
|
|
|
|
.Where(x => x.OpenID == tokenModel.OpenId).SingleAsync();
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (wxUser.IsEmpty())
|
|
|
|
if (wxUser.IsEmpty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wxUser = await this.Baseuser.InsertReturnEntityAsync(new BaseUser()
|
|
|
|
wxUser = await this.Baseuser.InsertReturnEntityAsync(new BaseUser()
|
|
|
@ -124,17 +139,31 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
CreatedTime = DateTime.Now,
|
|
|
|
CreatedTime = DateTime.Now,
|
|
|
|
CreatedUserName = sysUser.Name,
|
|
|
|
CreatedUserName = sysUser.Name,
|
|
|
|
AvatarUrl = "https://gdzongzhi.com/assets/img/logo.png",
|
|
|
|
AvatarUrl = "https://gdzongzhi.com/assets/img/logo.png",
|
|
|
|
Status = CommonStatus.ENABLE,
|
|
|
|
Status =(int)CommonStatus.ENABLE,
|
|
|
|
OpenID = tokenModel.OpenId,
|
|
|
|
OpenID = tokenModel.OpenId,
|
|
|
|
TenantId = 392820661919813,
|
|
|
|
TenantId = 392820661919813,
|
|
|
|
Type = UserEnum.JOB,
|
|
|
|
Type = (int)UserEnum.JOB,
|
|
|
|
UserName = phoneInfo.PhoneNumber,
|
|
|
|
UserName = phoneInfo.PhoneNumber,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//如果是企业账号,应该是绑定了企业租户信息
|
|
|
|
|
|
|
|
if (wxUser.IsEmpty()|| wxUser.CompanyID.IsNullOrZero())
|
|
|
|
|
|
|
|
throw Oops.Oh(ErrorCode.xg1002);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取公司信息
|
|
|
|
|
|
|
|
company = await this.CompanyRep.SingleAsync(x=>x.Id == wxUser.CompanyID);
|
|
|
|
|
|
|
|
authUserOut.companyDto = company.Adapt<CompanyDto>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
if (wxUser.IsEmpty() || sysUser.IsEmpty())
|
|
|
|
if (wxUser.IsEmpty() || sysUser.IsEmpty())
|
|
|
|
throw Oops.Oh(ErrorCode.xg1002);
|
|
|
|
throw Oops.Oh(ErrorCode.xg1002);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var Self = await this.Self.FirstOrDefaultAsync(x => x.CreatedUserId == sysUser.Id);
|
|
|
|
var Self = await this.Self.FirstOrDefaultAsync(x => x.CreatedUserId == sysUser.Id);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取加密后的密码
|
|
|
|
// 获取加密后的密码
|
|
|
@ -143,13 +172,13 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
// 验证账号是否被冻结
|
|
|
|
// 验证账号是否被冻结
|
|
|
|
if (sysUser.Status == CommonStatus.DISABLE)
|
|
|
|
if (sysUser.Status == CommonStatus.DISABLE)
|
|
|
|
throw Oops.Oh(ErrorCode.D1017);
|
|
|
|
throw Oops.Oh(ErrorCode.D1017);
|
|
|
|
|
|
|
|
|
|
|
|
//获取对应租户
|
|
|
|
//获取对应租户
|
|
|
|
var tenant = this._sysTenantRep.Single(sysUser.TenantId);
|
|
|
|
var tenant = this._sysTenantRep.Single(sysUser.TenantId);
|
|
|
|
|
|
|
|
|
|
|
|
if (tenant.IsNullOrZero())
|
|
|
|
if (tenant.IsNullOrZero())
|
|
|
|
throw Oops.Oh(ErrorCode.F1001);
|
|
|
|
throw Oops.Oh(ErrorCode.F1001);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 生成Token令牌
|
|
|
|
// 生成Token令牌
|
|
|
|
authUserOut.Token = JWTEncryption.Encrypt(new Dictionary<string, object>
|
|
|
|
authUserOut.Token = JWTEncryption.Encrypt(new Dictionary<string, object>
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -180,9 +209,11 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
authUserOut.Sex = sysUser.Sex;
|
|
|
|
authUserOut.Sex = sysUser.Sex;
|
|
|
|
authUserOut.UserId = sysUser.Id;
|
|
|
|
authUserOut.UserId = sysUser.Id;
|
|
|
|
authUserOut.UserName = sysUser.Name;
|
|
|
|
authUserOut.UserName = sysUser.Name;
|
|
|
|
authUserOut.Self = Self.IsEmpty() ? "未填写" : Self.Name;
|
|
|
|
authUserOut.Self = Self.IsEmpty() ? null : Self.Name;
|
|
|
|
authUserOut.Type = UserEnum.JOB;
|
|
|
|
authUserOut.Type = (UserEnum)wxUser.Type;
|
|
|
|
authUserOut.OpenID = tokenModel.OpenId;
|
|
|
|
authUserOut.OpenID = tokenModel.OpenId;
|
|
|
|
|
|
|
|
authUserOut.Tenant = tenant.Adapt<TenantOutput>();
|
|
|
|
|
|
|
|
authUserOut.Describe = wxUser.Describe;
|
|
|
|
|
|
|
|
|
|
|
|
await this.cacheService.SetUserInfoAsync(authUserOut, authUserOut.UserId);
|
|
|
|
await this.cacheService.SetUserInfoAsync(authUserOut, authUserOut.UserId);
|
|
|
|
return authUserOut;
|
|
|
|
return authUserOut;
|
|
|
@ -200,17 +231,11 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
return await this.cacheService.GetUserInfoAsync(UserManager.UserId);
|
|
|
|
return await this.cacheService.GetUserInfoAsync(UserManager.UserId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 微信支付
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="productId"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[HttpGet("Mini/WxPay")]
|
|
|
|
|
|
|
|
public async Task<dynamic> WxPay(AuthUserInput authUserInput)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|