更新后台smtp发信配置;更新组件
This commit is contained in:
@@ -728,6 +728,34 @@ namespace COMCMS.Common
|
||||
return url;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取post表单金钱字段值
|
||||
/// </summary>
|
||||
/// <param name="inputName"></param>
|
||||
/// <returns></returns>
|
||||
public static decimal GetPostFormMoney(string inputName)
|
||||
{
|
||||
string v = MyHttpContext.Current.Request.Form[inputName];
|
||||
decimal price = 0M;
|
||||
if (!IsDecimal(v) && decimal.Parse(v) < 0) v = "0";
|
||||
price = decimal.Parse(v);
|
||||
return price;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取get表单金钱字段值
|
||||
/// </summary>
|
||||
/// <param name="inputName"></param>
|
||||
/// <returns></returns>
|
||||
public static decimal GetQueryStringMoney(string inputName)
|
||||
{
|
||||
string v = MyHttpContext.Current.Request.Query[inputName];
|
||||
decimal price = 0M;
|
||||
if (!IsDecimal(v) && decimal.Parse(v) < 0) v = "0";
|
||||
price = decimal.Parse(v);
|
||||
return price;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 处理部分
|
||||
@@ -979,4 +1007,36 @@ namespace COMCMS.Common
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#region 常用扩展方法
|
||||
/// <summary>
|
||||
/// 扩展方法
|
||||
/// </summary>
|
||||
public static class CommExtension
|
||||
{
|
||||
#region 货币转换
|
||||
/// <summary>
|
||||
/// 数据库中金额换成元单位
|
||||
/// </summary>
|
||||
/// <param name="price"></param>
|
||||
/// <returns></returns>
|
||||
public static decimal ConvertToMoney(this int price)
|
||||
{
|
||||
decimal realPrice = (decimal)price / 100;
|
||||
return realPrice;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 元单位的金额换算成分
|
||||
/// </summary>
|
||||
/// <param name="price"></param>
|
||||
/// <returns></returns>
|
||||
public static int ConvertMoneyToInt(this decimal price)
|
||||
{
|
||||
return (int)(price * 100);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -69,6 +69,10 @@ namespace COMCMS.Core.Models
|
||||
set { _postusername = value; }
|
||||
get { return _postusername; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否采用SSL发信
|
||||
/// </summary>
|
||||
public int IsSSL { get; set; } = 0;
|
||||
#endregion Model
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ using COMCMS.Web.Common;
|
||||
using COMCMS.Core.Models;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.IO;
|
||||
using MimeKit;
|
||||
using MailKit.Net.Smtp;
|
||||
|
||||
namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
{
|
||||
@@ -116,7 +118,49 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
|
||||
return Json(tip);
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送测试
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[MyAuthorize("edit", "smptconfig", "JSON")]
|
||||
public IActionResult SendTestMail()
|
||||
{
|
||||
string mail = Request.Form["txtEmail"];
|
||||
Config cfg = Config.GetSystemConfig();
|
||||
if (string.IsNullOrWhiteSpace(mail) || !Utils.IsValidEmail(mail))
|
||||
{
|
||||
tip.Message = "请输入正确的邮箱格式!";
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
var smtp = cfg.SMTPConfigEntity;
|
||||
if (string.IsNullOrEmpty(smtp.SmtpHost) || string.IsNullOrEmpty(smtp.SmtpEmail) || string.IsNullOrEmpty(smtp.SmtpEmailPwd))
|
||||
{
|
||||
tip.Message = "系统SMTP配置错误,请先配置后再执行此操作!";
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
var emailMessage = new MimeMessage();
|
||||
emailMessage.From.Add(new MailboxAddress(smtp.PostUserName, smtp.SmtpEmail));
|
||||
emailMessage.To.Add(new MailboxAddress("", mail));
|
||||
emailMessage.Subject = "发送测试邮件";
|
||||
emailMessage.Body = new TextPart("html") { Text = $"<p>发送测试邮件,发送时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}</p>" };
|
||||
//同步发送
|
||||
using (var client = new SmtpClient())
|
||||
{
|
||||
client.Connect(smtp.SmtpHost, int.Parse(smtp.SmtpProt), smtp.IsSSL == 1 ? true : false);
|
||||
|
||||
client.Authenticate(smtp.SmtpEmail, smtp.SmtpEmailPwd);
|
||||
|
||||
client.Send(emailMessage);
|
||||
client.Disconnect(true);
|
||||
}
|
||||
tip.Status = JsonTip.SUCCESS;
|
||||
tip.Message = "发送成功,请查收!";
|
||||
Admin.WriteLogActions($"发送测试Email(to:${mail});");
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 附件配置
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">操作详细日志:</label>
|
||||
<div class="col-sm-8">
|
||||
<label class="control-label" style="text-align:left">@Model.Actions.Replace("|||","<br />")</label>
|
||||
<label class="control-label" style="text-align:left">@Html.Raw(Model.Actions.Replace("|||", "<br />"))</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<div class="tab-content">
|
||||
<div id="tab-1" class="tab-pane active">
|
||||
<div class="panel-body">
|
||||
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "editBaseConfigForm", @class = "form-horizontal m-t" }))
|
||||
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "editSMTPConfigForm", @class = "form-horizontal m-t" }))
|
||||
{
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">SMTP服务器:</label>
|
||||
@@ -44,11 +44,19 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">公司电话:</label>
|
||||
<label class="col-sm-3 control-label">SMTP身份验证密码:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="SmtpEmailPwd" name="SmtpEmailPwd" maxlength="50" type="text" class="form-control" placeholder="帐号密码" value="@Model.SmtpEmailPwd">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">SSL 连接:</label>
|
||||
<div class="col-sm-8">
|
||||
<label class="checkbox-inline i-checks">
|
||||
<input type="checkbox" value="1" name="IsSSL" id="IsSSL" @(Model.IsSSL == 1 ? "checked = \"checked\"" : "")> SSL连接(一般如果端口是465 则勾选此选项,如果是25端口,则不用勾选此选项)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-2">
|
||||
@@ -60,18 +68,20 @@
|
||||
</div>
|
||||
<div id="tab-2" class="tab-pane">
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">测试收件人:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="txtEmail" name="txtEmail" maxlength="200" type="text" class="form-control" placeholder="请输入一个接收邮箱地址进行测试" value="">
|
||||
<form asp-action="SendTestMail" asp-area="AdminCP" asp-controller="System" name="sendtestmailForm" id="sendtestmailForm" method="post" class="form-horizontal m-t">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">测试收件人:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="txtEmail" name="txtEmail" maxlength="200" type="email" class="form-control" placeholder="请输入一个接收邮箱地址进行测试" value="">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-2">
|
||||
<button class="btn btn-primary" type="button" onclick="alert('敬请期待...')"><i class="fa fa-send"></i> 测试发信 </button>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-2">
|
||||
<button class="btn btn-primary" type="submit"><i class="fa fa-send"></i> 测试发信 </button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -83,7 +93,8 @@
|
||||
</div>
|
||||
<script>
|
||||
$(function () {
|
||||
DoPost("editBaseConfigForm");
|
||||
DoPost("editSMTPConfigForm");
|
||||
DoPost("sendtestmailForm");
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -5,13 +5,17 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MailKit" Version="2.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.3" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.3" />
|
||||
<PackageReference Include="MimeKit" Version="2.0.6" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.12" />
|
||||
<PackageReference Include="NewLife.XCode" Version="9.9.6806.38809" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="Senparc.Weixin.MP" Version="15.2.2" />
|
||||
<PackageReference Include="Senparc.Weixin.WxOpen" Version="2.4.0" />
|
||||
<PackageReference Include="Senparc.Weixin" Version="5.1.8" />
|
||||
<PackageReference Include="Senparc.Weixin.MP" Version="15.3.0" />
|
||||
<PackageReference Include="Senparc.Weixin.TenPay" Version="0.1.0" />
|
||||
<PackageReference Include="Senparc.Weixin.WxOpen" Version="2.4.1" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.5.1" />
|
||||
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -9,7 +9,7 @@ using COMCMS.Web.Filter;
|
||||
using XCode;
|
||||
using NewLife.Log;
|
||||
using Senparc.Weixin.MP;
|
||||
using Senparc.Weixin.MP.TenPayLibV3;
|
||||
using Senparc.Weixin.TenPay.V3;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace COMCMS.Web.Controllers.api
|
||||
@@ -102,7 +102,7 @@ namespace COMCMS.Web.Controllers.api
|
||||
string rtimeStamp = Utils.GetTimeStamp();
|
||||
|
||||
//创建请求统一订单接口参数
|
||||
var xmlDataInfo = new TenPayV3UnifiedorderRequestData(TenPayV3Info.AppId, TenPayV3Info.MchId, entity.Title, model.PayOrderNum, (int)(entity.TotalPay * 100), Utils.GetIP(), TenPayV3Info.TenPayV3Notify, TenPayV3Type.JSAPI, my.WeixinAppOpenId, TenPayV3Info.Key, nonceStr);
|
||||
var xmlDataInfo = new TenPayV3UnifiedorderRequestData(TenPayV3Info.AppId, TenPayV3Info.MchId, entity.Title, model.PayOrderNum, (int)(entity.TotalPay * 100), Utils.GetIP(), TenPayV3Info.TenPayV3Notify, Senparc.Weixin.TenPay.TenPayV3Type.JSAPI, my.WeixinAppOpenId, TenPayV3Info.Key, nonceStr);
|
||||
|
||||
//返回给微信的请求
|
||||
RequestHandler res = new RequestHandler(null);
|
||||
|
||||
@@ -10,7 +10,7 @@ using NewLife.Log;
|
||||
using Senparc.Weixin.Exceptions;
|
||||
using Senparc.Weixin;
|
||||
using Senparc.Weixin.MP;
|
||||
using Senparc.Weixin.MP.TenPayLibV3;
|
||||
using Senparc.Weixin.TenPay.V3;
|
||||
using System.Collections;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@@ -28,9 +28,8 @@ namespace COMCMS.Web.Controllers
|
||||
XTrace.WriteLine("微信支付异步通知开始:");
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
ResponseHandler resHandler = new ResponseHandler(null);
|
||||
|
||||
string return_code = resHandler.GetParameter("return_code");
|
||||
string return_msg = resHandler.GetParameter("return_msg");
|
||||
|
||||
@@ -42,7 +41,6 @@ namespace COMCMS.Web.Controllers
|
||||
string wxmchKey = cfg.MCHKey;// ConfigurationManager.AppSettings["WeixinMCHKey"];
|
||||
|
||||
TenPayV3Info TenPayV3Info = new TenPayV3Info(appId, appSecrect, wxmchId, wxmchKey, Utils.GetServerUrl() + "/wxpayment/notify", Utils.GetServerUrl() + "/wxpayment/notify");
|
||||
|
||||
string res = null;
|
||||
|
||||
resHandler.SetKey(TenPayV3Info.Key);
|
||||
|
||||
Reference in New Issue
Block a user