@ -1,13 +1,11 @@
using ATS.NonCustodial.Application.Base ;
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 ;
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.SMS.Input ;
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.SMS.Input ;
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.SMS.Output ;
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.Admins ;
using ATS.NonCustodial.Domain.Entities.Business.CaseManagements ;
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.Enums ;
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore ;
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore ;
using ATS.NonCustodial.DynamicApi ;
using ATS.NonCustodial.DynamicApi ;
@ -19,10 +17,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.EntityFrameworkCore ;
using Microsoft.EntityFrameworkCore ;
using StackExchange.Profiling.Internal ;
using StackExchange.Profiling.Internal ;
using TencentCloud.Common ;
using System.Web ;
using TencentCloud.Common.Profile ;
using TencentCloud.Sms.V20210111 ;
using TencentCloud.Sms.V20210111.Models ;
namespace ATS.NonCustodial.Application.Impl.Admins
namespace ATS.NonCustodial.Application.Impl.Admins
{
{
@ -36,15 +31,31 @@ namespace ATS.NonCustodial.Application.Impl.Admins
private readonly IEfRepository < AppUser , long > _ appUserRepository ;
private readonly IEfRepository < AppUser , long > _ appUserRepository ;
protected readonly IEfRepository < AppCaseManagement , long > _ appCaseManagementRepository ;
protected readonly IEfRepository < AppCaseManagement , long > _ appCaseManagementRepository ;
protected readonly IEfRepository < AppCaseSupervisedPerson , long > _ appSupervisedPersonRepository ;
protected readonly IEfRepository < AppCaseSupervisedPerson , long > _ appSupervisedPersonRepository ;
private readonly HttpClient _ httpClient ;
protected readonly IAppDictionaryService _ appDictionaryService ;
public SMSService ( IEfRepository < AppCaseManagement , long > appCaseManagementRepository ,
public SMSService ( IEfRepository < AppCaseManagement , long > appCaseManagementRepository ,
IEfRepository < AppCaseSupervisedPerson , long > appSupervisedPersonRepository ,
IEfRepository < AppCaseSupervisedPerson , long > appSupervisedPersonRepository ,
IEfRepository < AppSMS ? , long > appSMSRepository ,
IEfRepository < AppSMS ? , long > appSMSRepository ,
IAppDictionaryService appDictionaryService ,
IEfRepository < AppUser , long > appUserRepository )
IEfRepository < AppUser , long > appUserRepository )
{
{
_ appSMSRepository = appSMSRepository ;
_ appSMSRepository = appSMSRepository ;
_ appUserRepository = appUserRepository ;
_ appUserRepository = appUserRepository ;
_ appCaseManagementRepository = appCaseManagementRepository ;
_ appCaseManagementRepository = appCaseManagementRepository ;
_ appSupervisedPersonRepository = appSupervisedPersonRepository ;
_ appSupervisedPersonRepository = appSupervisedPersonRepository ;
_ appDictionaryService = appDictionaryService ;
// 配置HttpClient,忽略SSL证书验证(仅用于测试环境)
var handler = new HttpClientHandler ( )
{
ServerCertificateCustomValidationCallback = ( message , cert , chain , errors ) = > true
} ;
_ httpClient = new HttpClient ( handler ) ;
_ httpClient . Timeout = TimeSpan . FromSeconds ( 3 0 ) ;
}
}
@ -62,8 +73,8 @@ namespace ATS.NonCustodial.Application.Impl.Admins
// .ToListAsync();
// .ToListAsync();
//var caseIdList = selectLimits.Select(w => w.CaseId).Distinct().ToList();
//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 < AppSMS , SmsGetpageInput , SmsListDto > ( input , express ) ;
var rtn = await base . GetPageAsync < AppSMS , SmsGetpageInput , SmsListDto > ( input , express ) ;
@ -86,35 +97,21 @@ namespace ATS.NonCustodial.Application.Impl.Admins
default :
default :
break ;
break ;
}
}
if ( item . Result . Contains ( "Code ") )
if ( item . Result . Split ( "|" ) [ 0 ] . Equals ( "OK ") )
{
{
int codeStart = item . Result . IndexOf ( "\"Code\":\"" ) + 8 ;
item . Message = item . Result ;
int codeEnd = item . Result . IndexOf ( "\"" , codeStart ) ;
item . Result = "短信发送成功" ;
string code = item . Result . Substring ( codeStart , codeEnd - codeStart ) ;
int msgStart = item . Result . IndexOf ( "\"Message\":\"" ) + 1 1 ;
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 = "短信发送异常" ;
}
}
}
else
else
{
{
item . Message = item . Result ;
item . Message = item . Result ;
item . Result = "短信发送异常" ;
item . Result = "短信发送异常" ;
}
}
}
}
var filteredList = rtn . Data
var filteredList = rtn . Data
. WhereIf ( input . Name . HasValue ( ) , item = > item . Name = = input . Name ) // 筛选条件
. WhereIf ( input . Name . HasValue ( ) , item = > item . Name = = input . Name ) // 筛选条件
. ToList ( ) ;
. ToList ( ) ;
rtn . Data = filteredList ;
rtn . Data = filteredList ;
return ResultOutput . Ok ( rtn ) ;
return ResultOutput . Ok ( rtn ) ;
@ -145,16 +142,20 @@ namespace ATS.NonCustodial.Application.Impl.Admins
[AllowAnonymous]
[AllowAnonymous]
public async Task < IResultOutput > SendCheckCodeSMS ( string phone , string ipAddress = "" , string type = "CheckCode" )
public async Task < IResultOutput > 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 ( "请检查手机号是否输入正确" ) ;
if ( personList . Count = = 0 ) return ResultOutput . NotOk ( "请检查手机号是否输入正确" ) ;
var datalist = await ( from a in _ appCaseManagementRepository . AsQueryable ( false , true )
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 )
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
on a . Id equals b . CaseId
select new { b . SupervisedPersonId } ) . ToListAsync ( ) ;
select new { b . SupervisedPersonId } ) . ToListAsync ( ) ;
if ( datalist . Count = = 0 ) return ResultOutput . NotOk ( "该手机号不存在运行中的案件" ) ;
if ( datalist . Count = = 0 ) return ResultOutput . NotOk ( "该手机号不存在运行中的案件" ) ;
@ -168,7 +169,9 @@ namespace ATS.NonCustodial.Application.Impl.Admins
// 生成随机验证码(6位数字)
// 生成随机验证码(6位数字)
var random = new Random ( ) ;
var random = new Random ( ) ;
var code = random . Next ( 1 0 0 0 0 0 , 9 9 9 9 9 9 ) . ToString ( ) ;
var code = random . Next ( 1 0 0 0 0 0 , 9 9 9 9 9 9 ) . 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
var addSMS = new AppSMS
{
{
@ -178,28 +181,30 @@ namespace ATS.NonCustodial.Application.Impl.Admins
expiresTime = DateTime . Now . AddMinutes ( 5 ) , // 5分钟有效期
expiresTime = DateTime . Now . AddMinutes ( 5 ) , // 5分钟有效期
ipAddress = ipAddress ,
ipAddress = ipAddress ,
type = type ,
type = type ,
receiver = name
receiver = name ,
content = sendMessage
} ;
} ;
var sendResult = SendSmsAsync ( sendMessage , phone ) ;
// 发送短信
// 发送短信
var sendResult = SendSMS ( phone , new string [ ] { code , "5" } , "2524683" ) ;
// var sendResult = SendSMS(phone, new string[] { code, "5" }, "2524683") ;
addSMS . result = sendResult ;
addSMS . result = sendResult . Result ;
var sms = await _ appSMSRepository . InsertAsync ( addSMS ) ;
var sms = await _ appSMSRepository . InsertAsync ( addSMS ) ;
return ResultOutput . Ok ( true ) ;
return ResultOutput . Ok ( true ) ;
}
}
/// <summary>
/// <summary>
/// 用于触发给指定人员发送短信
/// 用于触发给指定人员发送短信
/// </summary>
/// </summary>
/// <param name="alert">短信通知类型</param>
/// <param name="alert">短信通知类型</param>
/// <param name="supervisor">监管人姓名</param>
/// <param name="supervisor">监管人姓名</param>
/// <param name="phone">需要通知的电话</param>
/// <param name="phone">需要通知的电话</param>
/// <param name="dateTime">发送的日期</param>
/// <param name="dateTime">发送的日期</param>
/// <param name="msg">触发的消息内容(小于等于6个字)</param>
/// <param name="msg">触发的消息内容(小于等于6个字)</param>
/// <param name="ipAddress"></param>
/// <param name="ipAddress"></param>
/// <param name="supervisedPerson">被监管人姓名</param>
/// <param name="supervisedPerson">被监管人姓名</param>
/// <returns></returns>
/// <returns></returns>
public async Task < IResultOutput > SendMessageSMS ( MessageAlertTypeEnum alert , string supervisor , string phone , DateTime ? dateTime , string msg = "" , string ipAddress = "" , string supervisedPerson = "" )
public async Task < IResultOutput > SendMessageSMS ( MessageAlertTypeEnum alert , string supervisor , string phone , DateTime ? dateTime , string msg = "" , string ipAddress = "" , string supervisedPerson = "" )
{
{
// 检查是否可以发送(一分钟内只能发送一次)
// 检查是否可以发送(一分钟内只能发送一次)
if ( ! await CanSendCodeAsync ( phone ) )
if ( ! await CanSendCodeAsync ( phone ) )
@ -214,34 +219,20 @@ namespace ATS.NonCustodial.Application.Impl.Admins
expiresTime = DateTime . Now . AddMinutes ( 5 ) , // 5分钟有效期
expiresTime = DateTime . Now . AddMinutes ( 5 ) , // 5分钟有效期
ipAddress = ipAddress
ipAddress = ipAddress
} ;
} ;
string [ ] sendMessage ;
string sendMessage = string . Empty ;
string templateId = string . Empty ;
var date = dateTime . HasValue ? dateTime : DateTime . Now ;
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 ( ) ;
}
if ( alert = = MessageAlertTypeEnum . Alert )
if ( alert = = MessageAlertTypeEnum . Alert )
{
{
//[预警处理提醒] {1}您好,您于{2}年{3}月{4}日触发的{5}预警需及时处理,请尽快核查并修正相关事项。
//[预警处理提醒] {1}您好,您于{2}年{3}月{4}日触发的{5}预警需及时处理,请尽快核查并修正相关事项。
sendMessage = new string [ ] { supervisedPerson , year , month , day , msg } ;
sendMessage = $"[预警处理提醒] {supervisedPerson}您好,您于{date}触发的{msg}预警需及时处理,请尽快核查并修正相关事项。" ;
templateId = "2534751" ;
addSMS . type = "Alert" ;
addSMS . type = "Alert" ;
addSMS . receiver = supervisedPerson ;
addSMS . receiver = supervisedPerson ;
}
}
else if ( alert = = MessageAlertTypeEnum . Approved )
else if ( alert = = MessageAlertTypeEnum . Approved )
{
{
//[审批完成通知] {1}您好,您于{2}年{3}月{4}日提交的{5}申请已完成审批,请及时登录系统查看处理结果。
//[审批完成通知] {1}您好,您于{2}年{3}月{4}日提交的{5}申请已完成审批,请及时登录系统查看处理结果。
sendMessage = new string [ ] { supervisedPerson , year , month , day , msg } ;
sendMessage = $"[审批完成通知] {supervisedPerson}您好,您于{date}提交的{msg}申请已完成审批,请及时登录系统查看处理结果。" ;
templateId = "2535130" ;
addSMS . type = "Approved" ;
addSMS . type = "Approved" ;
addSMS . receiver = supervisedPerson ;
addSMS . receiver = supervisedPerson ;
@ -249,8 +240,7 @@ namespace ATS.NonCustodial.Application.Impl.Admins
else if ( alert = = MessageAlertTypeEnum . ReviewNotification )
else if ( alert = = MessageAlertTypeEnum . ReviewNotification )
{
{
//[待审批提醒] {1}您好,{2}于{3}年{4}月{5}日提交的{6}申请待您审批,请及时处理。
//[待审批提醒] {1}您好,{2}于{3}年{4}月{5}日提交的{6}申请待您审批,请及时处理。
sendMessage = new string [ ] { supervisor , supervisedPerson , year , month , day , msg } ;
sendMessage = $"[待审批提醒] {supervisor}您好,{supervisedPerson}于{date}提交的{msg}申请待您审批,请及时处理。" ;
templateId = "2535127" ;
addSMS . type = "ReviewNotification" ;
addSMS . type = "ReviewNotification" ;
addSMS . receiver = supervisor ;
addSMS . receiver = supervisor ;
@ -258,14 +248,15 @@ namespace ATS.NonCustodial.Application.Impl.Admins
else
else
{
{
//[监管预警通知] {1}您好,被监管人{2}于{3}年{4}月{5}日已触发{6}预警,请尽快核查处理。
//[监管预警通知] {1}您好,被监管人{2}于{3}年{4}月{5}日已触发{6}预警,请尽快核查处理。
sendMessage = new string [ ] { supervisor , supervisedPerson , year , month , day , msg } ;
sendMessage = $"[监管预警通知] {supervisor}您好,被监管人{supervisedPerson}于{date}已触发{msg}预警,请尽快核查处理。" ;
templateId = "2535150" ;
addSMS . type = "RegulatoryAlert" ;
addSMS . type = "RegulatoryAlert" ;
addSMS . receiver = supervisor ;
addSMS . receiver = supervisor ;
}
}
// 发送短信
// 发送短信
var sendResult = SendSMS ( phone , sendMessage , templateId ) ;
var sendResult = SendSmsAsync ( sendMessage , phone ) ;
addSMS . result = sendResult ;
addSMS . result = sendResult . Result ;
addSMS . content = sendMessage ;
//发送记录入库
//发送记录入库
var sms = await _ appSMSRepository . InsertAsync ( addSMS ) ;
var sms = await _ appSMSRepository . InsertAsync ( addSMS ) ;
@ -332,6 +323,120 @@ namespace ATS.NonCustodial.Application.Impl.Admins
#region Private
#region Private
/// <summary>
/// 发送短信接口
/// </summary>
/// <param name="content">短信内容</param>
/// <param name="phone">电话号码</param>
/// <returns>接口返回消息</returns>
public async Task < string > SendSmsAsync ( string content , string phone )
{
try
{
var smsConfig = LazyGetRequiredService < SmsConfiguration > ( ) ;
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 ) ;
}
}
/// <summary>
/// 构建查询字符串参数
/// </summary>
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 ( ) ;
}
/// <summary>
/// 带重试机制的发送方法
/// </summary>
public async Task < string > 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 ( 1 0 0 0 * ( i + 1 ) ) ; // 递增延迟
}
}
throw new Exception ( $"发送短信失败,已重试{maxRetries}次" ) ;
}
/// <summary>
/// 根据字典类型Code和字典Code获取字典数据
/// </summary>
/// <param name="dicTypeCode">字典类型Code</param>
/// <param name="dicCode">字典Code</param>
/// <returns></returns>
private async Task < DictionaryGetOutput > 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 ;
}
/// <summary>
/// <summary>
/// 发送短信
/// 发送短信
///【审批完成通知】
///【审批完成通知】
@ -347,89 +452,103 @@ namespace ATS.NonCustodial.Application.Impl.Admins
/// <param name="messages">消息列表</param>
/// <param name="messages">消息列表</param>
/// <param name="templateId">模版编号</param>
/// <param name="templateId">模版编号</param>
/// <returns></returns>
/// <returns></returns>
private string SendSMS ( string phone , string [ ] messages , string templateId )
//private string SendSMS(string phone, string[] messages, string templateId )
{
// {
try
// try
{
// {
var smsConfig = LazyGetRequiredService < SmsConfiguration > ( ) ;
// var smsConfig = LazyGetRequiredService<SmsConfiguration>() ;
// 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY
// // 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY
// 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性
// // 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性
// 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等
// // 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等
// 请参见:https://cloud.tencent.com/document/product/1278/85305
// // 请参见:https://cloud.tencent.com/document/product/1278/85305
// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
// // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
Credential cred = new Credential
// Credential cred = new Credential
{
// {
SecretId = smsConfig . SecretId , // "AKID52ovuoUzINL7g2A4mGYdHhtsfGdmhQv8",
// SecretId = smsConfig.SecretId, // "AKID52ovuoUzINL7g2A4mGYdHhtsfGdmhQv8",
SecretKey = smsConfig . SecretKey // "96qPlxzta3JL9j5D7oHWXN6f9D9sOiog"
// SecretKey = smsConfig.SecretKey // "96qPlxzta3JL9j5D7oHWXN6f9D9sOiog"
} ;
// } ;
// 使用临时密钥示例
// // 使用临时密钥示例
/ *
// / *
Credential cred = new Credential {
// Credential cred = new Credential {
SecretId = "SecretId" ,
// SecretId = "SecretId" ,
SecretKey = "SecretKey" ,
// SecretKey = "SecretKey" ,
Token = "Token"
// Token = "Token"
} ;
// } ;
* /
// * /
// 实例化一个client选项,可选的,没有特殊需求可以跳过
// // 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile ( ) ;
// ClientProfile clientProfile = new ClientProfile() ;
// 实例化一个http选项,可选的,没有特殊需求可以跳过
// // 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile ( ) ;
// HttpProfile httpProfile = new HttpProfile() ;
//"sms.tencentcloudapi.com"
// //"sms.tencentcloudapi.com"
httpProfile . Endpoint = ( smsConfig . Endpoint ) ;
// httpProfile.Endpoint = (smsConfig.Endpoint) ;
clientProfile . HttpProfile = httpProfile ;
// clientProfile.HttpProfile = httpProfile ;
// 实例化要请求产品的client对象,clientProfile是可选的
// // 实例化要请求产品的client对象,clientProfile是可选的
//Region = "ap-guangzhou"
// //Region = "ap-guangzhou"
SmsClient client = new SmsClient ( cred , smsConfig . Region , clientProfile ) ;
// SmsClient client = new SmsClient(cred, smsConfig.Region , clientProfile) ;
// 实例化一个请求对象,每个接口都会对应一个request对象
// // 实例化一个请求对象,每个接口都会对应一个request对象
SendSmsRequest req = new SendSmsRequest ( ) ;
// SendSmsRequest req = new SendSmsRequest() ;
/ * 基 本 类 型 的 设 置 :
// /* 基本类型的设置 :
* SDK采用的是指针风格指定参数 , 即 使 对 于 基 本 类 型 您 也 需 要 用 指 针 来 对 参 数 赋 值 。
// * SDK采用的是指针风格指定参数,即使对于基本类型您也需要用指针来对参数赋值 。
* SDK提供对基本类型的指针引用封装函数
// * SDK提供对基本类型的指针引用封装函数
* 帮 助 链 接 :
// * 帮助链接 :
* 短 信 控 制 台 : https : //console.cloud.tencent.com/smsv2
// * 短信控制台: 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 */
// * 腾讯云短信小助手: 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: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */
// 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看
// // 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看
req . SmsSdkAppId = smsConfig . SmsSdkAppId ; // "1401039888";
// req.SmsSdkAppId = smsConfig.SmsSdkAppId; // "1401039888";
/* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */
// /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */
// 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看
// // 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看
req . SignName = smsConfig . SignName ; // "成都阿凯思信息技术";
// req.SignName = smsConfig.SignName; // "成都阿凯思信息技术";
/* 模板 ID: 必须填写已审核通过的模板 ID */
// /* 模板 ID: 必须填写已审核通过的模板 ID */
// 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看
// // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看
req . TemplateId = templateId ; // "2524683";
// req.TemplateId = templateId; // "2524683";
/* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */
// /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */
req . TemplateParamSet = messages ; // new string[] { msg, expires.ToString() };
// req.TemplateParamSet = messages; // new string[] { msg, expires.ToString() };
/ * 下 发 手 机 号 码 , 采 用 E . 1 6 4 标 准 , + [ 国 家 或 地 区 码 ] [ 手 机 号 ]
// /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号 ]
* 示 例 如 : + 8 6 1 3 7 1 1 1 1 2 2 2 2 , 其 中 前 面 有 一 个 + 号 , 8 6 为 国 家 码 , 1 3 7 1 1 1 1 2 2 2 2 为 手 机 号 , 最 多 不 要 超 过 2 0 0 个 手 机 号 * /
// * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号* /
req . PhoneNumberSet = new string [ ] { smsConfig . PhoneNumberSet + phone } ;
// req.PhoneNumberSet = new string[] { smsConfig.PhoneNumberSet + phone } ;
/* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
// /* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
req . SessionContext = "" ;
// req.SessionContext = "" ;
/* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */
// /* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */
req . ExtendCode = "" ;
// 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)。 */
// /* 国内短信无需填写该项;国际/港澳台短信已申请独立 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 = "" ;
// req.SenderId = "" ;
// 返回的resp是一个SendSmsResponse的实例,与请求对象对应
// // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
SendSmsResponse resp = client . SendSmsSync ( req ) ;
// SendSmsResponse resp = client.SendSmsSync(req) ;
// 输出json格式的字符串回包
// // 输出json格式的字符串回包
return AbstractModel . ToJsonString ( resp ) ;
// return AbstractModel.ToJsonString(resp) ;
}
// }
catch ( Exception ex )
// catch (Exception ex )
{
// {
return ex . Message ;
// return ex.Message ;
}
// }
}
// }
# endregion
# endregion
}
}
/// <summary>
/// 短信接口参数类
/// </summary>
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 ; }
}
}
}