27 python 发送短信
腾讯云短信服务,来进行发送短信。
-
注册账号
-
开通服务 + 缴费 (实名、企业认证,公众号)
-
API服务、SDK服务
-
API,接口
import requests # 在此之前还会处理签名和加密的工作量 res = requests.get("......",params={"key":"xxx",'token':'...'})
-
SDK,服务(优先使用,如果没有提供pythonSDK,那就使用API)
pip install tencentcloud-sdk-python
import xxxx xxxxx.send(...)
-
# -*- coding: utf-8 -*-
from tencentcloud.common import credential
from tencentcloud.sms.v20210111 import sms_client, models
# SecretId SecretKey
cred = credential.Credential("xxx", "xxx")
client = sms_client.SmsClient(cred, "ap-guangzhou")
req = models.SendSmsRequest()
req.SmsSdkAppId = "xxx" # SDKappid
req.SignName = "角角边个人公众号" # 签名内容
req.TemplateId = "xxx" # 模板
req.TemplateParamSet = ["449739"] # 模板内存的占位符
req.PhoneNumberSet = ["+8613501483636"]
resp = client.SendSms(req)
print(resp)
# {"SendStatusSet": [{"SerialNo": "3364:272611138616643572126448356", "PhoneNumber": "+8613501483561", "Fee": 1, "SessionContext": "", "Code": "Ok", "Message": "send success", "IsoCode": "CN"}], "RequestId": "f51f3887-90f8-4aa9-af8b-cd303e7d59b4"}