using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using YuanXuan.IM.Common.Dtos.LoginMobile; using YuanXuan.IM.Common.Response; namespace YuanXuan.IM.Api.Controllers { /// /// 自定义基础Api控制器 /// [Authorize] [ApiController] public class BaseApiController : ControllerBase { /// /// Api版本前缀 /// protected const string RoutePrefix = "api/v{version:apiVersion}"; public MobileTokenInfo ZereUser => GetTokenInfo(); private MobileTokenInfo GetTokenInfo() { return new MobileTokenInfo { UserName = HttpContext?.User?.FindFirst("UserName")?.Value, UserId = HttpContext?.User?.FindFirst("UserId")?.Value, Jwt_id = HttpContext?.User?.FindFirst("Jwt_id")?.Value, }; } /// /// 返回成功结果 /// /// 数据 /// protected IActionResult Success(object data = null) { return Ok(new BaseResponse(200, "success", data)); } /// /// 返回失败结果 /// /// 错误信息 /// protected IActionResult Fail(string message) { return BadRequest(new BaseResponse(400, message)); } } }