You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Helpers;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft;
using Newtonsoft.Json;
using DS.Module.Core.Extensions;
namespace DS.Module.EmailModule
{
public class EmailService : IEmailService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly string emailServiceUrl;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="serviceProvider"></param>
public EmailService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
}
public async Task<DataResult<string>> SendEmailByDjy(DjyEmailSendReq req)
{
var url = db.Queryable<object>().Filter(null,true).AS("sys_config").Where("Code=@Code", new { Code = "djy_email_url" }).Select("Value").First()?.ToString();
if (url.IsNull())
return await Task.FromResult(DataResult<string>.Failed("未配置大简云邮件接口"));
var res1 = await RequestHelper.PostAsyncNoHeaders(url, JsonConvert.SerializeObject(req));
var res = JsonConvert.DeserializeObject<DjyEmailSendRes>(res1);
if (res.Success)
{
return await Task.FromResult(DataResult<string>.SuccessMsg(res.Message));
}
else {
return await Task.FromResult(DataResult<string>.Failed(res.Message));
}
}
}
}