using LiveForum.Code.Base; using LiveForum.Code.JwtInfrastructure; using LiveForum.IService.RealName; using LiveForum.Model.Dto.RealName; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace LiveForum.WebApi.Controllers { /// /// 实名认证接口 /// [Route("api/Auth/[action]")] [ApiController] [Authorize] public class RealNameController : ControllerBase { private readonly IRealNameService _realNameService; private readonly JwtUserInfoModel _userInfo; public RealNameController(IRealNameService realNameService, JwtUserInfoModel userInfo) { _realNameService = realNameService; _userInfo = userInfo; } /// /// 检查实名认证状态 /// [HttpGet] public async Task> RealNameStatus() { var userId = long.Parse(_userInfo.UserName); var status = await _realNameService.CheckStatusAsync(userId); return new BaseResponse(status); } /// /// 实名认证 /// [HttpPost] public async Task> RealNameVerify([FromBody] RealNameVerifyReq req) { if (req == null || string.IsNullOrWhiteSpace(req.RealName) || string.IsNullOrWhiteSpace(req.IdCardNumber)) { return new BaseResponse(ResponseCode.Error, "请输入姓名和身份证号"); } if (req.IdCardNumber.Length != 18) { return new BaseResponse(ResponseCode.Error, "请输入18位身份证号"); } var userId = long.Parse(_userInfo.UserName); var clientIp = HttpContext.Connection.RemoteIpAddress?.ToString(); var result = await _realNameService.VerifyAsync(userId, req.RealName, req.IdCardNumber, clientIp); if (result == "实名认证成功") { return new BaseResponse(result); } return new BaseResponse(ResponseCode.Error, result); } } }