django项目中使用云片网发送短信验证码的实现
1.在apps包下新建一个utils的python包
2.utils包中新建一个YunPian.py文件,文件中代码如下
importrequests
importjson
defsend_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
})
returnres
if__name__=='__main__':
res=send_single_sms("cdc06fa3370dfdsadasffadfadc53dc9d","149805","18889565149")
res_json=json.loads(res.text)
code=res_json["code"]
msg=res_json["msg"]
ifcode==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库:pipinstallrequests
到此这篇关于django项目中使用云片网发送短信验证码的实现的文章就介绍到这了,更多相关django云片网发送验证码内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下