短信验证
我的这个短信验证是必须得跨服一个网站注册才能进行接下来的操作
首先,先注册一个 www.Twilio.com 账号 ,他会自动给你一个免费的电话号码,不过别忘了必须的跨服才可以,然后把地址选China
然后呢安装twilio模块
pip install twillo #如果安装速度非常慢的话可以制定源 , 我在前面的文章写过,需要的可以参考
#然后是最重要的操作 , 发送短信,我把它封装成了工具类,需要的时候可以随时调用
还有一点需要注意的是收信人必须是在twilio网站上注册,同意过的才行
#导报 导入客户端 from twilio.rest import Client from django.http import HttpResponse class Note(object): def __init__(self,tonote,tobody): self.tonote = tonote self.tobody = tobody def Number(self): #定义短信sid account_sid = 'AC336b119161744712cca385b359ec8719' #定义秘钥 auth_token = 'f3d7b58236175c3d268aad13a9ed3388' #定义客户端对象 clinet = Client(account_sid,auth_token) #定义短信内容 1发给谁 2发信人 3短信内容 status = clinet.messages.create(to='+86'+self.tonote,from_='+12012980234',body=self.tobody) #打印发送结果 if status: return HttpResponse("发送短息成功") else: return HttpResponse("发送短信失败")