|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using SafeCampus.Core.Options;
- using TencentCloud.Common;
- using TencentCloud.Common.Profile;
- using TencentCloud.Sms.V20210111;
- using TencentCloud.Sms.V20210111.Models;
-
- namespace SafeCampus.Core.Utils.TXYSMS;
-
- public static class TxySmsUtil
- {
- /// <summary>
- /// 发送短信
- /// </summary>
- /// <param name="phone">new[] { $"+86{phone}" } 手机号码</param>
- /// <param name="content">new[] { code.ToString(), "5" } 内容参数</param>
- /// <returns></returns>
- public static bool SendSms(string[] phone, string[] content)
- {
- var setting = App.GetOptionsMonitor<TXSmsOptions>();
- Credential cred = new()
- {
- SecretId = setting.SecretId,
- SecretKey = setting.SecretKey
- };
- ClientProfile clientProfile = new();
- HttpProfile httpProfile = new()
- {
- Endpoint = ("sms.tencentcloudapi.com"),
- };
- clientProfile.HttpProfile = httpProfile;
- SmsClient client = new(cred, "ap-beijing", clientProfile);
- SendSmsRequest req = new()
- {
- PhoneNumberSet = phone,// new[] { $"+86{phone}" },
- SmsSdkAppId = setting.SmsAppId,
- SignName = setting.SmsSn,
- TemplateId = setting.VerificationCodeId,
- TemplateParamSet = content,
- };
- SendSmsResponse resp = client.SendSmsSync(req);
- if (resp.SendStatusSet[0].Code == "Ok")
- {
- // 缓存验证码
- return true;
- }
- return false;
- }
- }
|