| | |
| | | using FlexJobApi.Core; |
| | | using Furion.DatabaseAccessor; |
| | | using Mapster; |
| | | using MediatR; |
| | | using System; |
| | |
| | | /// <summary> |
| | | /// 验证码命令处理器 |
| | | /// </summary> |
| | | public class VerifyCodeCommandHandler |
| | | : IRequestHandler<SendVerifyCodeCommand> |
| | | public class VerifyCodeCommandHandler( |
| | | SmsUtils smsUtils |
| | | ) : |
| | | IRequestHandler<SendLoginOrRegisterVerifyCodeCommand, Guid>, |
| | | IRequestHandler<UpdatePhoneNumberVerifyCodeCommand, Guid> |
| | | { |
| | | private readonly SmsUtils smsUtils = smsUtils; |
| | | |
| | | /// <summary> |
| | | /// 发送验证码 |
| | | /// 发送登录或注册短信 |
| | | /// </summary> |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public Task Handle(SendVerifyCodeCommand request, CancellationToken cancellationToken) |
| | | public Task<Guid> Handle(SendLoginOrRegisterVerifyCodeCommand request, CancellationToken cancellationToken) |
| | | { |
| | | throw new Exception(); |
| | | //var callback = new FriendlyEmptyCallback(); |
| | | //var code = new Random().Next(100000, 999999).ToString(); |
| | | //var entity = new SmsLog(); |
| | | //request.Adapt(entity); |
| | | //entity.Expiry = DateTime.Now.AddMinutes(30); |
| | | //entity.TemplateParam = new { code }.ToJson(); |
| | | //await utils.SendAsync(request.PhoneNumber, request.TemplateCode, entity.TemplateParam, cancellationToken); |
| | | //rep.Add(entity); |
| | | //await rep.SaveChangesAsync(cancellationToken); |
| | | //return new FriendlyEmptyCallback("验证码已发送,请查收"); |
| | | return smsUtils.SendVerifyCode(new SendVerifyCodeModel |
| | | { |
| | | PhoneNumber = request.PhoneNumber, |
| | | TemplateCode = EnumSmsTemplateCode.LoginOrRegister |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 发送更换手机号短信 |
| | | /// </summary> |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public Task<Guid> Handle(UpdatePhoneNumberVerifyCodeCommand request, CancellationToken cancellationToken) |
| | | { |
| | | return smsUtils.SendVerifyCode(new SendVerifyCodeModel |
| | | { |
| | | PhoneNumber = request.PhoneNumber, |
| | | TemplateCode = EnumSmsTemplateCode.UpdateUserPhoneNumber |
| | | }); |
| | | } |
| | | } |
| | | } |