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.v20190711 import sms_client, models
def sms(phone):
"""
:param phone: 手机号
:return: 接口返回信息
"""
try:
cred = credential.Credential("id", "key") # API接口的 id key
httpProfile = HttpProfile()
httpProfile.endpoint = "sms.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = sms_client.SmsClient(cred, "", clientProfile)
req = models.SendSmsRequest()
params = {
"PhoneNumberSet": ['+86' + phone],
"TemplateParamSet": [] # 模板里的参数,
"TemplateID": "" # 模板id,
"SmsSdkAppid": "" # 你的sdk appID,
"Sign": "" # 备案名字(签名)
}
req.from_json_string(json.dumps(params))
resp = client.SendSms(req)
print('sms:短信验证码发送成功!', resp.to_json_string())
return resp.to_json_string()
except TencentCloudSDKException as err:
print('sms: 接口异常。', err)
return err
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!