django项目中使用云片网发送短信验证码的实现
1. 在apps包下新建一个utils的python包
2. utils包中新建一个YunPian.py文件,文件中代码如下
import requestsimport json def send_single_sms(apikey, code, mobile): # 发送单条短信 url = 'https://sms.yunpian.com/v2/sms/single_send.json' text = '【后端学习】您的验证码是{}。如非本人操作,请忽略本短信'.format(code) res = requests.post(url, data={ 'apikey': apikey, 'mobile': mobile, 'text': text }) return res if __name__ == ’__main__’: res = send_single_sms('cdc06fa3370dfdsadasffadfadc53dc9d', '149805', '18889565149') res_json = json.loads(res.text) code = res_json['code'] msg = res_json['msg'] if code == 0: print('发送成功') else: print('发送失败:{}'.format(msg)) print(res.text)
3. 云片网发送单条短信的api官网:https://www.yunpian.com/official/document/sms/zh_CN/domestic_single_send
注意:python开发环境中需要下载requests库: pip install requests
到此这篇关于django项目中使用云片网发送短信验证码的实现的文章就介绍到这了,更多相关django 云片网发送验证码内容请搜索好吧啦网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好吧啦网!
相关文章:
1. set rs=conn.execute,set rs=server.createobject(“ADODB.recordset”)的性能对比2. asp错误 '80040e21' 多步 OLE DB 操作产生错误3. 详解Android跨进程通信之AIDL4. 如何使用Mock修改Android设备上的features5. Android制作登录页面并且记住账号密码功能的实现代码6. php设计模式之观察者模式实例详解【星际争霸游戏案例】7. python tkinter GUI绘制,以及点击更新显示图片代码8. Python将CSV文件转化为HTML文件的操作方法9. Python ini文件常用操作方法解析10. 如何修改PHP的memory_limit限制