From e1799fc3b8f489c046682cf5020d84ed1f0a9326 Mon Sep 17 00:00:00 2001 From: zhaozhenjing Date: Thu, 30 Oct 2025 14:41:36 +0800 Subject: [PATCH] =?UTF-8?q?[MODIFY]=E4=BF=AE=E6=94=B9=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=96=B9=E5=BC=8F=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Impl/Admins/SMSService.cs | 431 +++++++++++------- .../Impl/Business/AppEarlyWarningService.cs | 4 +- .../appsettings.json | 4 +- .../configs/appsettings.json | 26 +- .../Options/SmsConfiguration.cs | 14 +- 5 files changed, 293 insertions(+), 186 deletions(-) diff --git a/src/2.services/ATS.NonCustodial.Application/Impl/Admins/SMSService.cs b/src/2.services/ATS.NonCustodial.Application/Impl/Admins/SMSService.cs index 8eebef0..5a6f920 100644 --- a/src/2.services/ATS.NonCustodial.Application/Impl/Admins/SMSService.cs +++ b/src/2.services/ATS.NonCustodial.Application/Impl/Admins/SMSService.cs @@ -1,13 +1,11 @@ using ATS.NonCustodial.Application.Base; +using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.AppDictionaries; +using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.AppDictionaries.Output; using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.SMS; using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.SMS.Input; using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.SMS.Output; -using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppCaseManagements.AppCaseManagement.Input; -using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppCaseManagements.AppCaseManagement.Output; -using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppEarlyWarnings.Input; using ATS.NonCustodial.Domain.Entities.Admins; using ATS.NonCustodial.Domain.Entities.Business.CaseManagements; -using ATS.NonCustodial.Domain.Entities.Business.EarlyWarning; using ATS.NonCustodial.Domain.Shared.Enums; using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore; using ATS.NonCustodial.DynamicApi; @@ -19,10 +17,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using StackExchange.Profiling.Internal; -using TencentCloud.Common; -using TencentCloud.Common.Profile; -using TencentCloud.Sms.V20210111; -using TencentCloud.Sms.V20210111.Models; +using System.Web; namespace ATS.NonCustodial.Application.Impl.Admins { @@ -36,15 +31,31 @@ namespace ATS.NonCustodial.Application.Impl.Admins private readonly IEfRepository _appUserRepository; protected readonly IEfRepository _appCaseManagementRepository; protected readonly IEfRepository _appSupervisedPersonRepository; + private readonly HttpClient _httpClient; + protected readonly IAppDictionaryService _appDictionaryService; + + public SMSService(IEfRepository appCaseManagementRepository, IEfRepository appSupervisedPersonRepository, IEfRepository appSMSRepository, + IAppDictionaryService appDictionaryService, IEfRepository appUserRepository) { _appSMSRepository = appSMSRepository; _appUserRepository = appUserRepository; _appCaseManagementRepository = appCaseManagementRepository; _appSupervisedPersonRepository = appSupervisedPersonRepository; + _appDictionaryService = appDictionaryService; + + // 配置HttpClient,忽略SSL证书验证(仅用于测试环境) + var handler = new HttpClientHandler() + { + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true + }; + + _httpClient = new HttpClient(handler); + _httpClient.Timeout = TimeSpan.FromSeconds(30); + } @@ -62,8 +73,8 @@ namespace ATS.NonCustodial.Application.Impl.Admins // .ToListAsync(); //var caseIdList = selectLimits.Select(w => w.CaseId).Distinct().ToList(); - var express =await GetExpression(input, _appSMSRepository.AsQueryable(false, true)); - + var express = await GetExpression(input, _appSMSRepository.AsQueryable(false, true)); + var rtn = await base.GetPageAsync(input, express); @@ -86,35 +97,21 @@ namespace ATS.NonCustodial.Application.Impl.Admins default: break; } - if(item.Result.Contains("Code")) + if (item.Result.Split("|")[0].Equals("OK")) { - int codeStart = item.Result.IndexOf("\"Code\":\"") + 8; - int codeEnd = item.Result.IndexOf("\"", codeStart); - string code = item.Result.Substring(codeStart, codeEnd - codeStart); - int msgStart = item.Result.IndexOf("\"Message\":\"") + 11; - int msgEnd = item.Result.IndexOf("\"", msgStart); - string message = item.Result.Substring(msgStart, msgEnd - msgStart); // "send success" - if (code.Equals("Ok")) - { - item.Message = message; - item.Result = "短信发送成功"; - } - else - { - item.Message = message; - item.Result = "短信发送异常"; - } + item.Message = item.Result; + item.Result = "短信发送成功"; } else { item.Message = item.Result; - item.Result ="短信发送异常"; + item.Result = "短信发送异常"; } } var filteredList = rtn.Data - .WhereIf(input.Name.HasValue(),item => item.Name == input.Name) // 筛选条件 + .WhereIf(input.Name.HasValue(), item => item.Name == input.Name) // 筛选条件 .ToList(); rtn.Data = filteredList; return ResultOutput.Ok(rtn); @@ -145,16 +142,20 @@ namespace ATS.NonCustodial.Application.Impl.Admins [AllowAnonymous] public async Task SendCheckCodeSMS(string phone, string ipAddress = "", string type = "CheckCode") { + // 检查是否可以发送(一分钟内只能发送一次) + if (!await CanSendCodeAsync(phone)) + { + return ResultOutput.NotOk("请求过于频繁,请稍后再试"); + } + var personList = await _appUserRepository.AsQueryable(false, true).Where(w => w.Phone == phone).ToListAsync(); - var personList = await _appUserRepository.AsQueryable(false, true).Where(w => w.Phone == phone).ToListAsync(); - if (personList.Count == 0) return ResultOutput.NotOk("请检查手机号是否输入正确"); var datalist = await (from a in _appCaseManagementRepository.AsQueryable(false, true) - .Where(w=>w.CaseProgress !=CaseProgressEnum.Closed) + .Where(w => w.CaseProgress != CaseProgressEnum.Closed) join b in _appSupervisedPersonRepository.AsQueryable(false, true) - .Where(w=> personList.Select(s=>s.Id).ToList().Contains(w.SupervisedPersonId)) + .Where(w => personList.Select(s => s.Id).ToList().Contains(w.SupervisedPersonId)) on a.Id equals b.CaseId select new { b.SupervisedPersonId }).ToListAsync(); if (datalist.Count == 0) return ResultOutput.NotOk("该手机号不存在运行中的案件"); @@ -168,7 +169,9 @@ namespace ATS.NonCustodial.Application.Impl.Admins // 生成随机验证码(6位数字) var random = new Random(); var code = random.Next(100000, 999999).ToString(); - var name = personList.Where(w => datalist.Select(s => s.SupervisedPersonId).Contains(w.Id))?.FirstOrDefault().UserName??""; + var name = personList.Where(w => datalist.Select(s => s.SupervisedPersonId).Contains(w.Id))?.FirstOrDefault().UserName ?? ""; + var sendMessage = $"您的验证码为:{code},请于五分钟内填写,若非本人操作,请勿泄露。"; + // 创建验证码记录 var addSMS = new AppSMS { @@ -178,28 +181,30 @@ namespace ATS.NonCustodial.Application.Impl.Admins expiresTime = DateTime.Now.AddMinutes(5), // 5分钟有效期 ipAddress = ipAddress, type = type, - receiver = name + receiver = name, + content = sendMessage }; + var sendResult = SendSmsAsync(sendMessage, phone); // 发送短信 - var sendResult = SendSMS(phone, new string[] { code, "5" }, "2524683"); - addSMS.result = sendResult; + // var sendResult = SendSMS(phone, new string[] { code, "5" }, "2524683"); + addSMS.result = sendResult.Result; var sms = await _appSMSRepository.InsertAsync(addSMS); return ResultOutput.Ok(true); } - /// - /// 用于触发给指定人员发送短信 - /// - /// 短信通知类型 - /// 监管人姓名 - /// 需要通知的电话 - /// 发送的日期 - /// 触发的消息内容(小于等于6个字) - /// - /// 被监管人姓名 - /// - public async Task SendMessageSMS(MessageAlertTypeEnum alert, string supervisor, string phone,DateTime? dateTime, string msg = "", string ipAddress = "",string supervisedPerson = "") + /// + /// 用于触发给指定人员发送短信 + /// + /// 短信通知类型 + /// 监管人姓名 + /// 需要通知的电话 + /// 发送的日期 + /// 触发的消息内容(小于等于6个字) + /// + /// 被监管人姓名 + /// + public async Task SendMessageSMS(MessageAlertTypeEnum alert, string supervisor, string phone, DateTime? dateTime, string msg = "", string ipAddress = "", string supervisedPerson = "") { // 检查是否可以发送(一分钟内只能发送一次) if (!await CanSendCodeAsync(phone)) @@ -214,34 +219,20 @@ namespace ATS.NonCustodial.Application.Impl.Admins expiresTime = DateTime.Now.AddMinutes(5), // 5分钟有效期 ipAddress = ipAddress }; - string[] sendMessage; - string templateId = string.Empty; - string year , month , day ; - if(dateTime.HasValue) - { - year = dateTime.Value.Year.ToString(); - month = dateTime.Value.Month.ToString(); - day = dateTime.Value.Day.ToString(); - } - else - { - year=DateTime.Now.Year.ToString(); - month = DateTime.Now.Month.ToString(); - day = DateTime.Now.Day.ToString(); - } + string sendMessage = string.Empty; + var date = dateTime.HasValue ? dateTime : DateTime.Now; + if (alert == MessageAlertTypeEnum.Alert) { //[预警处理提醒] {1}您好,您于{2}年{3}月{4}日触发的{5}预警需及时处理,请尽快核查并修正相关事项。 - sendMessage = new string[] { supervisedPerson, year, month, day, msg }; - templateId = "2534751"; + sendMessage = $"[预警处理提醒] {supervisedPerson}您好,您于{date}触发的{msg}预警需及时处理,请尽快核查并修正相关事项。"; addSMS.type = "Alert"; addSMS.receiver = supervisedPerson; } else if (alert == MessageAlertTypeEnum.Approved) { //[审批完成通知] {1}您好,您于{2}年{3}月{4}日提交的{5}申请已完成审批,请及时登录系统查看处理结果。 - sendMessage = new string[] { supervisedPerson, year, month, day, msg }; - templateId = "2535130"; + sendMessage = $"[审批完成通知] {supervisedPerson}您好,您于{date}提交的{msg}申请已完成审批,请及时登录系统查看处理结果。"; addSMS.type = "Approved"; addSMS.receiver = supervisedPerson; @@ -249,8 +240,7 @@ namespace ATS.NonCustodial.Application.Impl.Admins else if (alert == MessageAlertTypeEnum.ReviewNotification) { //[待审批提醒] {1}您好,{2}于{3}年{4}月{5}日提交的{6}申请待您审批,请及时处理。 - sendMessage = new string[] { supervisor, supervisedPerson, year, month, day, msg }; - templateId = "2535127"; + sendMessage = $"[待审批提醒] {supervisor}您好,{supervisedPerson}于{date}提交的{msg}申请待您审批,请及时处理。"; addSMS.type = "ReviewNotification"; addSMS.receiver = supervisor; @@ -258,14 +248,15 @@ namespace ATS.NonCustodial.Application.Impl.Admins else { //[监管预警通知] {1}您好,被监管人{2}于{3}年{4}月{5}日已触发{6}预警,请尽快核查处理。 - sendMessage = new string[] { supervisor, supervisedPerson, year, month, day, msg }; - templateId = "2535150"; + sendMessage = $"[监管预警通知] {supervisor}您好,被监管人{supervisedPerson}于{date}已触发{msg}预警,请尽快核查处理。"; addSMS.type = "RegulatoryAlert"; addSMS.receiver = supervisor; } // 发送短信 - var sendResult = SendSMS(phone, sendMessage, templateId); - addSMS.result = sendResult; + var sendResult = SendSmsAsync(sendMessage, phone); + addSMS.result = sendResult.Result; + addSMS.content = sendMessage; + //发送记录入库 var sms = await _appSMSRepository.InsertAsync(addSMS); @@ -332,6 +323,120 @@ namespace ATS.NonCustodial.Application.Impl.Admins #region Private + + + /// + /// 发送短信接口 + /// + /// 短信内容 + /// 电话号码 + /// 接口返回消息 + public async Task SendSmsAsync(string content, string phone) + { + try + { + + var smsConfig = LazyGetRequiredService(); + var signName = await GetDictionariesOutput("sms_config", "SignName"); + var feeType = await GetDictionariesOutput("sms_config", "FeeType"); + var baseUrl = await GetDictionariesOutput("sms_config", "BaseUrl"); + var pwd = await GetDictionariesOutput("sms_config", "Pwd"); + var loginName = await GetDictionariesOutput("sms_config", "LoginName"); + + var parameters = new SmsParameters() + { + Pwd = pwd.Value ?? smsConfig.Pwd, + Content = content, + FeeType = feeType.Value ?? smsConfig.FeeType, + LoginName = loginName.Value ?? smsConfig.LoginName, + SignName = signName.Value ?? smsConfig.SignName, + Mobile = phone + }; + + // 构建查询字符串 + var queryString = BuildQueryString(parameters); + var requestUrl = $"{baseUrl.Value ?? smsConfig.BaseUrl}?{queryString}"; + + // 发送HTTP GET请求 + var response = await _httpClient.GetAsync(requestUrl); + + // 确保响应成功 + response.EnsureSuccessStatusCode(); + + // 读取响应内容 + return await response.Content.ReadAsStringAsync(); + } + catch (HttpRequestException ex) + { + throw new Exception($"HTTP请求失败: {ex.Message}", ex); + } + catch (TaskCanceledException ex) + { + throw new Exception($"请求超时: {ex.Message}", ex); + } + catch (Exception ex) + { + throw new Exception($"发送短信失败: {ex.Message}", ex); + } + } + + /// + /// 构建查询字符串参数 + /// + private string BuildQueryString(SmsParameters parameters) + { + var query = HttpUtility.ParseQueryString(string.Empty); + + query["LoginName"] = parameters.LoginName ?? ""; + query["Pwd"] = parameters.Pwd ?? ""; + query["FeeType"] = parameters.FeeType ?? ""; + query["Mobile"] = parameters.Mobile ?? ""; + query["Content"] = parameters.Content ?? ""; + query["SignName"] = parameters.SignName ?? ""; + query["TimingDate"] = parameters.TimingDate ?? ""; + query["ExtCode"] = parameters.ExtCode ?? ""; + + return query.ToString(); + } + + /// + /// 带重试机制的发送方法 + /// + public async Task SendSmsWithRetryAsync(string phone, string content, int maxRetries = 3) + { + for (int i = 0; i < maxRetries; i++) + { + try + { + return await SendSmsAsync(content, phone); + } + catch (Exception ex) when (i < maxRetries - 1) + { + Console.WriteLine($"第{i + 1}次尝试失败: {ex.Message}"); + await Task.Delay(1000 * (i + 1)); // 递增延迟 + } + } + + throw new Exception($"发送短信失败,已重试{maxRetries}次"); + } + /// + /// 根据字典类型Code和字典Code获取字典数据 + /// + /// 字典类型Code + /// 字典Code + /// + private async Task GetDictionariesOutput(string dicTypeCode, string dicCode) + { + var dataDict = await _appDictionaryService.GetListNoApiAsync(null); + + //被监管人职位字典 + var dicData = dataDict + .FirstOrDefault(w => w.Code == dicTypeCode)?.Dictionaries! + .FirstOrDefault(w => w.Code == dicCode); + + //返回数据 + return dicData; + } /// /// 发送短信 ///【审批完成通知】 @@ -347,89 +452,103 @@ namespace ATS.NonCustodial.Application.Impl.Admins /// 消息列表 /// 模版编号 /// - private string SendSMS(string phone, string[] messages, string templateId) - { - try - { - var smsConfig = LazyGetRequiredService(); - // 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY - // 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性 - // 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等 - // 请参见:https://cloud.tencent.com/document/product/1278/85305 - // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 - Credential cred = new Credential - { - SecretId = smsConfig.SecretId,// "AKID52ovuoUzINL7g2A4mGYdHhtsfGdmhQv8", - SecretKey = smsConfig.SecretKey// "96qPlxzta3JL9j5D7oHWXN6f9D9sOiog" - }; - // 使用临时密钥示例 - /* - Credential cred = new Credential { - SecretId = "SecretId", - SecretKey = "SecretKey", - Token = "Token" - }; - */ - // 实例化一个client选项,可选的,没有特殊需求可以跳过 - ClientProfile clientProfile = new ClientProfile(); - // 实例化一个http选项,可选的,没有特殊需求可以跳过 - HttpProfile httpProfile = new HttpProfile(); - //"sms.tencentcloudapi.com" - httpProfile.Endpoint = (smsConfig.Endpoint); - clientProfile.HttpProfile = httpProfile; - - // 实例化要请求产品的client对象,clientProfile是可选的 - //Region = "ap-guangzhou" - SmsClient client = new SmsClient(cred, smsConfig.Region , clientProfile); - // 实例化一个请求对象,每个接口都会对应一个request对象 - SendSmsRequest req = new SendSmsRequest(); - - /* 基本类型的设置: - * SDK采用的是指针风格指定参数,即使对于基本类型您也需要用指针来对参数赋值。 - * SDK提供对基本类型的指针引用封装函数 - * 帮助链接: - * 短信控制台: https://console.cloud.tencent.com/smsv2 - * 腾讯云短信小助手: https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81 */ - /* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */ - // 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看 - req.SmsSdkAppId = smsConfig.SmsSdkAppId;// "1401039888"; - - /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */ - // 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看 - req.SignName = smsConfig.SignName;// "成都阿凯思信息技术"; - - /* 模板 ID: 必须填写已审核通过的模板 ID */ - // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看 - req.TemplateId = templateId;// "2524683"; - - /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ - req.TemplateParamSet = messages;// new string[] { msg, expires.ToString() }; - - /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] - * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/ - req.PhoneNumberSet = new string[] { smsConfig.PhoneNumberSet + phone }; - - /* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */ - req.SessionContext = ""; - - /* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */ - req.ExtendCode = ""; - - /* 国内短信无需填写该项;国际/港澳台短信已申请独立 SenderId 需要填写该字段,默认使用公共 SenderId,无需填写该字段。注:月度使用量达到指定量级可申请独立 SenderId 使用,详情请联系 [腾讯云短信小助手](https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81)。 */ - req.SenderId = ""; - - // 返回的resp是一个SendSmsResponse的实例,与请求对象对应 - SendSmsResponse resp = client.SendSmsSync(req); - - // 输出json格式的字符串回包 - return AbstractModel.ToJsonString(resp); - } - catch (Exception ex) - { - return ex.Message; - } - } + //private string SendSMS(string phone, string[] messages, string templateId) + //{ + // try + // { + // var smsConfig = LazyGetRequiredService(); + // // 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY + // // 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性 + // // 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等 + // // 请参见:https://cloud.tencent.com/document/product/1278/85305 + // // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 + // Credential cred = new Credential + // { + // SecretId = smsConfig.SecretId,// "AKID52ovuoUzINL7g2A4mGYdHhtsfGdmhQv8", + // SecretKey = smsConfig.SecretKey// "96qPlxzta3JL9j5D7oHWXN6f9D9sOiog" + // }; + // // 使用临时密钥示例 + // /* + // Credential cred = new Credential { + // SecretId = "SecretId", + // SecretKey = "SecretKey", + // Token = "Token" + // }; + // */ + // // 实例化一个client选项,可选的,没有特殊需求可以跳过 + // ClientProfile clientProfile = new ClientProfile(); + // // 实例化一个http选项,可选的,没有特殊需求可以跳过 + // HttpProfile httpProfile = new HttpProfile(); + // //"sms.tencentcloudapi.com" + // httpProfile.Endpoint = (smsConfig.Endpoint); + // clientProfile.HttpProfile = httpProfile; + + // // 实例化要请求产品的client对象,clientProfile是可选的 + // //Region = "ap-guangzhou" + // SmsClient client = new SmsClient(cred, smsConfig.Region , clientProfile); + // // 实例化一个请求对象,每个接口都会对应一个request对象 + // SendSmsRequest req = new SendSmsRequest(); + + // /* 基本类型的设置: + // * SDK采用的是指针风格指定参数,即使对于基本类型您也需要用指针来对参数赋值。 + // * SDK提供对基本类型的指针引用封装函数 + // * 帮助链接: + // * 短信控制台: https://console.cloud.tencent.com/smsv2 + // * 腾讯云短信小助手: https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81 */ + // /* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */ + // // 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看 + // req.SmsSdkAppId = smsConfig.SmsSdkAppId;// "1401039888"; + + // /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */ + // // 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看 + // req.SignName = smsConfig.SignName;// "成都阿凯思信息技术"; + + // /* 模板 ID: 必须填写已审核通过的模板 ID */ + // // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看 + // req.TemplateId = templateId;// "2524683"; + + // /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ + // req.TemplateParamSet = messages;// new string[] { msg, expires.ToString() }; + + // /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] + // * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/ + // req.PhoneNumberSet = new string[] { smsConfig.PhoneNumberSet + phone }; + + // /* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */ + // req.SessionContext = ""; + + // /* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */ + // req.ExtendCode = ""; + + // /* 国内短信无需填写该项;国际/港澳台短信已申请独立 SenderId 需要填写该字段,默认使用公共 SenderId,无需填写该字段。注:月度使用量达到指定量级可申请独立 SenderId 使用,详情请联系 [腾讯云短信小助手](https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81)。 */ + // req.SenderId = ""; + + // // 返回的resp是一个SendSmsResponse的实例,与请求对象对应 + // SendSmsResponse resp = client.SendSmsSync(req); + + // // 输出json格式的字符串回包 + // return AbstractModel.ToJsonString(resp); + // } + // catch (Exception ex) + // { + // return ex.Message; + // } + //} #endregion } + /// + /// 短信接口参数类 + /// + public class SmsParameters + { + public string LoginName { get; set; } + public string Pwd { get; set; } + public string FeeType { get; set; } + public string Mobile { get; set; } + public string Content { get; set; } + public string SignName { get; set; } + public string TimingDate { get; set; } + public string ExtCode { get; set; } + } } diff --git a/src/2.services/ATS.NonCustodial.Application/Impl/Business/AppEarlyWarningService.cs b/src/2.services/ATS.NonCustodial.Application/Impl/Business/AppEarlyWarningService.cs index c42ec81..3cc92d2 100644 --- a/src/2.services/ATS.NonCustodial.Application/Impl/Business/AppEarlyWarningService.cs +++ b/src/2.services/ATS.NonCustodial.Application/Impl/Business/AppEarlyWarningService.cs @@ -167,11 +167,11 @@ namespace ATS.NonCustodial.Application.Impl.Business { var supervisor = await _appUserRepository.AsQueryable(false, true).Where(w => w.Id == item.SupervisorId).ToListAsync(); //发短信给监管人,提醒被监管人脱离监管区域 - await _smsService.SendMessageSMS(MessageAlertTypeEnum.RegulatoryAlert, supervisor.FirstOrDefault().UserName, supervisor.FirstOrDefault().Phone, DateTime.Now, dictionaryGetOutput.Name.Length>6 ? dictionaryGetOutput.Name.Substring(0,6) : dictionaryGetOutput.Name, "", caseInfo.SupervisedPersonName); + await _smsService.SendMessageSMS(MessageAlertTypeEnum.RegulatoryAlert, supervisor.FirstOrDefault().UserName, supervisor.FirstOrDefault().Phone, DateTime.Now, dictionaryGetOutput.Name, "", caseInfo.SupervisedPersonName); } //通知被监管人 var supervisedPerson = await _appUserRepository.AsQueryable(false, true).Where(w => w.Id == input.SupervisedPersonId).ToListAsync(); - await _smsService.SendMessageSMS(MessageAlertTypeEnum.Alert, "", supervisedPerson.FirstOrDefault().Phone, DateTime.Now, dictionaryGetOutput.Name.Length > 6 ? dictionaryGetOutput.Name.Substring(0, 6) : dictionaryGetOutput.Name, "", caseInfo.SupervisedPersonName); + await _smsService.SendMessageSMS(MessageAlertTypeEnum.Alert, "", supervisedPerson.FirstOrDefault().Phone, DateTime.Now, dictionaryGetOutput.Name, "", caseInfo.SupervisedPersonName); #endregion //公共逻辑 diff --git a/src/4.apps/ATS.NonCustodial.Admin.Api/appsettings.json b/src/4.apps/ATS.NonCustodial.Admin.Api/appsettings.json index 7131347..0e9c790 100644 --- a/src/4.apps/ATS.NonCustodial.Admin.Api/appsettings.json +++ b/src/4.apps/ATS.NonCustodial.Admin.Api/appsettings.json @@ -10,8 +10,8 @@ //连接字符�? "ConnectionStringsConfiguration": { - "AdminAuditLogDbConnection": "Server=localhost;database=fjy_sl;uid=root;pwd=sa@admin;pooling=true;CharSet=utf8;port=3306;SslMode=none;Allow User Variables=True;AllowPublicKeyRetrieval=True;", - "AdminDbConnection": "Server=localhost;database=fjy_sl;uid=root;pwd=sa@admin;pooling=true;CharSet=utf8;port=3306;SslMode=none;Allow User Variables=True;AllowPublicKeyRetrieval=True;" + "AdminAuditLogDbConnection": "Server=localhost;database=fsl_cs;uid=root;pwd=sa@admin;pooling=true;CharSet=utf8;port=3306;SslMode=none;Allow User Variables=True;AllowPublicKeyRetrieval=True;", + "AdminDbConnection": "Server=localhost;database=fsl_cs;uid=root;pwd=sa@admin;pooling=true;CharSet=utf8;port=3306;SslMode=none;Allow User Variables=True;AllowPublicKeyRetrieval=True;" }, "DatabaseProviderConfiguration": { "ProviderType": "MySql" diff --git a/src/4.apps/ATS.NonCustodial.Admin.Api/configs/appsettings.json b/src/4.apps/ATS.NonCustodial.Admin.Api/configs/appsettings.json index 583fbb8..b2fcbd1 100644 --- a/src/4.apps/ATS.NonCustodial.Admin.Api/configs/appsettings.json +++ b/src/4.apps/ATS.NonCustodial.Admin.Api/configs/appsettings.json @@ -257,21 +257,15 @@ }, //短信平台推送 "SmsConfiguration": { - // 请参见:https://cloud.tencent.com/document/product/1278/85305 - // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 - "SecretId": "AKID52ovuoUzINL7g2A4mGYdHhtsfGdmhQv8", - "SecretKey": "96qPlxzta3JL9j5D7oHWXN6f9D9sOiog", - //默认腾讯云 - "Endpoint": "sms.tencentcloudapi.com", - //Region name, such as "ap-guangzhou" - "Region": "ap-guangzhou", - //短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 - "SmsSdkAppId": "1401039888", - //短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 - "SignName": "成都阿凯思信息技术", - // 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] - //示例如:+8613711112222, 其中前面有一个+号 , - //86为国家码,13711112222为手机号,最多不要超过200个手机号 - "PhoneNumberSet": "+86" + //账户名(企业登录名) + "LoginName": "DSCJKCSZH", + //密码(企业账号对应密码) + "Pwd": "Scmf@000731", + //默认地址 + "BaseUrl": "https://dxsdk.028lk.com:8082/Api/SendSms", + //计费套餐类型 2 为行业套餐 3 为政务套餐 + "FeeType": "2", + //短信签名内容:(如果账号绑定了自定义签名,要使用自定义签名这里必须传入自定义签名,并做Urlencode的UTF-8编码) + "SignName": "【灵讯通】" } } \ No newline at end of file diff --git a/src/5.shared/ATS.NonCustodial.Shared/Configurations/Options/SmsConfiguration.cs b/src/5.shared/ATS.NonCustodial.Shared/Configurations/Options/SmsConfiguration.cs index 3a3b08d..3d2b0af 100644 --- a/src/5.shared/ATS.NonCustodial.Shared/Configurations/Options/SmsConfiguration.cs +++ b/src/5.shared/ATS.NonCustodial.Shared/Configurations/Options/SmsConfiguration.cs @@ -8,20 +8,14 @@ namespace ATS.NonCustodial.Shared.Configurations.Options { public class SmsConfiguration { - public string SecretId { get; set; } + public string LoginName { get; set; } - public string SecretKey { get; set; } + public string Pwd { get; set; } - public string Endpoint { get; set; } + public string BaseUrl { get; set; } - public string Region { get; set; } + public string FeeType { get; set; } - public string SmsSdkAppId { get; set; } - /// - /// 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 - /// public string SignName { get; set; } - - public string PhoneNumberSet { get; set; } } }