Python 腾讯云短信,发送手机验证码

 

1.安装包shell

pip install qcloudsms_py
app

2.准备好相关参数spa

腾讯云短信每一个月赠送100条短信,申请一个应用,获取appid,而后建立短信签名,而后建立正文模版3d

 

3.发送短信code

咱们使用70439这个这个模版来发送短信blog

这个模版里只有一个参数{1},因此发送的时候就写一个参数ip

#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,成功返回事例utf-8

{u'ext': u'', u'fee': 1, u'result': 0, u'errmsg': u'OK', u'sid': u'8:3xujxW6UPZcVeP6hZfr20180106'}

it

注:若是发送模版有多个参数就须要在代码中传入多个参数。pip

例如:

您的验证码为{1},{2}分钟内有效。

 
params = ["1234","30"]效果为你的验证码为1234,30分钟内有效
相关文章
相关标签/搜索