AccountController.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Bowin.Common.Cache;
  2. using Bowin.Common.DES;
  3. using Bowin.Common.ServiceToken;
  4. using Bowin.Common.WebModels;
  5. using Microsoft.AspNetCore.Authorization;
  6. using Microsoft.AspNetCore.Mvc;
  7. using OrderSystem.Entity.ViewModel;
  8. using OrderSystem.Services.SystemSetting;
  9. namespace OrderSystem.Web.Controllers.SystemSetting
  10. {
  11. [Route("api/systemsetting/[controller]/[action]")]
  12. [Authorize]
  13. public class AccountController : ControllerBase
  14. {
  15. private IUserService UserService { get; set; }
  16. readonly IDesAccessor DesAccessor;
  17. public AccountController(IUserService userService, IDesAccessor desAccessor)
  18. {
  19. UserService = userService;
  20. this.DesAccessor = desAccessor;
  21. }
  22. [AllowAnonymous]
  23. [HttpPost]
  24. public ResultMessage GetToken([FromBody] DesModel inputObject)
  25. {
  26. var data = this.DesAccessor.DeDesToken(inputObject);
  27. var datas = data.Split('|');
  28. string loginID = datas[0];
  29. string pdmd = datas[1];
  30. string openID = datas.Length == 3 ? datas[2] : "";
  31. /*string verfiyKey = datas[2];
  32. string verfiyCode = datas[3];
  33. if (CacheHelper.Get(verfiyKey)?.ToString() != verfiyCode.ToUpper())
  34. {
  35. CacheHelper.Remove(verfiyKey);
  36. return ResultMessage.GetError("验证码错误,请重新输入。");
  37. }
  38. else
  39. {
  40. CacheHelper.Remove(verfiyKey);
  41. }*/
  42. ResultMessage result = new ResultMessage();
  43. var user = UserService.GetLoginUserById(loginID, pdmd);
  44. var token = JwtHelper.GetToken(() => user, (x => x.UserID));
  45. if (user != null && !string.IsNullOrEmpty(openID))
  46. UserService.UpdateUserOpenID(user.UserID, openID);
  47. return ResultMessage.Success(token);
  48. }
  49. [AllowAnonymous]
  50. [HttpPost]
  51. public ResultMessage GetTokenByOpenID([FromBody] DesModel inputObject)
  52. {
  53. var openID = this.DesAccessor.DeDesToken(inputObject);
  54. ResultMessage result = new ResultMessage();
  55. var user = UserService.GetLoginUserByVxId(openID);
  56. var token = JwtHelper.GetToken(() => user, (x => x.UserID));
  57. return ResultMessage.Success(token);
  58. }
  59. [HttpPost]
  60. public ResultMessage RefreshToken()
  61. {
  62. return ResultMessage.Success(JwtHelper.RefreshToken<LoginUser>());
  63. }
  64. }
  65. }