1.安裝包
pip install qcloudsms_py
2.准備好相關參數
騰訊雲短信每個月贈送100條短信,申請一個應用,獲取appid,然后創建短信簽名,然后創建正文模版
3.發送短信
我們使用70439這個這個模版來發送短信
這個模版里只有一個參數{1},所以發送的時候就寫一個參數
#coding:utf-8 from qcloudsms_py import SmsSingleSender from qcloudsms_py.httpclient import HTTPError appid = 140005xxxx appkey = "4fcd263d315340bf578c93de89faxxxx" phone_numbers = ["1520284xxxx", "1814439xxxx"] #手機號可以添加多個多個 template_id = 74039 ssender = SmsSingleSender(appid, appkey) params = ["1234",] #發送驗證碼為1234 try: result = ssender.send_with_param(86, phone_numbers[0], template_id, params) except HTTPError as e: print(e) except Exception as e: print(e) print(result)
4,成功返回事例
{u'ext': u'', u'fee': 1, u'result': 0, u'errmsg': u'OK', u'sid': u'8:3xujxW6UPZcVeP6hZfr20180106'}
注:如果發送模版有多個參數就需要在代碼中傳入多個參數。
例如:
您的驗證碼為{1},{2}分鍾內有效。
params = ["1234","30"]
效果為你的驗證碼為1234,30分鍾內有效