-
Notifications
You must be signed in to change notification settings - Fork 251
/
sms_client.py
455 lines (379 loc) · 24.7 KB
/
sms_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# -*- coding: utf8 -*-
# Copyright (c) 2017-2021 THL A29 Limited, a Tencent company. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.common.abstract_client import AbstractClient
from tencentcloud.sms.v20210111 import models
class SmsClient(AbstractClient):
_apiVersion = '2021-01-11'
_endpoint = 'sms.tencentcloudapi.com'
_service = 'sms'
def AddSmsSign(self, request):
"""本接口 (AddSmsSign) 用于添加短信签名。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>添加短信签名前,请先认真参阅 <a href="https://cloud.tencent.com/document/product/382/39022">腾讯云短信签名审核标准。</a></li><li>个人认证用户不支持使用 API 申请短信签名,请参阅了解 <a href="https://cloud.tencent.com/document/product/378/3629">实名认证基本介绍</a>,如果为个人认证请登录 <a href="https://console.cloud.tencent.com/smsv2">控制台</a> 申请短信签名。</li></ul></blockquote>
:param request: Request instance for AddSmsSign.
:type request: :class:`tencentcloud.sms.v20210111.models.AddSmsSignRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.AddSmsSignResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("AddSmsSign", params, headers=headers)
response = json.loads(body)
model = models.AddSmsSignResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def AddSmsTemplate(self, request):
"""本接口 (AddSmsTemplate) 用于创建短信模板。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>申请短信模板前,请先认真参阅 <a href="https://cloud.tencent.com/document/product/382/39023">腾讯云短信正文模板审核标准。</a></li><li>个人认证用户不支持使用 API 申请短信正文模板,请参阅了解 <a href="https://cloud.tencent.com/document/product/378/3629">实名认证基本介绍</a>,如果为个人认证请登录 <a href="https://console.cloud.tencent.com/smsv2">控制台</a> 申请短信正文模板。</li></ul></blockquote>
:param request: Request instance for AddSmsTemplate.
:type request: :class:`tencentcloud.sms.v20210111.models.AddSmsTemplateRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.AddSmsTemplateResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("AddSmsTemplate", params, headers=headers)
response = json.loads(body)
model = models.AddSmsTemplateResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def CallbackStatusStatistics(self, request):
"""本接口 (CallbackStatusStatistics) 用于统计用户回执的数据。
:param request: Request instance for CallbackStatusStatistics.
:type request: :class:`tencentcloud.sms.v20210111.models.CallbackStatusStatisticsRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.CallbackStatusStatisticsResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("CallbackStatusStatistics", params, headers=headers)
response = json.loads(body)
model = models.CallbackStatusStatisticsResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def DeleteSmsSign(self, request):
"""本接口 (DeleteSmsSign) 用于删除短信签名。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>个人认证用户不支持使用 API 删除短信签名,请参阅了解 <a href="https://cloud.tencent.com/document/product/378/3629">实名认证基本介绍</a>,如果为个人认证请登录 <a href="https://console.cloud.tencent.com/smsv2">控制台</a> 删除短信签名。</li></ul></blockquote>
:param request: Request instance for DeleteSmsSign.
:type request: :class:`tencentcloud.sms.v20210111.models.DeleteSmsSignRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.DeleteSmsSignResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("DeleteSmsSign", params, headers=headers)
response = json.loads(body)
model = models.DeleteSmsSignResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def DeleteSmsTemplate(self, request):
"""本接口 (DeleteSmsTemplate) 用于删除短信模板。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>个人认证用户不支持使用 API 删除短信正文模板,请参阅了解 <a href="https://cloud.tencent.com/document/product/378/3629">实名认证基本介绍</a>,如果为个人认证请登录 <a href="https://console.cloud.tencent.com/smsv2">控制台</a> 删除短信正文模板。</li></ul></blockquote>
:param request: Request instance for DeleteSmsTemplate.
:type request: :class:`tencentcloud.sms.v20210111.models.DeleteSmsTemplateRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.DeleteSmsTemplateResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("DeleteSmsTemplate", params, headers=headers)
response = json.loads(body)
model = models.DeleteSmsTemplateResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def DescribePhoneNumberInfo(self, request):
"""本接口 (DescribePhoneNumberInfo) 用于提供电话号码的信息查询,包括国家(或地区)码、规范的 E.164 格式号码等。
- 例如:查询号码 +86018845720123,可以得到国家码 86、规范的 E.164 号码 +8618845720123 等信息。
:param request: Request instance for DescribePhoneNumberInfo.
:type request: :class:`tencentcloud.sms.v20210111.models.DescribePhoneNumberInfoRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.DescribePhoneNumberInfoResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("DescribePhoneNumberInfo", params, headers=headers)
response = json.loads(body)
model = models.DescribePhoneNumberInfoResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def DescribeSmsSignList(self, request):
"""本接口 (DescribeSmsSignList) 用于查询短信签名状态。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>个人认证用户不支持使用 API 查询短信签名,请参阅了解 <a href="https://cloud.tencent.com/document/product/378/3629">实名认证基本介绍</a>,如果为个人认证请登录 <a href="https://console.cloud.tencent.com/smsv2">控制台</a> 查询短信签名。</li></ul></blockquote>
:param request: Request instance for DescribeSmsSignList.
:type request: :class:`tencentcloud.sms.v20210111.models.DescribeSmsSignListRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.DescribeSmsSignListResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("DescribeSmsSignList", params, headers=headers)
response = json.loads(body)
model = models.DescribeSmsSignListResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def DescribeSmsTemplateList(self, request):
"""本接口 (DescribeSmsTemplateList) 用于查询短信模板状态。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>个人认证用户不支持使用 API 查询短信正文模板,请参阅了解 <a href="https://cloud.tencent.com/document/product/378/3629">实名认证基本介绍</a>,如果为个人认证请登录 <a href="https://console.cloud.tencent.com/smsv2">控制台</a> 查询短信正文模板。</li></ul></blockquote>
:param request: Request instance for DescribeSmsTemplateList.
:type request: :class:`tencentcloud.sms.v20210111.models.DescribeSmsTemplateListRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.DescribeSmsTemplateListResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("DescribeSmsTemplateList", params, headers=headers)
response = json.loads(body)
model = models.DescribeSmsTemplateListResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def ModifySmsSign(self, request):
"""本接口 (ModifySmsSign) 用于修改短信签名。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>修改短信签名前,请先认真参阅 <a href="https://cloud.tencent.com/document/product/382/39022">腾讯云短信签名审核标准。</a></li><li>个人认证用户不支持使用 API 修改短信签名,请参阅了解 <a href="https://cloud.tencent.com/document/product/378/3629">实名认证基本介绍</a>,如果为个人认证请登录 <a href="https://console.cloud.tencent.com/smsv2">控制台</a> 修改短信签名。</li><li>修改短信签名,仅当签名为<b>待审核</b>或<b>已拒绝</b>状态时,才能进行修改,<b>已审核通过</b>的签名不支持修改。</li></ul></blockquote>
:param request: Request instance for ModifySmsSign.
:type request: :class:`tencentcloud.sms.v20210111.models.ModifySmsSignRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.ModifySmsSignResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("ModifySmsSign", params, headers=headers)
response = json.loads(body)
model = models.ModifySmsSignResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def ModifySmsTemplate(self, request):
"""本接口 (ModifySmsTemplate) 用于修改短信模板。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>修改短信正文模板前,请先认真参阅 <a href="https://cloud.tencent.com/document/product/382/39023">腾讯云短信正文模板审核标准。</a></li><li>个人认证用户不支持使用 API 修改短信正文模板,请参阅了解 <a href="https://cloud.tencent.com/document/product/378/3629">实名认证基本介绍</a>,如果为个人认证请登录 <a href="https://console.cloud.tencent.com/smsv2">控制台</a> 修改短信正文模板。</li><li>修改短信模板,仅当正文模板为<b>待审核</b>或<b>已拒绝</b>状态时,才能进行修改,<b>已审核通过</b>的正文模板不支持修改。</li></ul></blockquote>
:param request: Request instance for ModifySmsTemplate.
:type request: :class:`tencentcloud.sms.v20210111.models.ModifySmsTemplateRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.ModifySmsTemplateResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("ModifySmsTemplate", params, headers=headers)
response = json.loads(body)
model = models.ModifySmsTemplateResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def PullSmsReplyStatus(self, request):
"""本接口 (PullSmsReplyStatus) 用于拉取短信回复状态。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>此接口需要联系 <a href="https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81">腾讯云短信小助手</a> 开通。</li><li>上行回复也支持 <a href="https://cloud.tencent.com/document/product/382/42907">配置回复回调</a> 的方式获取。</li></ul></blockquote>
:param request: Request instance for PullSmsReplyStatus.
:type request: :class:`tencentcloud.sms.v20210111.models.PullSmsReplyStatusRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.PullSmsReplyStatusResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("PullSmsReplyStatus", params, headers=headers)
response = json.loads(body)
model = models.PullSmsReplyStatusResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def PullSmsReplyStatusByPhoneNumber(self, request):
"""本接口 (PullSmsReplyStatusByPhoneNumber) 用于拉取单个号码短信回复状态。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>上行回复也支持 <a href="https://cloud.tencent.com/document/product/382/42907">配置回复回调</a> 的方式获取。</li></ul></blockquote>
:param request: Request instance for PullSmsReplyStatusByPhoneNumber.
:type request: :class:`tencentcloud.sms.v20210111.models.PullSmsReplyStatusByPhoneNumberRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.PullSmsReplyStatusByPhoneNumberResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("PullSmsReplyStatusByPhoneNumber", params, headers=headers)
response = json.loads(body)
model = models.PullSmsReplyStatusByPhoneNumberResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def PullSmsSendStatus(self, request):
"""本接口 (PullSmsSendStatus) 用于拉取短信下发状态。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>此接口需要联系 <a href="https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81">腾讯云短信小助手</a> 开通。</li><li>下发状态也支持 <a href="https://cloud.tencent.com/document/product/382/37809#.E7.9F.AD.E4.BF.A1.E7.8A.B6.E6.80.81.E5.9B.9E.E8.B0.83.E9.85.8D.E7.BD.AE">配置回调</a> 的方式获取。</li></ul></blockquote>
:param request: Request instance for PullSmsSendStatus.
:type request: :class:`tencentcloud.sms.v20210111.models.PullSmsSendStatusRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.PullSmsSendStatusResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("PullSmsSendStatus", params, headers=headers)
response = json.loads(body)
model = models.PullSmsSendStatusResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def PullSmsSendStatusByPhoneNumber(self, request):
"""本接口 (PullSmsSendStatusByPhoneNumber) 用于拉取单个号码短信下发状态。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>下发状态也支持 <a href="https://cloud.tencent.com/document/product/382/37809#.E7.9F.AD.E4.BF.A1.E7.8A.B6.E6.80.81.E5.9B.9E.E8.B0.83.E9.85.8D.E7.BD.AE">配置回调</a> 的方式获取。</li></ul></blockquote>
:param request: Request instance for PullSmsSendStatusByPhoneNumber.
:type request: :class:`tencentcloud.sms.v20210111.models.PullSmsSendStatusByPhoneNumberRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.PullSmsSendStatusByPhoneNumberResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("PullSmsSendStatusByPhoneNumber", params, headers=headers)
response = json.loads(body)
model = models.PullSmsSendStatusByPhoneNumberResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def ReportConversion(self, request):
"""本接口 (ReportConversion) 用于短信转化率上报。将已接收到短信的流水号上报到腾讯云短信服务。
<blockquote class="d-mod-explain"><div class="d-mod-title d-explain-title" style="line-height: normal;"><i class="d-icon-explain"></i>说明:</div><p></p><ul><li>该接口当前以白名单方式对外开放,如有需要请联系 <a href="https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81">腾讯云短信小助手</a> 开通。</li></ul></blockquote>
:param request: Request instance for ReportConversion.
:type request: :class:`tencentcloud.sms.v20210111.models.ReportConversionRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.ReportConversionResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("ReportConversion", params, headers=headers)
response = json.loads(body)
model = models.ReportConversionResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def SendSms(self, request):
"""本接口 (SendSms) 用于发送验证码、通知类短信和营销短信。支持国内短信与国际/港澳台短信。
- 当前接口属于 2021-01-11 版本,如果您仍在使用 [2019-07-11 版本](https://cloud.tencent.com/document/product/382/38778),建议您使用当前最新版本的接口,版本差异可参考[版本描述](https://cloud.tencent.com/document/product/382/63195#.E7.89.88.E6.9C.AC.E6.8F.8F.E8.BF.B0)。
:param request: Request instance for SendSms.
:type request: :class:`tencentcloud.sms.v20210111.models.SendSmsRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.SendSmsResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("SendSms", params, headers=headers)
response = json.loads(body)
model = models.SendSmsResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def SendStatusStatistics(self, request):
"""本接口 (SendStatusStatistics) 用于统计用户发送短信的数据。
:param request: Request instance for SendStatusStatistics.
:type request: :class:`tencentcloud.sms.v20210111.models.SendStatusStatisticsRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.SendStatusStatisticsResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("SendStatusStatistics", params, headers=headers)
response = json.loads(body)
model = models.SendStatusStatisticsResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))
def SmsPackagesStatistics(self, request):
"""本接口 (SmsPackagesStatistics) 用于统计用户套餐包数据。
:param request: Request instance for SmsPackagesStatistics.
:type request: :class:`tencentcloud.sms.v20210111.models.SmsPackagesStatisticsRequest`
:rtype: :class:`tencentcloud.sms.v20210111.models.SmsPackagesStatisticsResponse`
"""
try:
params = request._serialize()
headers = request.headers
body = self.call("SmsPackagesStatistics", params, headers=headers)
response = json.loads(body)
model = models.SmsPackagesStatisticsResponse()
model._deserialize(response["Response"])
return model
except Exception as e:
if isinstance(e, TencentCloudSDKException):
raise
else:
raise TencentCloudSDKException(type(e).__name__, str(e))