1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using SmsTool.Models;
- using System;
- using TencentCloud.Common;
- using TencentCloud.Common.Profile;
- using TencentCloud.Sms.V20210111;
- using TencentCloud.Sms.V20210111.Models;
- namespace SmsTool.Tencent
- {
- public class TencentHelper
- {
- private static SmsClient _client;
- private static string _smsSdkAppId = "1400537314";//应用id
- public static void Init()
- {
- var credential = new Credential
- {
- SecretId = "AKIDMSIsADUUpvJGwJOKvsb5IDrGtGNBRzzi",
- SecretKey = "4sQhdJBl5HI7f3oLbZIlwqXOyILyLWP0"
- };
- ClientProfile clientProfile = new ClientProfile();
- HttpProfile httpProfile = new HttpProfile();
- httpProfile.Endpoint = ("sms.tencentcloudapi.com");
- clientProfile.HttpProfile = httpProfile;
- _client = new SmsClient(credential, "ap-nanjing", clientProfile);
- }
- public static SendSmsResponse SendSmsSync(SendSmsModel model)
- {
- try
- {
- SendSmsResponse resp = _client.SendSmsSync(new SendSmsRequest
- {
- TemplateId = model.TemplateId,
- PhoneNumberSet = model.FormatterMobiles.ToArray(),
- TemplateParamSet = model.Params.ToArray(),
- SignName = model.SignName,
- SmsSdkAppId = _smsSdkAppId
- });
- //Console.WriteLine(AbstractModel.ToJsonString(resp));
- Console.WriteLine($"[{DateTime.Now:MM-dd HH:mm:ss}]{resp.RequestId}");
- foreach (var item in resp.SendStatusSet)
- {
- Console.WriteLine($"[{DateTime.Now:MM-dd HH:mm:ss}]{item.PhoneNumber},{item.Code},{item.Message}");
- }
- return resp;
- }
- catch (Exception ex)
- {
- Console.WriteLine($"[{DateTime.Now:MM-dd HH:mm:ss}]templateId:{model.TemplateId},mobiles:{string.Join(";", model.Mobiles)},params:{string.Join(";", model.Params)},{ex.Message}");
- return null;
- }
- }
- }
- }
|