usertest
cjy 4 months ago
parent 17fc163841
commit cfca7a0171

@ -1,5 +1,9 @@
using System.Net;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Text;
using DS.Module.Core.Extensions;
using System.Security.Policy;
namespace DS.Module.Core.Helpers;
@ -72,7 +76,45 @@ public class RequestHelper
return result;
}
/// <summary>
/// http post请求
/// </summary>
/// <param name="url">地址</param>
/// <param name="parameter">入参</param>
/// <param name="token"></param>
/// <param name="headers">头信息</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
/// , string token ="", Dictionary<string, string> headers = null
public static async Task<string> PostAsyncNoHeaders(string url, string parameter)
{
using (var client = new HttpClient())
{
//var data = new StringContent("param1=value1&param2=value2", Encoding.UTF8, "application/x-www-form-urlencoded");
var data = new StringContent(parameter, Encoding.UTF8, "application/x-www-form-urlencoded");
//_logger.LogWarning($"data:{data.ToJsonString()}parameter{parameter}");
// 添加header参数
//client.DefaultRequestHeaders.Add("Authorization", "Bearer your_token_here");
//foreach (var header in headers)
//{
// client.DefaultRequestHeaders.Add(header.Key, header.Value);
//}
//_logger.LogWarning($"header:{client.DefaultRequestHeaders.ToJsonString()}");
try
{
var response = await client.PostAsync(url, data);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
return responseBody;
}
catch (HttpRequestException e)
{
throw new Exception(e.Message);
}
}
}
/// <summary>
/// http异步请求
/// </summary>

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DS.Module.Core\DS.Module.Core.csproj" />
<ProjectReference Include="..\DS.Module.Nuget\DS.Module.Nuget.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.Module.EmailModule
{
/// <summary>
/// 大简云邮箱接口请求
/// </summary>
public class DjyEmailSendReq
{
/// <summary>
/// 接收邮箱
/// </summary>
public string SendTo { get; set; }
/// <summary>
/// 抄送
/// </summary>
public string CCTo { get; set; }
/// <summary>
/// 邮件标题
/// </summary>
public string Title { get; set; }
/// <summary>
/// 邮件正文
/// </summary>
public string Body { get; set; }
/// <summary>
/// 邮件显示的发送人 不设置则显示发送的邮箱
/// </summary>
public string ShowName { get; set; }
/// <summary>
/// 发送邮箱配置(发件邮箱)
/// </summary>
public string SmtpConfig { get; set; }
/// <summary>
/// 附件列表
/// </summary>
public List<Attaches> Attaches { get; set; }
/// <summary>
/// 自定义发送的邮箱账号 发件邮箱的账号,使用自定义邮箱发送邮件时,必须指定
/// </summary>
public string Account { get; set; }
/// <summary>
/// 自定义发送的邮箱密码 发件邮箱的密码,使用自定义邮箱发送邮件时,必须指定
/// </summary>
public string Password { get; set; }
/// <summary>
/// 自定义发送的邮箱服务器 发件邮箱的服务器地址,使用自定义邮箱发送邮件时,必须指定
/// </summary>
public string Server { get; set; }
/// <summary>
/// 自定义发送的发件端口 发件邮箱的端口,使用自定义邮箱发送邮件时,必须指定
/// </summary>
public int Port { get; set; }
/// <summary>
/// 自定义发送是否使用ssl 发件邮箱的是否使用SSL使用自定义邮箱发送邮件时必须指定
/// </summary>
public bool UseSSL { get; set; }
}
/// <summary>
/// 附件信息
/// </summary>
public class Attaches {
/// <summary>
/// 附件名称 在邮件中显示的附件名称
/// </summary>
public string AttachName { get; set; } = string.Empty;
/// <summary>
/// 附件内容 以base64编码的字符串
/// </summary>
public string AttachContent { get; set; } = string.Empty;
}
/// <summary>
/// SmtpConfig选项枚举
/// </summary>
public enum SmtpConfigEnum {
/// <summary>
/// dongshengcangdan@h8j.top
/// </summary>
CANGDAN,
/// <summary>
/// inv@mail.myshipping.net
/// </summary>
INVOICE,
/// <summary>
/// noreplay@mail.myshipping.net
/// </summary>
NOREPLAY,
/// <summary>
/// service@mail.myshipping.net
/// </summary>
SERVICE,
/// <summary>
/// spot@mail.myshipping.net
/// </summary>
SPOT,
}
/// <summary>
/// 大简云邮箱接口返回
/// </summary>
public class DjyEmailSendRes {
/// <summary>
/// 是否成功
/// </summary>
public bool Success { get; set; }
/// <summary>
/// 说明文本
/// </summary>
public string Message { get; set; }
/// <summary>
/// 代号
/// </summary>
public string Code { get; set; }
}
}

@ -0,0 +1,27 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.Module.EmailModule
{
/// <summary>
/// 注入Email服务
/// </summary>
public static class EmailModuleInstall
{
/// <summary>
///
/// </summary>
/// <param name="services"></param>
/// <exception cref="ArgumentNullException"></exception>
public static void AddEmailModuleInstall(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
services.AddScoped<IEmailService, EmailService>();
}
}
}

@ -0,0 +1,40 @@
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> SendEmailByDjy(DjyEmailSendReq req)
{
var url = db.Queryable<object>().AS("sys_config").Where("Code=@Code", new { Code = "" }).Select("Value").First()?.ToString();
if (url.IsNull())
return await Task.FromResult(DataResult.Failed("未配置"));
var res =await RequestHelper.PostAsyncNoHeaders(url, JsonConvert.SerializeObject(req));
throw new NotImplementedException();
}
}
}

@ -0,0 +1,21 @@
using DS.Module.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.Module.EmailModule
{
public interface IEmailService
{
/// <summary>
/// 根据大简云邮箱接口发送邮件
/// </summary>
/// <param name="req">请求数据</param>
/// <returns></returns>
public Task<DataResult> SendEmailByDjy(DjyEmailSendReq req);
}
}

@ -57,7 +57,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DS.Module.DjyRulesEngine",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DS.Module.RedisModule", "DS.Module.RedisModule\DS.Module.RedisModule.csproj", "{CF36AACB-6405-4F5E-9494-72D8BD1FF414}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DS.WMS.FinanceApi", "DS.WMS.FinanceApi\DS.WMS.FinanceApi.csproj", "{32B97A3A-C361-44F3-B417-5D08E9FD9624}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DS.WMS.FinanceApi", "DS.WMS.FinanceApi\DS.WMS.FinanceApi.csproj", "{32B97A3A-C361-44F3-B417-5D08E9FD9624}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DS.Module.EmailModule", "DS.Module.EmailModule\DS.Module.EmailModule.csproj", "{4B51DCC1-62A5-49C5-978B-798E6B48F3C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -165,6 +167,10 @@ Global
{32B97A3A-C361-44F3-B417-5D08E9FD9624}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32B97A3A-C361-44F3-B417-5D08E9FD9624}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32B97A3A-C361-44F3-B417-5D08E9FD9624}.Release|Any CPU.Build.0 = Release|Any CPU
{4B51DCC1-62A5-49C5-978B-798E6B48F3C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B51DCC1-62A5-49C5-978B-798E6B48F3C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B51DCC1-62A5-49C5-978B-798E6B48F3C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B51DCC1-62A5-49C5-978B-798E6B48F3C0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -195,6 +201,7 @@ Global
{C3296BF4-9A02-4C7D-90C9-7BBFDAA4F1A1} = {518DB9B5-80A8-4B2C-8570-52BD406458DE}
{CF36AACB-6405-4F5E-9494-72D8BD1FF414} = {518DB9B5-80A8-4B2C-8570-52BD406458DE}
{32B97A3A-C361-44F3-B417-5D08E9FD9624} = {65D75DB2-12D5-4D1F-893D-9750905CE5E4}
{4B51DCC1-62A5-49C5-978B-798E6B48F3C0} = {518DB9B5-80A8-4B2C-8570-52BD406458DE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {66115F23-94B4-43C0-838E-33B5CF77F788}

Loading…
Cancel
Save