This commit is contained in:
Putoo
2026-05-18 18:12:21 +08:00
parent 571877970b
commit 2037d1e577
20 changed files with 555 additions and 77 deletions

View File

@@ -14,9 +14,15 @@ namespace Application.Web.Controllers.Login
public class LoginController : ControllerBase
{
private readonly IGameAccountService _accountService;
public LoginController(IGameAccountService accountService)
private readonly IAreaService _areaService;
private readonly IUnitUserService _userService;
public LoginController(IGameAccountService accountService, IAreaService areaService,
IUnitUserService userService)
{
_accountService = accountService;
_areaService = areaService;
_userService = userService;
}
/// <summary>
@@ -27,8 +33,6 @@ namespace Application.Web.Controllers.Login
[HttpPost]
public async Task<IPoAction> Login([FromBody] LoginParms parms)
{
return PoAction.Ok(parms.code);
}
@@ -38,14 +42,15 @@ namespace Application.Web.Controllers.Login
/// <param name="code"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> TwLogin( string code)
public async Task<IPoAction> TwLogin(string code)
{
if (string.IsNullOrEmpty(code))
{
return PoAction.Message("code值错误!");
}
AutoLogin login = new AutoLogin();
var loginInfo = await login.TwLogin(code);
var loginInfo = await login.TwLogin(code);
if (loginInfo.code == 0)
{
dynamic twInfo = JsonConvert.DeserializeObject<dynamic>(loginInfo.data.ToString());
@@ -54,14 +59,14 @@ namespace Application.Web.Controllers.Login
var accInfo = await _accountService.GetAccInfoByOpenId(openId);
if (accInfo == null)
{
var userData = await _accountService.Regist("", nick, "", "", openId);
var userData = await _accountService.Regist("", nick, "", "", openId);
if (userData == null)
{
return PoAction.Message("登录失败,请联系客服!");
}
else
{
object ret =new { token = userData.token };
object ret = new { token = userData.token };
return PoAction.Ok(ret);
}
}
@@ -73,7 +78,7 @@ namespace Application.Web.Controllers.Login
}
else
{
object ret =new { token = accInfo.token };
object ret = new { token = accInfo.token };
return PoAction.Ok(ret);
}
}
@@ -112,5 +117,60 @@ namespace Application.Web.Controllers.Login
return PoAction.Message("退出失败,请稍后尝试!");
}
}
/// <summary>
/// 注册基础账号信息
/// </summary>
/// <param name="sid"></param>
/// <param name="area"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> Register(string sid, int area)
{
if (string.IsNullOrEmpty(sid))
{
return PoAction.Message("未登录账号!");
}
var accInfo = await _accountService.GetAccInfoByToken(sid);
if (accInfo == null)
{
return PoAction.Message("未登录账号!");
}
var areaInfo = await _areaService.GetAreaInfo(area);
if (areaInfo == null)
{
return PoAction.Message("区服不存在!");
}
if (areaInfo.status != 1)
{
return PoAction.Message("当前区繁忙,无法进入!");
}
//判断是否已经注册
var userData = await _userService.GetUserDataByAccId(accInfo.accId);
if (userData.Any(it => it.areaId == area))
{
return PoAction.Message("该区已存在角色!");
}
var userInfo = await _userService.Register(areaInfo.areaId, accInfo.accId);
if (userInfo == null)
{
return PoAction.Message("注册失败,请稍后尝试!");
}
Dictionary<string, object> loadData = new Dictionary<string, object>();
loadData.Add("userId", userInfo.userId);
loadData.Add("accId", userInfo.accId);
string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString();
string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString();
string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString();
string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, 300);
return PoAction.Ok(new { token = token, refToken = userInfo.token, userId = userInfo.userId });
}
}
}

View File

@@ -13,12 +13,14 @@ namespace Application.Web.Controllers.Pub
private readonly IAreaService _areaService;
private readonly INoticeService _noticeService;
private readonly IGameAccountService _accountService;
private readonly IUnitUserService _userService;
public PubController(IAreaService areaService, INoticeService noticeService,IGameAccountService accountService)
public PubController(IAreaService areaService, INoticeService noticeService, IGameAccountService accountService,IUnitUserService userService)
{
_areaService = areaService;
_noticeService = noticeService;
_accountService = accountService;
_userService = userService;
}
/// <summary>
@@ -31,20 +33,27 @@ namespace Application.Web.Controllers.Pub
{
bool isOnline = false;
game_account account = new game_account();
List<unit_user> userData = new List<unit_user>();
if (!string.IsNullOrEmpty(sid))
{
account = await _accountService.GetAccInfoByToken(sid);
if (account != null)
{
isOnline = true;
userData = await _userService.GetUserDataByAccId(account.accId);
}
}
var areaData = await _areaService.GetAreaData();
var notice = await _noticeService.GetNoticeDataByTake(5);
foreach (var _user in userData)
{
areaData.RemoveAll(it => it.areaId == _user.areaId);
}
var notice = await _noticeService.GetNoticeDataByTake(5);
int OnCount = 100;
return PoAction.Ok(new { area = areaData, notice, isOnline, onCount = OnCount,account });
return PoAction.Ok(new { area = areaData, notice, isOnline, onCount = OnCount, account,userData });
}
/// <summary>
@@ -54,11 +63,28 @@ namespace Application.Web.Controllers.Pub
/// <param name="limit"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetNoticeData(int page,int limit)
public async Task<IPoAction> GetNoticeData(int page, int limit)
{
RefAsync<int> total = 0;
var data = await _noticeService.GetNoticeData(page, limit, total);
return PoAction.Ok(new { data, total=total.Value });
return PoAction.Ok(new { data, total = total.Value });
}
/// <summary>
/// 获取公告详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetNoticeInfo(string id)
{
var data = await _noticeService.GetNoticeInfo(id);
if (data == null)
{
return PoAction.Message("公告不存在!");
}
data.sign = data.sign.Replace("[Br]", "<br />");
return PoAction.Ok(data);
}
}
}