|
|
|
@ -36,6 +36,7 @@ using System.IO; |
|
|
|
using Shentun.WebPeis.CustomerOrgs; |
|
|
|
using Shentun.Utilities.Enums; |
|
|
|
using Shentun.Sms.Client; |
|
|
|
using Shentun.Utilities; |
|
|
|
namespace Shentun.WebPeis.Persons |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
@ -70,7 +71,7 @@ namespace Shentun.WebPeis.Persons |
|
|
|
IRepository<PatientRegister> patientRegisterRepository, |
|
|
|
IRepository<Patient> patientRepository, |
|
|
|
CacheService cacheService, |
|
|
|
//IHttpContextAccessor httpContextAccessor,
|
|
|
|
IHttpContextAccessor httpContextAccessor, |
|
|
|
IRepository<CustomerOrg> customerOrgRepository) |
|
|
|
{ |
|
|
|
_repository = repository; |
|
|
|
@ -84,7 +85,7 @@ namespace Shentun.WebPeis.Persons |
|
|
|
_patientRegisterRepository = patientRegisterRepository; |
|
|
|
_patientRepository = patientRepository; |
|
|
|
_cacheService = cacheService; |
|
|
|
//_httpContextAccessor = httpContextAccessor;
|
|
|
|
_httpContextAccessor = httpContextAccessor; |
|
|
|
_customerOrgRepository = customerOrgRepository; |
|
|
|
} |
|
|
|
|
|
|
|
@ -153,6 +154,19 @@ namespace Shentun.WebPeis.Persons |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("无效的WechatOpenId"); |
|
|
|
} |
|
|
|
if (string.IsNullOrWhiteSpace(input.MobileTelephone)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("手机号码不能为空"); |
|
|
|
} |
|
|
|
if (input.MobileTelephone.Length != 11) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("手机号码必须为11位"); |
|
|
|
} |
|
|
|
|
|
|
|
if (_cache.Get(CacheKeys.SmsKey + input.MobileTelephone) != input.SmsVerifyCode) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("无效的短信校验码"); |
|
|
|
} |
|
|
|
|
|
|
|
var person = await _repository.FindAsync(o => o.IdNo == input.IdNo); |
|
|
|
if (person != null) |
|
|
|
@ -233,6 +247,11 @@ namespace Shentun.WebPeis.Persons |
|
|
|
throw new UserFriendlyException("亲属关系不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (_cache.Get(CacheKeys.SmsKey + input.MobileTelephone) != input.SmsVerifyCode) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("无效的短信校验码"); |
|
|
|
} |
|
|
|
|
|
|
|
var person = await _repository.FindAsync(o=>o.IdNo == input.IdNo); |
|
|
|
if (person != null) |
|
|
|
{ |
|
|
|
@ -368,8 +387,78 @@ namespace Shentun.WebPeis.Persons |
|
|
|
return returnValue; |
|
|
|
|
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 获取校验码
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
|
|
[HttpPost("api/app/Person/GetSmsVerifyCode")] |
|
|
|
public async Task GetSmsVerifyCodeAsync(SmsVerifyCodeInputDto input) |
|
|
|
{ |
|
|
|
if(input == null) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("input不能为空"); |
|
|
|
} |
|
|
|
if (string.IsNullOrWhiteSpace(input.WechatOpenId)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("WechatOpenId不能为空"); |
|
|
|
} |
|
|
|
if (_cache.Get(CacheKeys.OpenIdKey + input.WechatOpenId) != input.WechatOpenId) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("无效的WechatOpenId"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(input.PersonName)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("姓名不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(input.MobileTelephone)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("手机号码不能为空"); |
|
|
|
} |
|
|
|
if (input.MobileTelephone.Length != 11) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("手机号码必须为11位"); |
|
|
|
} |
|
|
|
if (string.IsNullOrWhiteSpace(input.IdNo)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("身份证号码不能为空"); |
|
|
|
} |
|
|
|
input.IdNo = input.IdNo.Trim(); |
|
|
|
if (input.IdNo.Length != 18) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("身份证长度必须为18位"); |
|
|
|
} |
|
|
|
//var sexByIdNo = ConvertExtr.ToSexByIdNo(idNo).ToCharArray();
|
|
|
|
|
|
|
|
|
|
|
|
var person = await _repository.FindAsync(o => o.IdNo == input.IdNo); |
|
|
|
if (person != null) |
|
|
|
{ |
|
|
|
var user = (await _identityUserRepository.GetQueryableAsync()).Where(o => o.Id == person.PersonId && |
|
|
|
o.PhoneNumber == input.MobileTelephone).FirstOrDefault(); |
|
|
|
if (user == null) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("该身份证号已注册,但手机号码不一致"); |
|
|
|
} |
|
|
|
//if (!string.IsNullOrWhiteSpace(person.WechatOpenId))
|
|
|
|
//{
|
|
|
|
// throw new UserFriendlyException("该微信号已注册");
|
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
var createSmsTaskDto = new CreateSmsTaskDto() |
|
|
|
{ |
|
|
|
PersonId = "0001", |
|
|
|
PersonName = input.PersonName, |
|
|
|
MobileTelephone = input.MobileTelephone, |
|
|
|
CountryCode = "86", |
|
|
|
}; |
|
|
|
var message = await SendVerifySms(createSmsTaskDto); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private async Task<UserTokenDto> GetTokenAsync(string request) |
|
|
|
{ |
|
|
|
@ -434,22 +523,35 @@ namespace Shentun.WebPeis.Persons |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task SendVerifySms(CreateSmsTaskDto createSmsTaskDto) |
|
|
|
public async Task<string> SendVerifySms(CreateSmsTaskDto createSmsTaskDto) |
|
|
|
{ |
|
|
|
if(createSmsTaskDto == null) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("createSmsTaskDto参数不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var message = Shentun.Utilities.Encrypt.RandomHelper.CreateRandom(Utilities.Enums.RandomType.Num, 6); |
|
|
|
createSmsTaskDto.Content = message+"|1"; |
|
|
|
|
|
|
|
var verifySmsValidTimeStr = _configuration.GetSection("Sms") |
|
|
|
.GetSection("VerifySmsValidTime").Value; |
|
|
|
if (!int.TryParse(verifySmsValidTimeStr, out var verifySmsValidTime)) |
|
|
|
{ |
|
|
|
throw new Exception("解析校验短信有效时间错误"); |
|
|
|
} |
|
|
|
|
|
|
|
createSmsTaskDto.Content = message+"|" + verifySmsValidTime.ToString(); |
|
|
|
//发送短信
|
|
|
|
createSmsTaskDto.TaskCycleType = '0'; |
|
|
|
await SmsClientHelper.CreateVerifySmsTask(createSmsTaskDto); |
|
|
|
//存储短信校验码
|
|
|
|
_cache.Set(createSmsTaskDto.MobileTelephone, message); |
|
|
|
var options = new DistributedCacheEntryOptions() |
|
|
|
.SetAbsoluteExpiration(TimeSpan.FromMinutes(verifySmsValidTime)); |
|
|
|
_cache.Set(CacheKeys.SmsKey + createSmsTaskDto.MobileTelephone, message, options); |
|
|
|
return message; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |