From 83fa670fc682d359737afe03bbe2b4a44fd24778 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期三, 10 九月 2025 14:26:49 +0800 Subject: [PATCH] feat:开发 --- FlexJobApi.Core/Utils/SmsUtils/SmsUtils.cs | 29 +++++++++++++++++++++++++++-- 1 files changed, 27 insertions(+), 2 deletions(-) diff --git a/FlexJobApi.Core/Utils/SmsUtils/SmsUtils.cs b/FlexJobApi.Core/Utils/SmsUtils/SmsUtils.cs index fa3b0fa..fe1f343 100644 --- a/FlexJobApi.Core/Utils/SmsUtils/SmsUtils.cs +++ b/FlexJobApi.Core/Utils/SmsUtils/SmsUtils.cs @@ -1,9 +1,13 @@ 锘縰sing Azure.Core; +using Furion; using Furion.DatabaseAccessor; using Furion.FriendlyException; +using Furion.UnifyResult; using Mapster; using MediatR; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; @@ -18,15 +22,29 @@ /// </summary> public class SmsUtils { - private readonly IRepository<SmsLog> rep; + private readonly IRepository<SmsLog, LogDbContextLocator> rep; + private readonly IOptions<AliyunOptions> options; private readonly AliyunSmsUtils aliyunSmsUtils; public SmsUtils( - IRepository<SmsLog> rep, + IRepository<SmsLog, LogDbContextLocator> rep, + IOptions<AliyunOptions> options, AliyunSmsUtils aliyunSmsUtils) { this.rep = rep; + this.options = options; this.aliyunSmsUtils = aliyunSmsUtils; + } + + public async Task<Guid> Send(SendSmsModel model, object templateParam, CancellationToken cancellationToken = default) + { + var entity = new SmsLog(); + model.Adapt(entity); + entity.Expiry = DateTime.Now.AddMinutes(10); + entity.TemplateParam = templateParam.ToJson(); + await aliyunSmsUtils.SendAsync(model.PhoneNumber, model.TemplateCode, entity.TemplateParam, cancellationToken); + await rep.InsertAsync(entity); + return entity.Id; } public async Task<Guid> SendVerifyCode(SendVerifyCodeModel model, CancellationToken cancellationToken = default) @@ -38,6 +56,13 @@ entity.TemplateParam = new { code }.ToJson(); await aliyunSmsUtils.SendAsync(model.PhoneNumber, model.TemplateCode, entity.TemplateParam, cancellationToken); await rep.InsertAsync(entity); + if (options.Value.SMS.WithoutVerifyCode) + { + UnifyContext.Fill(new + { + Code = code + }); + } return entity.Id; } -- Gitblit v1.9.1