django項(xiàng)目中使用云片網(wǎng)發(fā)送短信驗(yàn)證碼的實(shí)現(xiàn)
1. 在apps包下新建一個(gè)utils的python包
2. utils包中新建一個(gè)YunPian.py文件,文件中代碼如下
import requestsimport json def send_single_sms(apikey, code, mobile): # 發(fā)送單條短信 url = 'https://sms.yunpian.com/v2/sms/single_send.json' text = '【后端學(xué)習(xí)】您的驗(yàn)證碼是{}。如非本人操作,請(qǐng)忽略本短信'.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('發(fā)送成功') else: print('發(fā)送失敗:{}'.format(msg)) print(res.text)
3. 云片網(wǎng)發(fā)送單條短信的api官網(wǎng):https://www.yunpian.com/official/document/sms/zh_CN/domestic_single_send
注意:python開(kāi)發(fā)環(huán)境中需要下載requests庫(kù): pip install requests
到此這篇關(guān)于django項(xiàng)目中使用云片網(wǎng)發(fā)送短信驗(yàn)證碼的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)django 云片網(wǎng)發(fā)送驗(yàn)證碼內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 一款功能強(qiáng)大的markdown編輯器tui.editor使用示例詳解2. 利用CSS制作3D動(dòng)畫(huà)3. Python+unittest+requests 接口自動(dòng)化測(cè)試框架搭建教程4. Springboot 全局日期格式化處理的實(shí)現(xiàn)5. Python 實(shí)現(xiàn)勞拉游戲的實(shí)例代碼(四連環(huán)、重力四子棋)6. SpringBoot+TestNG單元測(cè)試的實(shí)現(xiàn)7. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程8. Java GZip 基于內(nèi)存實(shí)現(xiàn)壓縮和解壓的方法9. 存儲(chǔ)于xml中需要的HTML轉(zhuǎn)義代碼10. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))
