需要三个参数SmsSdkAppId、SecretId、SecretKey,
SignName和TemplateId在写模版短信的时候创建即可
import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.sms.v20210111 import sms_client, models
try:
cred = credential.Credential("SecretId", "SecretKey")
httpProfile = HttpProfile()
httpProfile.endpoint = "sms.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = sms_client.SmsClient(cred, "ap-guangzhou", clientProfile)
req = models.SendSmsRequest()
params = {
"PhoneNumberSet": [ "13312345678" ],
"SmsSdkAppId": "SmsSdkAppId",
"SignName": "阿BU的技术笔记",
"TemplateId": "111111",
"TemplateParamSet": [ "测试" ]
}
req.from_json_string(json.dumps(params))
resp = client.SendSms(req)
print(resp.to_json_string())
except TencentCloudSDKException as err:
print(err)