11
This commit is contained in:
21
Service/Application.Web/Common/DateTimeJsonConverter.cs
Normal file
21
Service/Application.Web/Common/DateTimeJsonConverter.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Application.Web;
|
||||
|
||||
public class DateTimeJsonConverter: JsonConverter<DateTime>
|
||||
{
|
||||
public override DateTime Read(
|
||||
ref Utf8JsonReader reader,
|
||||
Type typeToConvert,
|
||||
JsonSerializerOptions options)
|
||||
{
|
||||
return DateTime.ParseExact(reader.GetString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,8 +53,13 @@ builder.Services.InjectTimer(services =>
|
||||
builder.Logging.InjectLog();
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers().AddJsonOptions(option =>
|
||||
{
|
||||
option.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter());
|
||||
option.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
|
||||
option.JsonSerializerOptions.MaxDepth =int.MaxValue;
|
||||
});
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
|
||||
#region 配置跨域处理,允许所有来源
|
||||
|
||||
Reference in New Issue
Block a user