From 6e3a51ea8cd4da057b5a2d9f13043e7aee74aacb Mon Sep 17 00:00:00 2001 From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com> Date: Fri, 7 Jun 2024 00:20:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E6=A0=A1=E9=AA=8C=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shentun.Sms.Client/SmsClientHelper.cs | 1 + .../Persons/CreatePersonDto.cs | 24 +++- .../Persons/CreatePersonKinshipDto.cs | 71 +---------- .../Persons/SmsVerifyCodeInputDto.cs | 24 ++++ .../Persons/PersonAppService.cs | 118 ++++++++++++++++-- .../Enums/CacheKeys.cs | 1 + .../Persons/PersonManager.cs | 2 + .../appsettings.json | 1 + 8 files changed, 160 insertions(+), 82 deletions(-) create mode 100644 src/Shentun.WebPeis.Application.Contracts/Persons/SmsVerifyCodeInputDto.cs diff --git a/Shentun.Sms.Client/SmsClientHelper.cs b/Shentun.Sms.Client/SmsClientHelper.cs index 1826789..7f1d2a9 100644 --- a/Shentun.Sms.Client/SmsClientHelper.cs +++ b/Shentun.Sms.Client/SmsClientHelper.cs @@ -90,6 +90,7 @@ namespace Shentun.Sms.Client { throw new Exception("解析校验短信类别ID错误"); } + smsDto.SmsTypeId = verifySmsTypeId; await CreateSmsTask(smsDto); } diff --git a/src/Shentun.WebPeis.Application.Contracts/Persons/CreatePersonDto.cs b/src/Shentun.WebPeis.Application.Contracts/Persons/CreatePersonDto.cs index 21e7a65..9796e3c 100644 --- a/src/Shentun.WebPeis.Application.Contracts/Persons/CreatePersonDto.cs +++ b/src/Shentun.WebPeis.Application.Contracts/Persons/CreatePersonDto.cs @@ -68,16 +68,30 @@ namespace Shentun.WebPeis.Persons /// public string? Address { get; set; } - + /// + /// 微信OpenId + /// public string? WechatOpenId { get; set; } - + /// + /// 身份证件类别 + /// public string? IdTypeId { get; set; } - + /// + /// 国家码 + /// public string? CountryCode { get; set; } - + /// + /// 允许绑定 + /// public char? IsAllowBind { get; set; } - + /// + /// 微信JsCode + /// public string? JsCode { get; set; } + /// + /// 短信校验码 + /// + public string SmsVerifyCode { get; set; } } } diff --git a/src/Shentun.WebPeis.Application.Contracts/Persons/CreatePersonKinshipDto.cs b/src/Shentun.WebPeis.Application.Contracts/Persons/CreatePersonKinshipDto.cs index 008be75..af59dba 100644 --- a/src/Shentun.WebPeis.Application.Contracts/Persons/CreatePersonKinshipDto.cs +++ b/src/Shentun.WebPeis.Application.Contracts/Persons/CreatePersonKinshipDto.cs @@ -4,76 +4,9 @@ using System.Text; namespace Shentun.WebPeis.Persons { - public class CreatePersonKinshipDto + public class CreatePersonKinshipDto: CreatePersonDto { - /// - /// 组织单位ID - /// - public Guid MedicalCenterId { get; set; } - - - - /// - /// 姓名 - /// - public string PersonName { get; set; } = null!; - - /// - /// 性别 - /// - public char SexId { get; set; } - - /// - /// 婚姻状况 - /// - public char MaritalStatusId { get; set; } - - /// - /// 出生日期 - /// - public DateTime? BirthDate { get; set; } - - /// - /// 民族编号 - /// - public string? NationId { get; set; } - - /// - /// 出生地 - /// - public Guid? BirthPlaceId { get; set; } - - /// - /// 身份证号 - /// - public string? IdNo { get; set; } - - /// - /// 邮政编码 - /// - public string? PostalCode { get; set; } - - /// - /// email - /// - public string? Email { get; set; } - - /// - /// 手机号 - /// - public string? MobileTelephone { get; set; } - - /// - /// 地址 - /// - public string? Address { get; set; } - - public string? IdTypeId { get; set; } - - public string? CountryCode { get; set; } - - public char? IsAllowBind { get; set; } - public string KinshipId { get; set; } + } } diff --git a/src/Shentun.WebPeis.Application.Contracts/Persons/SmsVerifyCodeInputDto.cs b/src/Shentun.WebPeis.Application.Contracts/Persons/SmsVerifyCodeInputDto.cs new file mode 100644 index 0000000..8238874 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/Persons/SmsVerifyCodeInputDto.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.Persons +{ + public class SmsVerifyCodeInputDto + { + /// + /// 微信OpenId + /// + public string WechatOpenId { get; set; } + /// + /// 姓名 + /// + public string PersonName { get; set; } ; + + /// + /// 手机号码 + /// + public string MobileTelephone { get; set; } + public string IdNo { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application/Persons/PersonAppService.cs b/src/Shentun.WebPeis.Application/Persons/PersonAppService.cs index 61a1eb4..aa895a9 100644 --- a/src/Shentun.WebPeis.Application/Persons/PersonAppService.cs +++ b/src/Shentun.WebPeis.Application/Persons/PersonAppService.cs @@ -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 { /// @@ -70,7 +71,7 @@ namespace Shentun.WebPeis.Persons IRepository patientRegisterRepository, IRepository patientRepository, CacheService cacheService, - //IHttpContextAccessor httpContextAccessor, + IHttpContextAccessor httpContextAccessor, IRepository 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; } + /// + /// 获取校验码 + /// + /// + /// + /// + [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 GetTokenAsync(string request) { @@ -434,22 +523,35 @@ namespace Shentun.WebPeis.Persons } - public async Task SendVerifySms(CreateSmsTaskDto createSmsTaskDto) + public async Task 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; } + + + + } } diff --git a/src/Shentun.WebPeis.Domain.Shared/Enums/CacheKeys.cs b/src/Shentun.WebPeis.Domain.Shared/Enums/CacheKeys.cs index 5b36812..244962a 100644 --- a/src/Shentun.WebPeis.Domain.Shared/Enums/CacheKeys.cs +++ b/src/Shentun.WebPeis.Domain.Shared/Enums/CacheKeys.cs @@ -7,5 +7,6 @@ namespace Shentun.WebPeis.Enums public class CacheKeys { public const string OpenIdKey = "OpenIdKey"; + public const string SmsKey = "SmsKey"; } } diff --git a/src/Shentun.WebPeis.Domain/Persons/PersonManager.cs b/src/Shentun.WebPeis.Domain/Persons/PersonManager.cs index 38d32b4..896c847 100644 --- a/src/Shentun.WebPeis.Domain/Persons/PersonManager.cs +++ b/src/Shentun.WebPeis.Domain/Persons/PersonManager.cs @@ -143,6 +143,8 @@ namespace Shentun.WebPeis.Persons { throw new UserFriendlyException("体检中心不能为空"); } + + if (!string.IsNullOrEmpty(entity.IdNo)) { entity.IdNo = entity.IdNo.Trim(); diff --git a/src/Shentun.WebPeis.HttpApi.Host/appsettings.json b/src/Shentun.WebPeis.HttpApi.Host/appsettings.json index 1d14582..85ebf2d 100644 --- a/src/Shentun.WebPeis.HttpApi.Host/appsettings.json +++ b/src/Shentun.WebPeis.HttpApi.Host/appsettings.json @@ -53,6 +53,7 @@ "User": "admin", "Password": "888888", "VerifySmsTypeId": "3a12e09d-438a-1d08-d4f0-712aef13708d", + "VerifySmsValidTime": "1", "SmsAppId": "3a12e09f-8534-ec43-8c46-e61af0964ab6" } }