1. 在apps包下新建一個utils的python包
2. utils包中新建一個YunPian.py檔案,檔案中代碼如下
import requests
import 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/250225.html
標籤:python
