使用python发送短信验证码@TOC
使用云片网的接口发送短信验证码
1、云片网地址
2、API指导文档
3、python代码示例:
class YunPian(object):
"""
https://www.yunpian.com/doc/zh_CN/domestic/list.html
"""
def __init__(self, apikey):
self.apikey = apikey
self.single_send_url = "https://sms.yunpian.com/v2/sms/single_send.json"
def send_sms(self, code, mobile):
parmas = {
"apikey":self.apikey,
"mobile":mobile,
"text":"【刘胜的网站】您的验证码是{code}。如非本人操作,请忽略本条信息".format(code=code),
}
response = requests.post(self.single_send_url, data=parmas)
re_dict = json.loads(response.text)
print(re_dict)
4、注意事项:需要在云片网的后台的设置中把运行代码的机器的ip地址填入白名单中