diff --git a/COMCMS.Common/Utils.cs b/COMCMS.Common/Utils.cs index 1668157..6d2a31b 100644 --- a/COMCMS.Common/Utils.cs +++ b/COMCMS.Common/Utils.cs @@ -728,6 +728,34 @@ namespace COMCMS.Common return url; } + /// + /// 获取post表单金钱字段值 + /// + /// + /// + 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; + } + + /// + /// 获取get表单金钱字段值 + /// + /// + /// + 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 常用扩展方法 + /// + /// 扩展方法 + /// + public static class CommExtension + { + #region 货币转换 + /// + /// 数据库中金额换成元单位 + /// + /// + /// + public static decimal ConvertToMoney(this int price) + { + decimal realPrice = (decimal)price / 100; + return realPrice; + } + + /// + /// 元单位的金额换算成分 + /// + /// + /// + public static int ConvertMoneyToInt(this decimal price) + { + return (int)(price * 100); + } + #endregion + + } + #endregion } diff --git a/COMCMS.Core/Models/SMTPConfig.cs b/COMCMS.Core/Models/SMTPConfig.cs index d198523..3e5311e 100644 --- a/COMCMS.Core/Models/SMTPConfig.cs +++ b/COMCMS.Core/Models/SMTPConfig.cs @@ -69,6 +69,10 @@ namespace COMCMS.Core.Models set { _postusername = value; } get { return _postusername; } } + /// + /// 是否采用SSL发信 + /// + public int IsSSL { get; set; } = 0; #endregion Model } diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs index ba07c5e..8159af5 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs @@ -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); } + /// + /// 发送测试 + /// + /// + [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 = $"

发送测试邮件,发送时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}

" }; + //同步发送 + 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 附件配置 diff --git a/COMCMS.Web/Areas/AdminCP/Views/Member/ViewAdminLogDetail.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Member/ViewAdminLogDetail.cshtml index 39c98d1..a07407f 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Member/ViewAdminLogDetail.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Member/ViewAdminLogDetail.cshtml @@ -53,7 +53,7 @@
- +
diff --git a/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml b/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml index b9953a0..6e63b45 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml @@ -17,7 +17,7 @@
- @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" })) {
@@ -44,11 +44,19 @@
- +
+
+ +
+ +
+
@@ -60,18 +68,20 @@
-
- -
- +
+
+ +
+ +
-
-
-
-
- +
+
+
+ +
-
+
@@ -83,7 +93,8 @@
diff --git a/COMCMS.Web/COMCMS.Web.csproj b/COMCMS.Web/COMCMS.Web.csproj index 1e382df..fa1cd38 100644 --- a/COMCMS.Web/COMCMS.Web.csproj +++ b/COMCMS.Web/COMCMS.Web.csproj @@ -5,13 +5,17 @@ + + - - + + + + diff --git a/COMCMS.Web/Controllers/api/PaymentController.cs b/COMCMS.Web/Controllers/api/PaymentController.cs index 6fe395d..e0c2408 100644 --- a/COMCMS.Web/Controllers/api/PaymentController.cs +++ b/COMCMS.Web/Controllers/api/PaymentController.cs @@ -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); diff --git a/COMCMS.Web/Controllers/wxpaymentController.cs b/COMCMS.Web/Controllers/wxpaymentController.cs index 9c82b3f..bf7be8a 100644 --- a/COMCMS.Web/Controllers/wxpaymentController.cs +++ b/COMCMS.Web/Controllers/wxpaymentController.cs @@ -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);