VerificationCodeController.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using GxPress.Service.Interface.VerificationCode;
  4. using System.Threading.Tasks;
  5. using GxPress.Auth;
  6. using GxPress.Request.App.VerificationCode;
  7. namespace GxPress.Api.AppControllers
  8. {
  9. /// <summary>
  10. /// 收藏上传验证码
  11. /// </summary>
  12. [Route("api/app/verification-code")]
  13. [ApiController]
  14. [Authorize]
  15. public partial class VerificationCodeController : ControllerBase
  16. {
  17. private readonly IVerificationCodeService verificationCodeService;
  18. private readonly ILoginContext _loginContext;
  19. public VerificationCodeController(IVerificationCodeService verificationCodeService, ILoginContext loginContext)
  20. {
  21. this.verificationCodeService = verificationCodeService;
  22. _loginContext = loginContext;
  23. }
  24. /// <summary>
  25. /// 生成验证码
  26. /// </summary>
  27. /// <returns></returns>
  28. [HttpPost("send-code")]
  29. public async Task<string> GetCodeAsync()
  30. {
  31. return await verificationCodeService.GetCodeAsync(_loginContext.AccountId);
  32. }
  33. /// <summary>
  34. /// 生成验证码
  35. /// </summary>
  36. /// <returns></returns>
  37. [HttpPost("app-send-code")]
  38. public async Task<VerificationDto> GetAppCodeAsync()
  39. {
  40. var code = await verificationCodeService.GetCodeAsync(_loginContext.AccountId);
  41. var result = new VerificationDto();
  42. result.Code = code;
  43. var serviceUrl = GxPress.Common.Tools.ConfigHelper.GetValue("ServiceAddress:AddressUrlDownload");
  44. result.ServiceUrl = $"{serviceUrl}/mobile/pcupload";
  45. return result;
  46. }
  47. /// <summary>
  48. ///验证验证码码
  49. /// </summary>
  50. /// <returns></returns>
  51. [HttpPost("confirmation-code")]
  52. [AllowAnonymous]
  53. public async Task<bool> ConfirmationCodeAsync(VerificationCodeRequest request)
  54. {
  55. //request.UserId=_loginContext.AccountId;
  56. return await verificationCodeService.ConfirmationCodeAsync(request);
  57. }
  58. /// <summary>
  59. /// 持久连接验证码
  60. /// </summary>
  61. /// <returns></returns>
  62. [HttpPost("Lasting-confirmation-code")]
  63. [AllowAnonymous]
  64. public async Task<bool> LastingConfirmationCode(VerificationCodeRequest request)
  65. {
  66. return await verificationCodeService.LastingConfirmationCodeAsync(request);
  67. }
  68. }
  69. }