新增加发送邮件功能
This commit is contained in:
@@ -1,12 +1,25 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
private OptionsSetting OptionsSetting;
|
||||
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
public HomeController(IOptions<OptionsSetting> options)
|
||||
{
|
||||
OptionsSetting = options.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 心跳
|
||||
/// </summary>
|
||||
@@ -31,7 +44,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
}
|
||||
string key = ConfigUtils.Instance.GetConfig("DbKey");
|
||||
string encryptTxt = NETCore.Encrypt.EncryptProvider.DESEncrypt(content, key);
|
||||
return Ok(new { content, encryptTxt });
|
||||
return Ok(new { content, encryptTxt });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,5 +62,30 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
string encryptTxt = NETCore.Encrypt.EncryptProvider.DESDecrypt(content, key);
|
||||
return Ok(new { content, encryptTxt });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送邮件
|
||||
/// </summary>
|
||||
/// <param name="sendEmailVo">请求参数接收实体</param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "tool:email:send")]
|
||||
public IActionResult SendEmail([FromBody] SendEmailDto sendEmailVo)
|
||||
{
|
||||
if (sendEmailVo == null || string.IsNullOrEmpty(sendEmailVo.Subject) || string.IsNullOrEmpty(sendEmailVo.ToUser))
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"请求参数不完整"));
|
||||
}
|
||||
if (string.IsNullOrEmpty(OptionsSetting.MailOptions.From) || string.IsNullOrEmpty(OptionsSetting.MailOptions.Password))
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"请配置邮箱信息"));
|
||||
}
|
||||
MailHelper mailHelper = new MailHelper(OptionsSetting.MailOptions.From, OptionsSetting.MailOptions.Smtp, OptionsSetting.MailOptions.Port, OptionsSetting.MailOptions.Password);
|
||||
|
||||
mailHelper.SendMail(sendEmailVo.ToUser, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent);
|
||||
|
||||
logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}");
|
||||
|
||||
return SUCCESS(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.IO;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
@@ -26,24 +27,28 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <param name="formFile"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Verify]
|
||||
[ActionPermissionFilter(Permission = "system")]
|
||||
public IActionResult SaveFile([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传图片不能为空");
|
||||
string fileExt = Path.GetExtension(formFile.FileName);
|
||||
string savePath = Path.Combine(WebHostEnvironment.WebRootPath, FileUtil.GetdirPath("uploads"));
|
||||
|
||||
if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); }
|
||||
|
||||
string fileName = FileUtil.HashFileName(Guid.NewGuid().ToString()).ToLower() + fileExt;
|
||||
string finalFilePath = Path.Combine(savePath, fileName);
|
||||
string finalFilePath = Path.Combine(WebHostEnvironment.WebRootPath, FileUtil.GetdirPath("uploads"), fileName);
|
||||
finalFilePath = finalFilePath.Replace("\\", "/").Replace("//", "/");
|
||||
|
||||
if (!Directory.Exists(Path.GetDirectoryName(finalFilePath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(finalFilePath));
|
||||
}
|
||||
|
||||
using (var stream = new FileStream(finalFilePath, FileMode.Create))
|
||||
{
|
||||
formFile.CopyToAsync(stream);
|
||||
}
|
||||
|
||||
string accessPath = $"{OptionsSetting.Upload.UploadUrl}/{finalFilePath.Replace("wwwroot", "").Replace("\\", "/")}";
|
||||
return ToResponse(ToJson(1, accessPath));
|
||||
string accessPath = $"{OptionsSetting.Upload.UploadUrl}/{FileUtil.GetdirPath("uploads").Replace("\\", " /")}{fileName}";
|
||||
return ToResponse(ResultCode.SUCCESS, new { accessPath, fullPath = finalFilePath });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,12 +54,12 @@ namespace ZR.Admin.WebApi.Filters
|
||||
bool isDemoMode = ConfigUtils.Instance.GetAppConfig("DemoMode", false);
|
||||
|
||||
//演示公开环境屏蔽权限
|
||||
string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear" };
|
||||
string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "send" };
|
||||
if (isDemoMode && (denyPerms.Any(f => Permission.ToLower().Contains(f.ToLower())) || Permission.Equals("system")))
|
||||
{
|
||||
context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "演示模式 , 不允许操作" });
|
||||
}
|
||||
if (!HasPermi)
|
||||
if (!HasPermi && !Permission.Equals("system"))
|
||||
{
|
||||
logger.Info($"用户{info.NickName}没有权限访问{context.HttpContext.Request.Path},当前权限[{Permission}]");
|
||||
context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "你没有权限访问" });
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"urls": "http://localhost:8888", //<2F><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>url
|
||||
"sysConfig": {
|
||||
"DBCommandTimeout": 10,
|
||||
"tokenExpire": 1440,//Jwt token<65><6E>ʱʱ<CAB1>䣨<EFBFBD>֣<EFBFBD>
|
||||
"tokenExpire": 1440, //Jwt token<65><6E>ʱʱ<CAB1>䣨<EFBFBD>֣<EFBFBD>
|
||||
"cors": "http://localhost:8887" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<22><><EFBFBD><EFBFBD>
|
||||
},
|
||||
"DemoMode": false, //<2F>Ƿ<EFBFBD><C7B7><EFBFBD>ʾģʽ
|
||||
@@ -22,7 +22,7 @@
|
||||
"UploadDirectory": "/",
|
||||
"UploadUrl": "http://localhost:8888"
|
||||
},
|
||||
"ALYUN_OCS": {
|
||||
"QIQIU_OSS": {
|
||||
"REGIONID": "cn-hangzhou",
|
||||
"KEY": "XX",
|
||||
"SECRET": "XX"
|
||||
@@ -33,5 +33,15 @@
|
||||
"autoPre": true, //<2F>Զ<EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD>ǰ
|
||||
"author": "zr",
|
||||
"tablePrefix": "live_,sys_" //"<22><>ǰ<C7B0><D7BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<C7B0><D7BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6>ŷָ<C5B7><D6B8><EFBFBD>",
|
||||
},
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
"MailOptions": {
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
"From": "xxxx@qq.com",
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
"Password": "123456",
|
||||
//Э<><D0AD>
|
||||
"Smtp": "smtp.qq.com",
|
||||
"Port": 587
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user