首页 > 编程开发 > Python    日期:2021-01-19 / 来自互联网 / 浏览

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

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章

1 2 3 4 5