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 { /// /// 发送短信 /// /// new[] { $"+86{phone}" } 手机号码 /// new[] { code.ToString(), "5" } 内容参数 /// public static bool SendSms(string[] phone, string[] content) { var setting = App.GetOptionsMonitor(); 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; } }