本文主要是介绍Vue + Django 2.0.6 学习笔记 7.7云片网发送短信,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先要去 云片网注册:
https://www.yunpian.com/
然后开发者信息认证
然后就是新增签名和新增模板。
然后查看api文档:
https://www.yunpian.com/doc/zh_CN/introduction/brief.html
本次用的是单发短信 所以只需要看单发短信的api就可以了
https://www.yunpian.com/doc/zh_CN/domestic/single_send.html
这三个参数是必传:
接下来就是根据该api写一个短信发送的程序
apps/utils/yunpian.py
# -*- encoding: utf-8 -*-import json
import requestsclass YunPian(object):def __init__(self, api_key):self.api_key = api_keyself.single_send_url = "https://sms.yunpian.com/v2/sms/single_send.json"def send_sms(self, code, mobile):params = {"apikey": self.api_key,"mobile": mobile,"text": "dfsfa{code}fewfe".format(code=code),}response = requests.post(self.single_send_url, data=params)re_dict = json.loads(response.text)print(re_dict)# 测试用if __name__ == '__main__':yun_pian = YunPian("key")yun_pian.send_sms("fwf",'15164440792')
其中有用到requests模块,这个在爬虫方面用得多 具体使用看文档
https://2.python-requests.org//zh_CN/latest/user/quickstart.html
如果发送被拒那就吧IP添加入白名单中
这样发送短信的工具类就写好了 本篇完结
注:没有测试结果 因为云片网那小婊砸要我上传公司营业执照 谁会有啊
这篇关于Vue + Django 2.0.6 学习笔记 7.7云片网发送短信的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!