更新SMS配置
This commit is contained in:
parent
d47b38c155
commit
4c43f221a0
@ -5,15 +5,33 @@
|
|||||||
"Aliyun": {
|
"Aliyun": {
|
||||||
"AccessKeyId": "",
|
"AccessKeyId": "",
|
||||||
"AccessKeySecret": "",
|
"AccessKeySecret": "",
|
||||||
"SignName": "AdminNET 平台", // 短信签名
|
"Templates": [
|
||||||
"TemplateCode": "" // 短信模板
|
{
|
||||||
|
"Id": "0",
|
||||||
|
"SignName": "AdminNET 平台",
|
||||||
|
"TemplateCode": "SMS_291005708",
|
||||||
|
"Content": "您的验证码为:${code},请勿泄露于他人!"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Id": "1",
|
||||||
|
"SignName": "AdminNET 平台",
|
||||||
|
"TemplateCode": "SMS_462801755",
|
||||||
|
"Content": "注册成功,感谢您的注册,请妥善保管您的账户信息"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"Tencentyun": {
|
"Tencentyun": {
|
||||||
"SdkAppId": "",
|
"SdkAppId": "",
|
||||||
"AccessKeyId": "",
|
"AccessKeyId": "",
|
||||||
"AccessKeySecret": "",
|
"AccessKeySecret": "",
|
||||||
"SignName": "AdminNET 平台", // 短信签名
|
"Templates": [
|
||||||
"TemplateCode": "" // 短信模板
|
{
|
||||||
|
"Id": "0",
|
||||||
|
"SignName": "AdminNET 平台",
|
||||||
|
"TemplateCode": "",
|
||||||
|
"Content": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,12 +40,27 @@ public sealed class SMSSettings
|
|||||||
public string AccessKeySecret { get; set; }
|
public string AccessKeySecret { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 短信签名
|
/// Templates
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SignName { get; set; }
|
public List<SmsTemplate> Templates { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 短信模板
|
/// GetTemplate
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
public SmsTemplate GetTemplate(string id = "0")
|
||||||
|
{
|
||||||
|
foreach (var template in Templates)
|
||||||
|
{
|
||||||
|
if (template.Id == id) { return template; }
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SmsTemplate
|
||||||
|
{
|
||||||
|
public string Id { get; set; } = string.Empty;
|
||||||
|
public string SignName { get; set; }
|
||||||
public string TemplateCode { get; set; }
|
public string TemplateCode { get; set; }
|
||||||
|
public string Content { get; set; }
|
||||||
}
|
}
|
||||||
@ -8,6 +8,7 @@ using AlibabaCloud.SDK.Dysmsapi20170525.Models;
|
|||||||
using TencentCloud.Common;
|
using TencentCloud.Common;
|
||||||
using TencentCloud.Common.Profile;
|
using TencentCloud.Common.Profile;
|
||||||
using TencentCloud.Sms.V20190711;
|
using TencentCloud.Sms.V20190711;
|
||||||
|
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ComponentTCBBatchCreateContainerServiceVersionRequest.Types;
|
||||||
|
|
||||||
namespace Admin.NET.Core.Service;
|
namespace Admin.NET.Core.Service;
|
||||||
|
|
||||||
@ -65,11 +66,12 @@ public class SysSmsService : IDynamicApiController, ITransient
|
|||||||
});
|
});
|
||||||
|
|
||||||
var client = CreateAliyunClient();
|
var client = CreateAliyunClient();
|
||||||
|
var template = _smsOptions.Aliyun.GetTemplate();
|
||||||
var sendSmsRequest = new SendSmsRequest
|
var sendSmsRequest = new SendSmsRequest
|
||||||
{
|
{
|
||||||
PhoneNumbers = phoneNumber, // 待发送手机号, 多个以逗号分隔
|
PhoneNumbers = phoneNumber, // 待发送手机号, 多个以逗号分隔
|
||||||
SignName = _smsOptions.Aliyun.SignName, // 短信签名
|
SignName = template.SignName, // 短信签名
|
||||||
TemplateCode = _smsOptions.Aliyun.TemplateCode, // 短信模板
|
TemplateCode = template.TemplateCode, // 短信模板
|
||||||
TemplateParam = templateParam.ToString(), // 模板中的变量替换JSON串
|
TemplateParam = templateParam.ToString(), // 模板中的变量替换JSON串
|
||||||
OutId = YitIdHelper.NextId().ToString()
|
OutId = YitIdHelper.NextId().ToString()
|
||||||
};
|
};
|
||||||
@ -104,11 +106,12 @@ public class SysSmsService : IDynamicApiController, ITransient
|
|||||||
throw Oops.Oh("短信内容不能为空");
|
throw Oops.Oh("短信内容不能为空");
|
||||||
|
|
||||||
var client = CreateAliyunClient();
|
var client = CreateAliyunClient();
|
||||||
|
var template = _smsOptions.Aliyun.GetTemplate();
|
||||||
var sendSmsRequest = new SendSmsRequest
|
var sendSmsRequest = new SendSmsRequest
|
||||||
{
|
{
|
||||||
PhoneNumbers = phoneNumber, // 待发送手机号, 多个以逗号分隔
|
PhoneNumbers = phoneNumber, // 待发送手机号, 多个以逗号分隔
|
||||||
SignName = _smsOptions.Aliyun.SignName, // 短信签名
|
SignName = template.SignName, // 短信签名
|
||||||
TemplateCode = _smsOptions.Aliyun.TemplateCode, // 短信模板
|
TemplateCode = template.TemplateCode, // 短信模板
|
||||||
TemplateParam = templateParam.ToString(), // 模板中的变量替换JSON串
|
TemplateParam = templateParam.ToString(), // 模板中的变量替换JSON串
|
||||||
OutId = YitIdHelper.NextId().ToString()
|
OutId = YitIdHelper.NextId().ToString()
|
||||||
};
|
};
|
||||||
@ -142,13 +145,14 @@ public class SysSmsService : IDynamicApiController, ITransient
|
|||||||
|
|
||||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||||
var client = new SmsClient(CreateTencentClient(), "ap-guangzhou", new ClientProfile() { HttpProfile = new HttpProfile() { Endpoint = ("sms.tencentcloudapi.com") } });
|
var client = new SmsClient(CreateTencentClient(), "ap-guangzhou", new ClientProfile() { HttpProfile = new HttpProfile() { Endpoint = ("sms.tencentcloudapi.com") } });
|
||||||
|
var template = _smsOptions.Tencentyun.GetTemplate();
|
||||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||||
var req = new TencentCloud.Sms.V20190711.Models.SendSmsRequest
|
var req = new TencentCloud.Sms.V20190711.Models.SendSmsRequest
|
||||||
{
|
{
|
||||||
PhoneNumberSet = new string[] { "+86" + phoneNumber.Trim(',') },
|
PhoneNumberSet = new string[] { "+86" + phoneNumber.Trim(',') },
|
||||||
SmsSdkAppid = _smsOptions.Tencentyun.SdkAppId,
|
SmsSdkAppid = _smsOptions.Tencentyun.SdkAppId,
|
||||||
Sign = _smsOptions.Tencentyun.SignName,
|
Sign = template.SignName,
|
||||||
TemplateID = _smsOptions.Tencentyun.TemplateCode,
|
TemplateID = template.TemplateCode,
|
||||||
TemplateParamSet = new string[] { verifyCode.ToString() }
|
TemplateParamSet = new string[] { verifyCode.ToString() }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user