:param phone: 手机号 :param session: 客户端唯一字符串 :param verify_code: 验证码 :param secret_id: 凭证ID :param secret_key: 凭证钥匙 :param region: 地域 :param app_id: 应用ID :param sign: 签名 :param template_id: 模版ID :return:
(
phone: str,
session: str,
verify_code: str,
secret_id: str,
secret_key: str,
region: str,
app_id: str,
sign: str,
template_id: str
)
| 155 | |
| 156 | |
| 157 | def send( |
| 158 | phone: str, |
| 159 | session: str, |
| 160 | verify_code: str, |
| 161 | secret_id: str, |
| 162 | secret_key: str, |
| 163 | region: str, |
| 164 | app_id: str, |
| 165 | sign: str, |
| 166 | template_id: str |
| 167 | ): |
| 168 | """ |
| 169 | |
| 170 | :param phone: 手机号 |
| 171 | :param session: 客户端唯一字符串 |
| 172 | :param verify_code: 验证码 |
| 173 | :param secret_id: 凭证ID |
| 174 | :param secret_key: 凭证钥匙 |
| 175 | :param region: 地域 |
| 176 | :param app_id: 应用ID |
| 177 | :param sign: 签名 |
| 178 | :param template_id: 模版ID |
| 179 | :return: |
| 180 | """ |
| 181 | try: |
| 182 | # 必要步骤: |
| 183 | # 实例化一个认证对象,入参需要传入腾讯云账户密钥对 secretId 和 secretKey |
| 184 | # 本示例采用从环境变量读取的方式,需要预先在环境变量中设置这两个值 |
| 185 | # 您也可以直接在代码中写入密钥对,但需谨防泄露,不要将代码复制、上传或者分享给他人 |
| 186 | # CAM 密钥查询:https://console.cloud.tencent.com/cam/capi |
| 187 | cred = credential.Credential(secret_id, secret_key) |
| 188 | # cred = credential.Credential( |
| 189 | # os.environ.get(""), |
| 190 | # os.environ.get("") |
| 191 | # ) |
| 192 | |
| 193 | # 实例化一个 http 选项,可选,无特殊需求时可以跳过 |
| 194 | http_profile = HttpProfile() |
| 195 | http_profile.reqMethod = "POST" # POST 请求(默认为 POST 请求) |
| 196 | http_profile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒) |
| 197 | http_profile.endpoint = "sms.tencentcloudapi.com" # 指定接入地域域名(默认就近接入) |
| 198 | |
| 199 | # 非必要步骤: |
| 200 | # 实例化一个客户端配置对象,可以指定超时时间等配置 |
| 201 | client_profile = ClientProfile() |
| 202 | client_profile.signMethod = "TC3-HMAC-SHA256" # 指定签名算法 |
| 203 | client_profile.language = "en-US" |
| 204 | client_profile.httpProfile = http_profile |
| 205 | |
| 206 | # 实例化 SMS 的 client 对象 |
| 207 | # 第二个参数是地域信息,可以直接填写字符串 ap-guangzhou,或者引用预设的常量 |
| 208 | client = sms_client.SmsClient(cred, region, client_profile) |
| 209 | |
| 210 | # 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数 |
| 211 | # 您可以直接查询 SDK 源码确定 SendSmsRequest 有哪些属性可以设置 |
| 212 | # 属性可能是基本类型,也可能引用了另一个数据结构 |
| 213 | # 推荐使用 IDE 进行开发,可以方便的跳转查阅各个接口和数据结构的文档说明 |
| 214 | req = models.SendSmsRequest() |
no outgoing calls
no test coverage detected