111
This commit is contained in:
25
Service/Application.Web/Common/ComHelper.cs
Normal file
25
Service/Application.Web/Common/ComHelper.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace Application.Web;
|
||||
|
||||
public class ComHelper
|
||||
{
|
||||
public static string GetClientUserIp(HttpContext context)
|
||||
{
|
||||
var ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
|
||||
if (string.IsNullOrEmpty(ip))
|
||||
{
|
||||
ip = context.Connection.RemoteIpAddress.ToString();
|
||||
ip = ip.Replace("::ffff:", "");
|
||||
}
|
||||
if (ip.Contains(","))
|
||||
{
|
||||
ip = ip.Split(',')[0];
|
||||
}
|
||||
//var ip = context.Request.Cookies["kxUserIp"];
|
||||
//if (string.IsNullOrEmpty(ip))
|
||||
//{
|
||||
// ip = "0.0.0.0";
|
||||
//}
|
||||
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,20 @@
|
||||
return token.Claims["userId"];
|
||||
}
|
||||
}
|
||||
public static string sid
|
||||
public static string accId
|
||||
{
|
||||
get
|
||||
{
|
||||
var token = App.HttpContext.GetTokenInfo();
|
||||
return token.Claims["token"];
|
||||
return token.Claims["accId"];
|
||||
}
|
||||
}
|
||||
public static int areaId
|
||||
{
|
||||
get
|
||||
{
|
||||
var token = App.HttpContext.GetTokenInfo();
|
||||
return Convert.ToInt32(token.Claims["areaId"]) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +154,11 @@ namespace Application.Web.Controllers.Login
|
||||
return PoAction.Message("当前区繁忙,无法进入!");
|
||||
}
|
||||
|
||||
if (areaInfo.opTime > DateTime.Now)
|
||||
{
|
||||
return PoAction.Message("暂未开放本区服!");
|
||||
}
|
||||
|
||||
//判断是否已经注册
|
||||
var userData = await _userService.GetUserDataByAccId(accInfo.accId);
|
||||
if (userData.Any(it => it.areaId == area))
|
||||
@@ -170,7 +175,7 @@ namespace Application.Web.Controllers.Login
|
||||
Dictionary<string, object> loadData = new Dictionary<string, object>();
|
||||
loadData.Add("userId", userInfo.userId);
|
||||
loadData.Add("accId", userInfo.accId);
|
||||
|
||||
loadData.Add("areaId", userInfo.areaId);
|
||||
string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString();
|
||||
string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString();
|
||||
string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString();
|
||||
@@ -222,7 +227,7 @@ namespace Application.Web.Controllers.Login
|
||||
Dictionary<string, object> loadData = new Dictionary<string, object>();
|
||||
loadData.Add("userId", userInfo.userId);
|
||||
loadData.Add("accId", userInfo.accId);
|
||||
|
||||
loadData.Add("areaId", userInfo.areaId);
|
||||
string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString();
|
||||
string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString();
|
||||
string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString();
|
||||
@@ -238,16 +243,18 @@ namespace Application.Web.Controllers.Login
|
||||
{
|
||||
return PoAction.Message("刷新失败");
|
||||
}
|
||||
|
||||
|
||||
string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString();
|
||||
string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString();
|
||||
string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString();
|
||||
var data = JwtHelper.GetTokenPload(parms.token,Key);
|
||||
|
||||
string accId = string.Empty;
|
||||
if (data.TryGetValue("accId", out object _accId))
|
||||
var tokenData = await JwtTool.GetJwtData(parms.token, Key, "accId");
|
||||
if (tokenData != null)
|
||||
{
|
||||
accId = _accId.ToString();
|
||||
accId = tokenData.ToString();
|
||||
}
|
||||
|
||||
var userInfo = await _userService.GetUserInfoByToken(parms.refToken);
|
||||
if (userInfo == null)
|
||||
{
|
||||
@@ -258,12 +265,14 @@ namespace Application.Web.Controllers.Login
|
||||
{
|
||||
return PoAction.Message("刷新失败,数据信息不合法!");
|
||||
}
|
||||
|
||||
Dictionary<string, object> loadData = new Dictionary<string, object>();
|
||||
loadData.Add("userId", userInfo.userId);
|
||||
loadData.Add("accId", userInfo.accId);
|
||||
loadData.Add("areaId", userInfo.areaId);
|
||||
string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, TokenConfig.TokenTime);
|
||||
return PoAction.Ok(new
|
||||
{ token = token, refToken = userInfo.token, userId = userInfo.userId });
|
||||
{ token = token, refToken = userInfo.token, userId = userInfo.userId });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -284,6 +293,7 @@ namespace Application.Web.Controllers.Login
|
||||
{
|
||||
return PoAction.Message("昵称需要1-12字符之间哦!");
|
||||
}
|
||||
|
||||
string sex = parms.sex == 0 ? "女" : "男";
|
||||
string userId = StateHelper.userId;
|
||||
var userInfo = await _userService.GetUserInfoByUserId(userId);
|
||||
|
||||
61
Service/Application.Web/Controllers/Map/MapController.cs
Normal file
61
Service/Application.Web/Controllers/Map/MapController.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.Map;
|
||||
|
||||
/// <summary>
|
||||
/// 地图接口
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "Map")]
|
||||
[Route("Map/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class MapController : ControllerBase
|
||||
{
|
||||
private readonly IUnitUserService _userService;
|
||||
private readonly IGameMapService _mapService;
|
||||
|
||||
public MapController(IUnitUserService userService, IGameMapService mapService)
|
||||
{
|
||||
_userService = userService;
|
||||
_mapService = mapService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取地图主页信息
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetMapData(string? map)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
var onMap = await _mapService.GetUserOnMap(userId);
|
||||
game_city_map mapInfo = new game_city_map();
|
||||
if (string.IsNullOrEmpty(map))
|
||||
{
|
||||
mapInfo = await _mapService.GetMapInfo(onMap.mapId);
|
||||
}
|
||||
else
|
||||
{
|
||||
mapInfo = await _mapService.GetMapInfo(map);
|
||||
}
|
||||
|
||||
//NPC信息
|
||||
|
||||
var npcData = await _mapService.GetMapNpc(mapInfo.mapId);
|
||||
npcData = npcData.FindAll(it => GameTool.AreaVerify(StateHelper.areaId,it.areaId));
|
||||
//城市信息
|
||||
var cityInfo = await _mapService.GetCityInfo((int)mapInfo.cityId);
|
||||
|
||||
#region 更新在线
|
||||
|
||||
string ip = ComHelper.GetClientUserIp(HttpContext);
|
||||
await _mapService.UpdateUserOnMap(userId, ip, mapInfo.mapId);
|
||||
|
||||
#endregion
|
||||
|
||||
object ret = new { mapInfo, cityInfo, npcData };
|
||||
|
||||
return PoAction.Ok(ret);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,12 @@ groups.Add("User", new OpenApiInfo
|
||||
Version = "v1",
|
||||
Description = "航海时代用户相关接口。",
|
||||
});
|
||||
groups.Add("Map", new OpenApiInfo
|
||||
{
|
||||
Title = "用户地图文档",
|
||||
Version = "v1",
|
||||
Description = "航海时代用户地图相关接口。",
|
||||
});
|
||||
|
||||
builder.Services.InjectJwt(builder.Configuration, new OpenApiInfo
|
||||
{
|
||||
@@ -94,7 +100,8 @@ if (app.Environment.IsDevelopment())
|
||||
#region 测试swagger配置
|
||||
app.UseJwtSwagger("swagger", "航海时代接口文档",new List<JwtGroupConfig> {
|
||||
new JwtGroupConfig(){ groupId="Login", groupName="登录接口文档"},
|
||||
new JwtGroupConfig(){ groupId="User", groupName="用户接口文档"}
|
||||
new JwtGroupConfig(){ groupId="User", groupName="用户接口文档"},
|
||||
new JwtGroupConfig(){ groupId="Map", groupName="用户地图文档"}
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user