This commit is contained in:
陈淳
2023-04-19 18:07:57 +08:00
parent a93e65df0a
commit 8ed1c958af

View File

@@ -39,7 +39,7 @@ namespace Yi.Furion.Application.Rbac.SignalRHub
public override Task OnConnectedAsync()
{
var name = _currentUser.UserName;
var loginUser = GetLoginLogInfo(_httpContext);
var loginUser = _httpContext.GetLoginLogInfo();
var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId);
//判断用户是否存在,否则添加集合
if (!user)
@@ -89,46 +89,5 @@ namespace Yi.Furion.Application.Rbac.SignalRHub
await Clients.All.SendAsync("ReceiveAllInfo", test);
}
/// <summary>
/// 获取客户端信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private static ClientInfo GetClientInfo(HttpContext context)
{
var str = context.GetUserAgent();
var uaParser = Parser.GetDefault();
ClientInfo c = uaParser.Parse(str);
return c;
}
/// <summary>
/// 记录用户登陆信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private static LoginLogEntity GetLoginLogInfo(HttpContext context)
{
var ipAddr = context.GetClientIp();
IpInfo location;
if (ipAddr == "127.0.0.1")
{
location = new IpInfo() { Province = "本地", City = "本机" };
}
else
{
location = IpTool.Search(ipAddr);
}
ClientInfo clientInfo = GetClientInfo(context);
LoginLogEntity entity = new()
{
Browser = clientInfo.Device.Family,
Os = clientInfo.OS.ToString(),
LoginIp = ipAddr,
LoginLocation = location.Province + "-" + location.City
};
return entity;
}
}
}