Browse Source

短信

master
DESKTOP-G961P6V\Zhh 1 year ago
parent
commit
e6cdeafe47
  1. 5
      src/Shentun.WebPeis.Application.Contracts/Persons/CreatePersonDto.cs
  2. 11
      src/Shentun.WebPeis.Application.Contracts/Persons/SmsVerifyCodeDto.cs
  3. 37
      src/Shentun.WebPeis.Application/Persons/PersonAppService.cs
  4. 2
      src/Shentun.WebPeis.EntityFrameworkCore/Configures/AppointScheduleTemplateTimeConfigure.cs

5
src/Shentun.WebPeis.Application.Contracts/Persons/CreatePersonDto.cs

@ -93,5 +93,10 @@ namespace Shentun.WebPeis.Persons
/// </summary>
public string SmsVerifyCode { get; set; }
/// <summary>
/// 短信校验码键
/// </summary>
public string SmsVerifyCodeKey { get; set;}
}
}

11
src/Shentun.WebPeis.Application.Contracts/Persons/SmsVerifyCodeDto.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.WebPeis.Persons
{
public class SmsVerifyCodeDto
{
public string SmsVerifyCodeKey { get; set; }
}
}

37
src/Shentun.WebPeis.Application/Persons/PersonAppService.cs

@ -163,9 +163,14 @@ namespace Shentun.WebPeis.Persons
throw new UserFriendlyException("手机号码必须为11位");
}
if (_cache.Get(CacheKeys.SmsKey + input.MobileTelephone) != input.SmsVerifyCode)
if (string.IsNullOrWhiteSpace(input.SmsVerifyCodeKey))
{
throw new UserFriendlyException("无效的短信校验码");
throw new UserFriendlyException("短信校验码键不能为空");
}
if (_cache.Get(input.SmsVerifyCodeKey) != input.SmsVerifyCode)
{
throw new UserFriendlyException("无效的短信校验码或已过期");
}
var person = await _repository.FindAsync(o => o.IdNo == input.IdNo);
@ -247,9 +252,14 @@ namespace Shentun.WebPeis.Persons
throw new UserFriendlyException("亲属关系不能为空");
}
if (_cache.Get(CacheKeys.SmsKey + input.MobileTelephone) != input.SmsVerifyCode)
if (string.IsNullOrWhiteSpace(input.SmsVerifyCodeKey))
{
throw new UserFriendlyException("无效的短信校验码");
throw new UserFriendlyException("短信校验码键不能为空");
}
if (_cache.Get(input.SmsVerifyCodeKey) != input.SmsVerifyCode)
{
throw new UserFriendlyException("无效的短信校验码或已过期");
}
var person = await _repository.FindAsync(o=>o.IdNo == input.IdNo);
@ -393,8 +403,9 @@ namespace Shentun.WebPeis.Persons
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
[AllowAnonymous]
[HttpPost("api/app/Person/GetSmsVerifyCode")]
public async Task GetSmsVerifyCodeAsync(SmsVerifyCodeInputDto input)
public async Task<SmsVerifyCodeDto> GetSmsVerifyCodeAsync(SmsVerifyCodeInputDto input)
{
if(input == null)
{
@ -456,8 +467,15 @@ namespace Shentun.WebPeis.Persons
MobileTelephone = input.MobileTelephone,
CountryCode = "86",
};
var message = await SendVerifySms(createSmsTaskDto);
var smsVerifyCodeKey = await SendVerifySms(createSmsTaskDto);
var SmsVerifyCodeDto = new SmsVerifyCodeDto()
{
SmsVerifyCodeKey = smsVerifyCodeKey
};
return SmsVerifyCodeDto;
}
private async Task<UserTokenDto> GetTokenAsync(string request)
@ -546,8 +564,9 @@ namespace Shentun.WebPeis.Persons
//存储短信校验码
var options = new DistributedCacheEntryOptions()
.SetAbsoluteExpiration(TimeSpan.FromMinutes(verifySmsValidTime));
_cache.Set(CacheKeys.SmsKey + createSmsTaskDto.MobileTelephone, message, options);
return message;
var smsVerifyCodeKey = CacheKeys.SmsKey + createSmsTaskDto.MobileTelephone + Guid.NewGuid().ToString();
_cache.Set(smsVerifyCodeKey, message, options);
return smsVerifyCodeKey;
}

2
src/Shentun.WebPeis.EntityFrameworkCore/Configures/AppointScheduleTemplateTimeConfigure.cs

@ -18,7 +18,7 @@ namespace Shentun.WebPeis.Configures
entity.ToTable("appoint_schedule_template_time");
entity.HasIndex(e =>new object[] {e.AppointScheduleTemplateId,e.StartTime }, "ix_appoint_schedule_template_time").IsUnique();
//entity.HasIndex(e =>new object[] {e.AppointScheduleTemplateId,e.StartTime }, "ix_appoint_schedule_template_time").IsUnique();
entity.Property(e => e.AppointScheduleTemplateTimeId)
.ValueGeneratedNever()

Loading…
Cancel
Save