Python operation Tencent cloud SMS (SMS) detailed tutorial

noosphere 2021-04-06 16:47:59
python operation tencent cloud sms


Tencent cloud SMS

1. register Tencent cloud

existing Tencent cloud The account number can jump to The second step

  • Official website
  • register , Wechat code scanning attention Tencent cloud Assistant can quickly register
     Insert picture description here
  • choice Sign up for a new account , After registration , Real name authentication . choice Personal Certification , Just fill in the information ok 了 .
     Insert picture description here  Insert picture description here  Insert picture description here

2. Opening Tencent cloud SMS

  • We have already registered through the previous step Tencent cloud account number , Next, we'll open it Tencent cloud SMS function .
  • Open website :https://console.cloud.tencent.com/smsv2

2.1 Create an

  • Create an application , Click in and you'll see SDK AppID & App Key, You can use it later .
     Insert picture description here  Insert picture description here

2.2 Create signature

  • We create a domestic SMS signature
     Insert picture description here
  • Signature type I recommend using official account , It's easier to get through , The official account is also easier to apply. .
     Insert picture description here

2.3 Create a template

  • Next, we create several SMS templates , register 、 Login and so on
     Insert picture description here
  • Here are some common standard templates , It can be used directly
     Insert picture description here

Be careful :
There is a frequency limit for sending short messages , However, this can only be modified by enterprise users , Individual user cannot modify
 Insert picture description here

3. Python operation Tencent cloud SMS

3.1 Module installation

pip install qcloudsms_py

3.2 Detailed code 【 Can be used directly as an interface 】

# -*- coding: UTF-8 -*-
'''=================================================
@Project -> File :MyDjango -> sms
@IDE :PyCharm
@Author :ruochen
@Date :2020/6/21 15:57
@Desc :
=================================================='''
import ssl
# ssl._create_default_https_context = ssl._create_unverified_context
from qcloudsms_py import SmsMultiSender, SmsSingleSender
from qcloudsms_py.httpclient import HTTPError
from django.conf import settings
def send_sms_single(phone_num, template_id, template_param_list):
"""
Single SMS
:param phone_num: cell-phone number
:param template_id: [ Tencent cloud ](https://l.gushuji.site/tencent) SMS template ID
:param template_param_list: Parameter list required by SMS template , for example :【 Verification Code :{1}, describe :{2}】, Then pass the parameter [888,666] Format the template in order
:return:
"""
appid = settings.TENCENT_SMS_APP_ID # Apply it yourself ID
appkey = settings.TENCENT_SMS_APP_KEY # Apply it yourself Key
sms_sign = settings.TENCENT_SMS_SIGN # own [ Tencent cloud ](https://l.gushuji.site/tencent) Signature content filled in when creating a signature ( This is generally the official account number or the official account. )
sender = SmsSingleSender(appid, appkey)
try:
response = sender.send_with_param(86, phone_num, template_id, template_param_list, sign=sms_sign)
except HTTPError as e:
response = {'result': 1000, 'errmsg': " Network exception sending failed "}
return response
def send_sms_multi(phone_num_list, template_id, param_list):
"""
Send text messages in bulk
:param phone_num_list: Mobile phone number list
:param template_id:[ Tencent cloud ](https://l.gushuji.site/tencent) SMS template ID
:param param_list: Parameter list required by SMS template , for example :【 Verification Code :{1}, describe :{2}】, Then pass the parameter [888,666] Format the template in order
:return:
"""
appid = settings.TENCENT_SMS_APP_ID # Apply it yourself ID
appkey = settings.TENCENT_SMS_APP_KEY # Apply it yourself Key
sms_sign = settings.TENCENT_SMS_SIGN # own [ Tencent cloud ](https://l.gushuji.site/tencent) Signature content filled in when creating a signature ( This is generally the official account number or the official account. )
sender = SmsMultiSender(appid, appkey)
try:
response = sender.send_with_param(86, phone_num_list, template_id, param_list, sign=sms_sign)
except HTTPError as e:
response = {'result': 1000, 'errmsg': " Network exception sending failed "}
return response
版权声明
本文为[noosphere]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/04/20210406164559238O.html

  1. 商业数据分析从入门到入职(7)Python基础数据结构及其操作
  2. 商业数据分析从入门到入职(6)Python程序结构和函数
  3. Business data analysis from entry to entry (9) Python Network Data Acquisition
  4. Business data analysis from entry to entry (8) Python module, file IO and object oriented
  5. Business data analysis from entry to entry (7) Python basic data structure and its operation
  6. Business data analysis from entry to entry (6) Python program structure and function
  7. 简简单单实现 Python Web 的登录注册页面,还包含一半逻辑。
  8. Simple implementation of Python web login registration page, but also contains half of the logic.
  9. 什么是pip?Python新手入门指南
  10. What is PIP? Getting started with Python
  11. Python uses for... Else to jump out of double nested loop
  12. Python基础之:Python中的内部对象
  13. 人工智能入门:Python实现机器学习
  14. The foundation of Python: inner objects in Python
  15. Introduction to artificial intelligence: machine learning in Python
  16. Python基础之:Python中的内部对象
  17. The foundation of Python: inner objects in Python
  18. Python 小技之 Office 文件转 PDF
  19. 还在为多张Excel汇总统计发愁?Python 秒处理真香!
  20. 用 Python 制作音乐聚合下载器
  21. Spark Delta Lake 0.4.0 发布,支持 Python API 和部分 SQL
  22. How to transfer office files to PDF
  23. Are you still worried about multiple excel summary statistics? Python second processing really fragrant!
  24. Making music aggregate downloader with Python
  25. Spark delta Lake 0.4.0 is released, supporting Python API and part of SQL
  26. Python信息搜集
  27. Python information gathering
  28. Python - 关于类(self/cls) 以及 多进程通讯的思考
  29. Python - thinking about class (self / CLS) and multi process communication
  30. Python - 关于类(self/cls) 以及 多进程通讯的思考
  31. Python - thinking about class (self / CLS) and multi process communication
  32. Python信用评分卡建模(附代码)
  33. Python credit score card modeling (with code)
  34. 学Python需要学数据库吗?Python学习教程!
  35. Do you need to learn database to learn Python!
  36. Python私有变量如何定义?Python学习教程!
  37. How to define Python private variables? Python tutorial!
  38. Python数据分析入门(六):Pandas的函数应用
  39. Introduction to Python data analysis (6): function application of pandas
  40. 学Python需要学数据库吗?Python学习教程!
  41. Do you need to learn database to learn Python!
  42. Python描述 LeetCode 80. 删除有序数组中的重复项 II
  43. C++/python描述 AcWing 94. 递归实现排列型枚举
  44. C++/python描述 AcWing 92. 递归实现指数型枚举
  45. Python描述 LeetCode 88. 合并两个有序数组
  46. 苏州大学计算机考研 复试机试真题2013-2021真题及Python题解
  47. Python描述 LeetCode 781. 森林中的兔子
  48. 字典和json的区别是什么?Python学习
  49. Python describes leetcode 80. Removing duplicate items from ordered arrays II
  50. C + + / Python description acwing 94. Recursive implementation of permutation enumeration
  51. C + + / Python description acwing 92. Recursive implementation of exponential enumeration
  52. Python describes leetcode 88. Merging two ordered arrays
  53. Real computer test questions 2013-2021 of computer postgraduate entrance examination of Soochow University and python solutions
  54. The rabbit in the forest
  55. Python中的魔法属性
  56. What's the difference between dictionary and JSON? Python learning
  57. Magic properties in Python
  58. 字典和json的区别是什么?Python学习
  59. What's the difference between dictionary and JSON? Python learning
  60. python刷题-字母图形