using Bowin.Common.Cache; using Bowin.Common.DES; using Bowin.Common.ServiceToken; using Bowin.Common.WebModels; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OrderSystem.Entity.ViewModel; using OrderSystem.Services.SystemSetting; namespace OrderSystem.Web.Controllers.SystemSetting { [Route("api/systemsetting/[controller]/[action]")] [Authorize] public class AccountController : ControllerBase { private IUserService UserService { get; set; } readonly IDesAccessor DesAccessor; public AccountController(IUserService userService, IDesAccessor desAccessor) { UserService = userService; this.DesAccessor = desAccessor; } [AllowAnonymous] [HttpPost] public ResultMessage GetToken([FromBody] DesModel inputObject) { var data = this.DesAccessor.DeDesToken(inputObject); var datas = data.Split('|'); string loginID = datas[0]; string pdmd = datas[1]; string openID = datas.Length == 3 ? datas[2] : ""; /*string verfiyKey = datas[2]; string verfiyCode = datas[3]; if (CacheHelper.Get(verfiyKey)?.ToString() != verfiyCode.ToUpper()) { CacheHelper.Remove(verfiyKey); return ResultMessage.GetError("验证码错误,请重新输入。"); } else { CacheHelper.Remove(verfiyKey); }*/ ResultMessage result = new ResultMessage(); var user = UserService.GetLoginUserById(loginID, pdmd); var token = JwtHelper.GetToken(() => user, (x => x.UserID)); if (user != null && !string.IsNullOrEmpty(openID)) UserService.UpdateUserOpenID(user.UserID, openID); return ResultMessage.Success(token); } [AllowAnonymous] [HttpPost] public ResultMessage GetTokenByOpenID([FromBody] DesModel inputObject) { var openID = this.DesAccessor.DeDesToken(inputObject); ResultMessage result = new ResultMessage(); var user = UserService.GetLoginUserByVxId(openID); var token = JwtHelper.GetToken(() => user, (x => x.UserID)); return ResultMessage.Success(token); } [HttpPost] public ResultMessage RefreshToken() { return ResultMessage.Success(JwtHelper.RefreshToken()); } } }