|
@@ -8,6 +8,7 @@ using Datory.Utils;
|
|
|
using GxPress.Api.Tools;
|
|
|
using GxPress.Auth;
|
|
|
using GxPress.Common.Exceptions;
|
|
|
+using GxPress.Common.Tools;
|
|
|
using GxPress.Common.Validation;
|
|
|
using GxPress.Entity;
|
|
|
using GxPress.EnumConst;
|
|
@@ -183,7 +184,7 @@ namespace GxPress.Api.AppControllers
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("sendSmsCode")]
|
|
|
[AllowAnonymous]
|
|
|
- public async Task<bool> SendSmsCode([FromQuery] [Required] [Mobile] string phone)
|
|
|
+ public async Task<bool> SendSmsCode([FromQuery][Required][Mobile] string phone)
|
|
|
{
|
|
|
var user = await _userRepository.GetByPhoneAsync(phone);
|
|
|
|
|
@@ -196,19 +197,23 @@ namespace GxPress.Api.AppControllers
|
|
|
//TODO 短信验证码发送
|
|
|
//return await _smsService.
|
|
|
//SendValidationCodeAsync(phone);
|
|
|
+ //发送短信
|
|
|
var key = $"login:{phone}";
|
|
|
- //if (await RedisHelper.ExistsAsync(key)) throw new BusinessException("发送太频繁");
|
|
|
- var code = "180606";
|
|
|
- _logger.LogInformation($"{key}", phone, code);
|
|
|
- var codeByte = Encoding.UTF8.GetBytes(Utilities.JsonSerialize(code));
|
|
|
- await _cache.SetAsync($"{key}", codeByte, new DistributedCacheEntryOptions
|
|
|
+ var code = await _cache.GetStringAsync(key);
|
|
|
+ if (!string.IsNullOrEmpty(code))
|
|
|
+ throw new BusinessException("请求太频繁!");
|
|
|
+ code = RandomGenerator.GetNumberString(6);
|
|
|
+ if (Common.Sms.MasSms.SendSms(phone, code))
|
|
|
{
|
|
|
- AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(300)
|
|
|
- });
|
|
|
- // var result = await RedisHelper.SetAsync(key, code, 300);
|
|
|
- // if (result == false)
|
|
|
- // throw new BusinessException("发送失败");
|
|
|
- return true;
|
|
|
+ _logger.LogInformation("{phone}验证码:{code}", phone, code);
|
|
|
+ var codeByte = Encoding.UTF8.GetBytes(Utilities.JsonSerialize(code));
|
|
|
+ await _cache.SetAsync($"{key}", codeByte, new DistributedCacheEntryOptions
|
|
|
+ {
|
|
|
+ AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(60)
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -217,7 +222,7 @@ namespace GxPress.Api.AppControllers
|
|
|
/// <param name="phone"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("send-sms-code")]
|
|
|
- public async Task<bool> SendSmsCodeReplace([FromQuery] [Required] [Mobile] string phone)
|
|
|
+ public async Task<bool> SendSmsCodeReplace([FromQuery][Required][Mobile] string phone)
|
|
|
{
|
|
|
var user = await _userRepository.GetByPhoneAsync(phone);
|
|
|
if (user != null)
|